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.
The googleanalytics.js catches all clicks on links, but does not prevent the default browser behavior, what will not delay the target url loading and may break successfully logging of clicks as recording may be interrupted while loading the tracking code. As documented in http://www.google.com/support/analytics/bin/answer.py?hl=en&answer=55527 the script should wait fraction of a second.
As per http://fuelyourcoding.com/jquery-events-stop-misusing-return-false/ the default browser behavior should be blocked with event.preventDefault()
.
Comment | File | Size | Author |
---|---|---|---|
#2 | googleanalytics_event_preventDefault-D6.patch | 1.43 KB | hass |
#1 | googleanalytics_D7_event_preventDefault.patch | 1.95 KB | hass |
Comments
Comment #1
hass CreditAttribution: hass commentedPatch attached.
Comment #2
hass CreditAttribution: hass commentedD6 patch
Comment #3
Tabbycat CreditAttribution: Tabbycat commentedHi hass,
Thanks for looking at the issue. Taking a quick look at your patch I noticed that you've added "event.preventDefault();" in one path through the code where I think setTimeout isn't being done.. i.e.:
if (ga.trackDomainMode == 2 && isCrossDomain.test(this.href)) {
// Top-level cross domain clicked. document.location is handled by _link internally.
+ event.preventDefault();
_gaq.push(["_link", this.href]);
}
So my guess is that particular path through the code either should be calling setTimeout but isn't, or else by design it should allow the original event to still occur!
Comment #4
izmeez CreditAttribution: izmeez commentedsubscribing
Comment #5
jsquyres CreditAttribution: jsquyres commentedsubscribing
Comment #6
hass CreditAttribution: hass commentedAs we are not able to click a link programatically or at least I don't know how and many docs around the net say it is not possible - and I do not like to rebild a browser in javascript to be able to support custom javascript click cases - I keep it for now with the roled back patch. Maybe somedays we found a solution. Until than we may theoretically lose a very few hits as in past :-(