Possible to add Google Analytics outbound traffic tracking?
-
Hello,
I’d like to collect data on users clicking on the widget button as their method of exiting the site it is hosted on. Google Analytics supports exit tracking by adding the below code to href tags, with the ‘trackOutboundLink’ function defined in my site header.
onclick=”trackOutboundLink(‘https://www.example.com’); return false;”
Is there a way to add this to the widget link? I tried editing into the core_actions.php script that appears to generate the href tags, but it gave a fatal error, presumably because the widget doesn’t know the function is defined elsewhere in the site.
Halp?
The script code (in my header) straight copied from Google is:
<script>
/**
* Function that tracks a click on an outbound link in Analytics.
* This function takes a valid URL string as an argument, and uses that URL string
* as the event label. Setting the transport method to ‘beacon’ lets the hit be sent
* using ‘navigator.sendBeacon’ in browser that support it.
*/
var trackOutboundLink = function(url) {
ga(‘send’, ‘event’, ‘outbound’, ‘click’, url, {
‘transport’: ‘beacon’,
‘hitCallback’: function(){document.location = url;}
});
}
</script>The page I need help with: [log in to see the link]
- The topic ‘Possible to add Google Analytics outbound traffic tracking?’ is closed to new replies.