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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

hass’s picture

Status: Active » Closed (fixed)

Already implemented for years.

decibel.places’s picture

@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)

hass’s picture

Outgoing links are tracked as EVENTS. See project home if you cannot find event trackings.

decibel.places’s picture

oic thanks - now I see the outgoing urls in GA

Anonymous’s picture

Status: Closed (fixed) » Active

Tracking 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

hass’s picture

Title: Google Analytics: enable tracking outbound links / add code inside trackPageview() » Track outgoing links as targets / Disable event tracking optionally for outgoing links
Version: 6.x-2.2 » 7.x-1.x-dev

Is 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.

hass’s picture

Tabbycat’s picture

The 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!

hass’s picture

Status: Fixed » Active

Sound like a bug. Can you share a patch?

hass’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

hass’s picture

Status: Closed (fixed) » Active

@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.

hass’s picture

Title: Track outgoing links as targets / Disable event tracking optionally for outgoing links » Rollback: Track outgoing links as targets / Disable event tracking optionally for outgoing links
hass’s picture

Status: Active » Fixed

Rolled back D6 and D7 patch.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.