Analytics
1.9K members online now
Understand information in your reports and troubleshoot reporting issues such as self-referrals, (not set) data, and inaccurate information
 
Guide Me
star_border
Reply

Adding track outbound links to in-page analytics

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hello,

I have recently implemented the "Track outbound links" under: 

https://support.google.com/analytics/answer/1136920?hl=en

And it is working fine but I would like to know if there is a way to tweak this snippet of code so it could include the original page where it was clicked from to exit the page? Events merely displays the link clicked and the amount of times a user clicked on the link to exit.  Is there also a way to include outbound links in my in-page analytics in percentages like the rest of the links on my page that link to a page on my server? 

Thanks a lot

1 Expert replyverified_user
Marked as Best Answer.
Solution
Accepted by topic author Claudia T
December 2015

Re: Adding track outbound links to in-page analytics

Top Contributor
# 2
Top Contributor
Hi Claudia,

I'm no actual JavaScript wizard but maybe you could change the line to something like

ga('send', 'event', 'outbound', 'click', document.location '->' url, {

to make this work - it's just a guess ... ;-)

Even if that worked, a much better possibility would be using Google Tag Manager (GTM) for that [1]. The smart thing about it is that you don't have to include any code or decorate any outbound link on your website any more.

The other thing, if you want to treat an outbound link as kind of normal page view you just have to define it as ordinary page view in GTM instead of using an Analytics event for that. Then, you'd see it in all page reports, behavioural-flow reports etc. You just would have to define a virtual name for the outbound link.

Christoph

[1] http://www.simoahava.com/gtm-tips/track-outbound-links-in-gtm-v2/

Re: Adding track outbound links to in-page analytics

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭
Excellent, Thanks so much for the help!

Adding track outbound links to in-page analytics

Visitor ✭ ✭ ✭
# 4
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!