Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SOLVED Outgoing links analytics?
#1
So I'm looking to get a little analytics on our site. So far, it looks like I can see inbound stats using Google Analytics, but I'm not sure how to track outgoing links (i.e. to social media etc).

Is there anything like this available?
Reply
#2
Turns out with a little trickery it can be done.

https://support.google.com/analytics/ans...6920?hl=en

My adapted version:
<script>
/**
* Source: https://support.google.com/analytics/ans...6920?hl=en
* 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(event) {
var url = $(event.target).attr("href");
//Check if this is an out-bound link, and GA has been instantiated
if(typeof ga != "undefined" && !(url.startsWith("/") || url.indexOf("domain.com") > -1))
ga('send', 'event', 'outbound', 'click', url, {
'transport': 'beacon',
'hitCallback': function(){document.location = url;}
});
}
//Once the DOM has loaded, attach a click handler to all the available links
$("body a").on("click", trackOutboundLink );
</script>
Reply




Users browsing this thread: 1 Guest(s)