Reputation: 3264
I'm implementing google analytics into a website. This website has a page A that has two links to page B (on same domain).
I want track with GA which navigation the user used to come from page A to page B.
As far as I understand the google's devguides it's only 100% tracked when I use hitCallbacks.
Is this correct or are there better solutions than do a javascript redirect after GA event was successfully sent?
Upvotes: 1
Views: 319
Reputation: 2383
I believe you are looking for something called Link Attribution.
From the page:
You can tag your pages to implement an enhanced link-tracking functionality that lets you:
See separate information for multiple links on a page that all have the same destination. For example, if there are two links on the same page that both lead to the Contact Us page, then you see separate click information for each link.
See when one page element has multiple destinations. For example, a Search button on your page is likely to lead to multiple destinations.
Track buttons, menus, and actions driven by javascript.
To enable this, you simply need to add one of the following lines depending on which version you are using:
analytics.js/Universal Analytics:
ga('require', 'linkid', 'linkid.js');
ga.js/Legacy:
var pluginUrl =
'//www.google-analytics.com/plugins/ga/inpage_linkid.js';
_gaq.push(['_require', 'inpage_linkid', pluginUrl]);
Upvotes: 1
Reputation: 1062
If you have the GA tracking code on both pages, there is no need to use hitCallbacks. Simply add different events to each link from page A to page B.
In my experience, hitCallback is most useful for tracking outbound links - when the user clicks a link that leaves your site. On an outbound link, the new page often loads before your GA script has time to run and register the event. hitCallback solves that problem by ensuring that the event registers before the new page is loaded.
However, when the user is moving from one page to another in your own domain, GA will register the event while the user is on Page B (assuming it didn't get registered on page A). GA puts the event into its queue before moving from A to B. Once B has loaded, the GA script will process the queue and send the event to Google. This is the asynchronous nature of the GA script. GA went asynchronous back in 2009, and this article from that time give a good explanation of how it works.
The reason that this does not work on outbound links is that when the user's browser leaves your domain, the information in his browser's Javascript global variables is lost - that includes the events in the GA queue that have not yet been transmitted to Google. In such situations, hitCallback can be used to force transmission before leaving your domain.
Upvotes: 2