GA requires addition of artificial URLs to tracking code on links to external web pages to track the exit links.
http://www.google.com/support/analytics/bin/answer.py?hl=en&answer=72712
note that the sample code on that page is wrong because the nested double quotes break the code, it should be with single quotes and double quotes:
<a href="http://www.example.com" onClick="javascript: pageTracker._trackPageview('/G1/example.com');">
Perhaps the GA module can add an artificial URL to all outbound links such as
onClick="javascript: pageTracker._trackPageview('/ExitURL/linkURL');"
where linkURL is the link of the anchor tag
additional customization is possible, however this would be very helpful to track exit pages and links
currently the Google Analytics module allows adding code before and after trackPageview()
so this would add code inside the function call
Comment | File | Size | Author |
---|---|---|---|
#2 | GA-module-b4-and-after-trackPageview.jpg | 56.09 KB | decibel.places |
#2 | GA-ExitURL-manual-link.jpg | 32.17 KB | decibel.places |
#2 | GA-ExitURL-atort.jpg | 64.32 KB | decibel.places |
#2 | GA-no-results-for-aa.com_.jpg | 29.76 KB | decibel.places |
#2 | GA-no-tracking-code-external-link.jpg | 13.67 KB | decibel.places |
Comments
Comment #1
hass CreditAttribution: hass commentedAlready implemented for years.
Comment #2
decibel.places CreditAttribution: decibel.places commented@haas
apparently it's not implemented
it's possible to add code BEFORE or AFTER trackPageview() - but not the artificial URL INSIDE the function to track exits to external links
(GA-module-b4-and-after-trackPageview.jpg)
nor can we choose to have the pageTracker code applied to external links
you can see the code I manually added (GA-ExitURL-manual-link.jpg) and the results showing in Google Analytics, for a link to a Facebook page (GA-ExitURL-atort.jpg)
a link to American Airlines (aa.com) does not show up in Google Analytics (GA-no-results-for-aa.com_.jpg) because no code is added to the link (GA-no-tracking-code-external-link.jpg)
Comment #3
hass CreditAttribution: hass commentedOutgoing links are tracked as EVENTS. See project home if you cannot find event trackings.
Comment #4
decibel.places CreditAttribution: decibel.places commentedoic thanks - now I see the outgoing urls in GA
Comment #5
Anonymous (not verified) CreditAttribution: Anonymous commentedTracking outgoing links as events works nicely.
But still tracking outgoing links with an "artificial URL" would help a lot. Events can currently not be tracked as targets in GA. That's a big disadvantage if it comes to Adsense optimization.
Is there any possibility to get that solved? Thanks, RV
Comment #6
hass CreditAttribution: hass commentedIs it enough to create an optional checkbox (e.g. in advanced settings) that disables event tracking only for outgoing links or do we need to disable event tracking for downloads and mailto, too? I guess outgoing is enough... Site overlay will for sure break with this change.
Can you share a patch, please.
Comment #7
hass CreditAttribution: hass commentedD6, http://drupal.org/cvs?commit=495142
D7, http://drupal.org/cvs?commit=495140
Comment #8
Tabbycat CreditAttribution: Tabbycat commentedThe code doesn't cancel the original click event, which it should do if it's going to hook in its own setting of document.location after a short timeout. Presumably the browser could have started to load the page from the original click in the brief time before the setTimeout goes off. In the linked answer on the Google site there's a comment "Be sure to use return false for the onClick handler, because without that statement the browser will follow the link before the recordOutboundLink method has a chance to execute."
This is related to another aspect of this code - if you have a target attribute set on the link that isn't respected by this code or the linked answer on the Google site because it sets document.location on this document in the timeout event. Coupling this with not canceling the original click then what happens if you have e.g. foo is that the *current* window/tab is changed to the linked site by the javascript code in setTimeout *and* the original click goes off so you also get the linked site opened in a new window/tab.
So I think there needs to be a warning that the track outgoing links code shouldn't be used if targets are used on links!
Comment #9
hass CreditAttribution: hass commentedSound like a bug. Can you share a patch?
Comment #10
hass CreditAttribution: hass commentedFollow up bug is at #1057890: Prevent browsers default behavior if monitored links are clicked.
Comment #12
hass CreditAttribution: hass commented@rvinne: I'm going to role back this code change for the reason of http://analytics.blogspot.com/2011/04/new-google-analytics-events-goals.... really bad that this feature came out sooo short after I've implemented these workaround.
Comment #13
hass CreditAttribution: hass commentedComment #14
hass CreditAttribution: hass commentedRolled back D6 and D7 patch.