This is really puzzling. I now found an ordinary internal link (what you get via the icon minus the username part) which has a click counter, but I also have multiple such links where clicks are not countedā¦
There was meant to be a sample link in the OP but apparently I posted it without pasting the link. Fixed it now. Letās see if it will get a link counter as predictedā¦
In any case: could you clarify what the expected behaviour is? When does a link get a click counter and when does it not get one?
Thereās something suspicious going on? Or something Iām missing.
I have two posts, linked with hyperlinked text.
When I go to the target link I see that itās been visited from the first post several times (from the counter and link at the bottom of the post!), but there is no corresponding counter on the source pageā¦
The link counters that donāt work have exactly the same format as the ones that do, they are all using the full URL including https and the domain and full path.
Iāve done a very little amount of investigation so far.
Iāve confirmed so far that my suspicious links that are showing zero clicks exist in the table, and the count is zero. Thatās so unlikely as to be almost impossible. So why arenāt the clicks accumulating? Other links within the same topic and post are accumulating fine ā¦ (or perhaps its an intermittent issue so the counts are lower than they should be?)
Try it yourself in Data Explorer for suspicious links with no counter:
(the topic id is in the URL, naturally)
SELECT * from topic_links where topic_id = <your affected topic id>
Next, I clicked on the suspicious link whilst impersonating a user, logged out, logged back in as admin and then ran the query again. Still zero.
So this isolates it to the point of input perhaps? Perhaps in the code behind the click action ā¦ or a data issue? But the data looks very like the data for the links that accumulate clicks. Except for the count ā¦
I checked to see if the ID was unique (and presumably the id is a primary key in any case, but I checked anyway in case the wrong record is being updated) ā¦ itās unique.
I noticed the URL generated in the ajax call with path /click/track uses an out of date slug which was changed during the life of the target Topic - could that have affected it? I know most code should rely on the id only, but is this an isolated case where it requires the slug to remain the same as when the link was created in order to work?
BOOM, thatās the problem!
Update the old slug in the source link to the new target slug and the counter appears.
The counters fail because the slug has changed - I think this should be fixed if possible as this should not be a dependency?
WORKAROUND: Update the source link to the new target slug and the counter starts working! @tophee@sam
Unfortunately this is a lot of manual work and you need to identify each mismatching link. A fix to remove this dependency to rely only on the id would be lovely
Would be also good to check:
if the bug affects the āarrived fromā counters in the post footers.
if adding a mid post location with a heading at the end of the url breaks the counter code e.g. #headingāmyheading because Iām not seeing any counters on those types of links ā¦
Unfortunately, I cannot confirm this. Although I found one link where the target slug had indeed changed, but multiple others where correct but without a counter nonetheless.
Ok but did fixing the slug add the counter in that instance? Worked for me. You may need to impersonate a user to accumulate a count (not sure if it registers admin clicks? Might not. Hence you need user account to check?)
Is it possible no user has clicked those links where the slug was up-to-date in the link? Donāt think using admin account is valid check.
i also think accumulation presently isnāt supported for targets involving mid post headings.
So you are saying that internal links will be counted if they donāt have a username appended but not if they do? (If so, is that intended behaviour and if it is why?)
This was one of the first things I checked before I wrote the post and could not confirm it. I have a long table-of-contents type post in which I intentionally omitted the username in order not to skew my stats, but none of the (internal) links had a counter. And this was the case also yesterday. Since people use that post a lot, itās impossible that none of the links were clicked.
Looking at it today, however, I see some link counters appear for internal links. What has changed since yesterday? We upgraded to latest via a rebuild (because we had to remove the deprecated github linkback plugin).
So, if this ever was a bug (I was never sure from the start, because I wasnāt sure what the intended behaviour was), it may be fixed now.
But does anyone understand what was the cause of this? It looks like someone broke it and fixed it without even realizing it?
Or perhaps there are several things coinciding here? One is the thing with the appended username (which didnāt explain things for me), and another thing is some bug that was fixed in a recent commit.
an out of date slug tested on latest, still not working/supported - slugs have to be identical to target.
a username (taking Jeffās word for it, not tested).
a heading (mid-post) specific link? tested on latest, still not working/supported
Because I donāt think these are supported at the moment and will still fail.
Also Iāve just edited a page (changed just one link) and most of the counters were reset to zero and this is reflected in the database ā¦ (according to Data Explorer).
@zogstrip I saw you were looking at this, you might be interested:
Do we need to rebake posts?
Does rebaking fix out of date slugs?
Does rebaking reset counters?
Why would an edit of one link, reset all counters?
Some additional observations: I just changed the ownership of that table-of-content post I mentioned earlier and the effect was that all (both internal and external) links had their counters reset to 0; all but the first link in the post (which is an external link).
So there is definitely some huge incoherent behaviour here.
But apart from that it would be more coherent if all counters were reset (or only internal ones or only external ones), Iām wondering whether a change of post ownership should/needs to reset any counter at all? After all, information is being destroyed here.
My proposal would be that neither rebaking nor change of ownership should reset counters.