简体   繁体   中英

Track outbound Google Analytics link in new analytics.js

I have new analytics.js on a new webpage. This webpage has to be linked analytically to the existing webpages, managed by other people.

They sent me a line of code to do it:

_gaq.push(['_link', $(this).attr('href')]);

This is the old version of the analytics. I understand, that the same thing in new analytics can be accomplished using:

ga('send', 'event', [eventCategory], [eventAction], [eventLabel], [eventValue], [fieldsObject]);

To where on the second I should put '_link' and $(this).attr('href') parameters?

There is not much documentation on the Google website. I have enabled official linker plugin, but they say, that this is not enough.

Edit: Bit of js after loading analytics.js looks like this:

ga('create', 'UA-12312312-1', 'auto', {'allowLinker': true});
ga('require', 'linker');
ga('linker:autoLink', ['friendlydomain.com'] );
ga('set', {page: window.location.href});
ga('send', 'pageview');

Where UA-12312312-1 is their tracking id. I can see, that ga parameter is added to the links going towards friendlydomain.com

This line of code:

_gaq.push(['_link', $(this).attr('href')]);

is not for outbound link tracking, it's the linker for Cross Domain tracking (see the documentation for the old ga.js library ).

To accomplish the same with analytics.js it would be best to use the autolink plugin . This appends the client id to outgoing links; the linked pages must have linking enabled in the configuration to receive the parameter from the url and set it as client id when the tracker is created. GA will then use the client id to merge the sessions on both domains into one.

This will work only if both pages run analytics.js. Also you need to set both domains in the referral exclusion list in the property settings.

analytics.js is fairly flexible, so it mostly depends on how you want to view the data on the GA site.

One possible solution would be...

ga('send', 'event', 'link', 'click', $(this).attr('href'));

Also, the docs are fairly comprehensive. You might consider re-reading them here: https://developers.google.com/analytics/devguides/collection/analyticsjs/events#event_fields

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM