Data Studio
2.7K members online now
2.7K members online now
Ask questions about Data Studio
Guide Me
star_border
Reply

exit links

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

I have links exiting to a map site so people can get directions. How can I find out how many people are using this feature?

1 Expert replyverified_user

Re: exit links

Top Contributor
# 2
Top Contributor

 Hi :-)
This is pretty easy to do with the GA Autotrack plugin

 

You will need to add the autotrack.js to your site pages.

Download the master autotrack zip file from github

https://github.com/googleanalytics/autotrack

 

Unzip it and upload the autotrack.js file to whever you usually keep script files for your website on the server

(I usually keep min in a folder called assets)

 

Then add it to the head of section of your website just after the analytics tracking code snippet

<script async src='path/to/autotrack.js'></script>


Then edit your analytics tracking code snippet to include the following code

  ga('require', 'outboundLinkTracker', {
  shouldTrackOutboundLink: function(link, parseUrl) {
    var url = parseUrl(link.href);
    return /mapsdomainhere\.com$/.test(url.hostname);
  }
});

where it has the following line of code 

return /mapsdomainhere\.com$/.test(url.hostname);

change mapsdomainhere to the name of the domain that you are linking out to eg if you were linking out to facebook then the could would read as the following instead:

return /facebook\.com$/.test(url.hostname);


So by the time you are finished your tracking code should look similar to the following:

<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-XXXXXXXX-YY', 'auto');
  ga('require', 'outboundLinkTracker', {
  shouldTrackOutboundLink: function(link, parseUrl) {
    var url = parseUrl(link.href);
    return /mapsdomainhere\.com$/.test(url.hostname);
  }
});
  ga('send', 'pageview');

</script>

This should then track all clicks outgoing to the maps domain with the 
Event Category = Outbound Link
Event Action = click
Event Label = the url of the outgoing linked website that was clicked

 

 

 

 

Bronwyn Vourtis, Google Analytics Top Contributor
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here