Analytics
4.6K members online now
4.6K members online now
Dive into multiple domain (Cross/Sub) tracking, implementing Ecommerce and Enhanced Ecommerce, setting up Event tracking, and Universal Analytics code.
 
Guide Me
star_border
Reply

Need help tracking outbound links

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hi all.  I'm a novice at adding code to my website, and need some help setting up tracking for outbound links on my page.  Clients would like tracking, and I can't figure out how to set it up.  I'm in unfamiliar territory!

 

1) I've read this: https://support.google.com/analytics/answer/1136920?hl=en  

 

but I'm unsure where the code goes.  I use a Google Analytics plug-in on my site, so should I put it there?

 

2) I'm unsure where to add the onclick attribute after the code.

 

Basically, I don't know what I'm doing at all and need some help!

1 Expert replyverified_user

Re: Need help tracking outbound links

Top Contributor
# 2
Top Contributor
Hi :-)
I'm assuming when you say plugin you are meaning a wordpress plugin?
If so, then which plugin are you using, as most of them offer configuration options for tracking outbound links
and similar such as file downloads etc
Bronwyn Vourtis, Google Analytics Top Contributor
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here

Re: Need help tracking outbound links

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭
Yes! I'm using a Wordpress plugin- it's just called Google Analytics. When I go to edit it, the only thing it has is code :/ That's fine, I just don't know where to put the tracking code.

Re: Need help tracking outbound links

[ Edited ]
Top Contributor
# 4
Top Contributor

Hi :-)
If its the plugin I am thinking of, it just needs you to enter the tracking id is that correct?

 

Does the current active theme offer an a settings/option to add script to the footer of the site?

If so.. then the following script needs to be added:

<script>
/**
* Function that tracks a click on an outbound link in Google 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>

Is the link in a post or page? If so then you need to make sure you have the editor set to Text (not visual)
There are two tabs at the upper right of the editor

Look for the code for the link and edit it to add the red bolded code just make sure you change the http://www.example.com

to reflect the actual link http://www.example.com

<a href="http://www.example.com" onclick="trackOutboundLink('http://www.example.com'); return false;">Check out example.com</a>

 

For future reference, you may want to look into the following plugins, they offer WordPress users much more functionality for configuring Google Analytics

https://wordpress.org/plugins/google-analytics-dashboard-for-wp/

https://wordpress.org/plugins/google-analyticator/

 

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

Need help tracking outbound links

Visitor ✭ ✭ ✭
# 5
Visitor ✭ ✭ ✭

I am using Go Daddy website builder. I cannot figure out why outbound analytics is not even showing up on my reporting dashboard. I have these lines of code in the HTML editor:

 

1. analytics.js tracking code

 

You can add <strong>HTML</strong> directly into this element to render on the page.<p><p>Just edit this element to add your own HTML.
<script>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-I HAV EMY CORRECT NUMBER HERE']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src=('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>

 

2. Outbound script

 

<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>

 

3. onclick attribution (I am clueless about this one).. We want to see if people are going to our amazon page from our site (there is an amazon button). https://www.amazon.com/FSTI-12-5-Sodium-Hypochlorite-Bleach/dp/B01J4ERF3W

 

You can add <strong>HTML</strong> directly into this element to render on the page.<p><p>Just edit this element to add your own HTML.
<a href="https://www.amazon.com/FSTI-12-5-Sodium-Hypochlorite-Bleach/dp/B01J4ERF3W" onclick="trackOutboundLink('https://www.amazon.com/FSTI-12-5-Sodium-Hypochlorite-Bleach/dp/B01J4ERF3W'); return false;">Check out example.com</a>

 

 

Please help and thanks in advance!

 

Need help tracking outbound links

Visitor ✭ ✭ ✭
# 6
Visitor ✭ ✭ ✭

 

Hee Stormey,

 

You are mixing up the old ga.js and analytics.js.

 

The code you have under 1. Is ga.js not analytics.js. So, the question is. Do you have Universal Analytics or Classic Analytics?

 

Assuming you have Universal Analytics, you have to have the following code:

 

1.

(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-XXXXX-Y', 'auto');
ga('send', 'pageview');

 

2.

var trackOutboundLink = function(url) {
ga('send', 'event', 'outbound', 'click', url, {
'transport': 'beacon',
'hitCallback': function(){document.location = url;}
});
}

 

I have just tested it and it works. 

 

It basically means you have to upgrade your initialization code to analytics.js. Then it works, because the WordPress part is already analytics.js.

 

Does it work for you?