Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
If cross-domain link tracking is switched on, links to domains in the relevant array should have a long string of parameters attached to them. This requires GA to override the default behaviour of the browser and stop it from sending the user directly to the URL in the link. This fails with the GA module, however, because, although the correct _link method is passed into gaq at line 49 of googleanalytics.js, it does not then return false.
Adding "return false;" at line 50 fixes this.
Comment | File | Size | Author |
---|---|---|---|
#9 | 1608310+Cross-domain+link+tracking+fails+because+it+does+not+return+false.patch | 743 bytes | hass |
#7 | 1608310+Cross-domain+link+tracking+fails+because+it+does+not+return+false.patch | 742 bytes | hass |
Comments
Comment #1
hass CreditAttribution: hass commentedComment #2
jeremyo CreditAttribution: jeremyo commentedSorry, I'm not sure how closing this helps. It's in Google's own documentation that in order for cross-domain tracking to work you need to return false.
https://developers.google.com/analytics/devguides/collection/gajs/method...
Otherwise _link() or _getLinkerURL() will not override the browser's default behaviour when you click a link, which is to follow that link. To tell if it's working or not, simply turn it on and see whether a link that it should work on has a query-string appended to it, something like:
?__utma=1.887369289.1337963650.1338020967.1338550310.3&__utmb=1.1.10.1338550310&__utmc=1&__utmx=-&__utmz=1.1337963650.1.1.utmcsr=xyz.org|utmccn=(referral)|utmcmd=referral|utmcct=/corporate/privacy-copyright&__utmv=-&__utmk=13927991
If it doesn't, it ain't tracking, and it certainly isn't for me, nor can I see how it possibly could without return false. Adding it fixes it.
Thanks, Jeremy
Comment #3
hass CreditAttribution: hass commentedIt's noted in foc that _link delays itself by a fraction of a second. Returning false cause many side effects.
Comment #4
jeremyo CreditAttribution: jeremyo commentedHmm, but without it cross-domain tracking doesn't work, which is also pointless.
"Return false;" is only needed within that "if" test, but does it prevent other things that need to be triggered by that click? If so then there is still a bug because it needs to prevent the click from causing the browser to follow the link: it has to override it with the link-tracking URL or it's not working.
Comment #5
jeremyo CreditAttribution: jeremyo commentedSorry for reopening this, Hass, but I can't consider it closed. I don't know what you did to try to reproduce the bug but if your own test sites are not set up for cross-domain tracking you can always take a look at mine. If you go to http://www.iwm.org.uk/ and debug the javascript (a little awkward because the JS is aggregated), put a breakpoint at the following line in your code:
Then click the link to "Shop" in the top navigation. You'll see it break on that line but when the link is followed it does not have the query string that is required for cross-domain tracking. If you know of examples where this works I'd be interested to see them. This is fixed by by suggestion, which should have no implications for anything else because it is inside the final "if" statement before a user leaves the website
Comment #6
hass CreditAttribution: hass commentedjQuery command for return false is
preventDefault();
as I know. http://api.jquery.com/event.preventDefault/Comment #7
hass CreditAttribution: hass commentedCould you guys give this patch a try, please?
Comment #8
hass CreditAttribution: hass commentedComment #9
hass CreditAttribution: hass commentedIt need to be
event.
or it has no effect. New patch.Comment #10
hass CreditAttribution: hass commentedhttp://drupalcode.org/project/google_analytics.git/commit/9b86c78