AdWords is now Google Ads. Our new name reflects the full range of advertising options we offer across Search, Display, YouTube, and more. Learn more

Analytics
1.9K members online now
1.9K 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

Event Tracking

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hello, I'm interested in setting up google analytics tracking events to distinguish the number of bounces leaving our site to enter two other sites we are connected with but am having a difficult time as I am very unfamiliar with coding in general. I asked our coder to enter the following script into our page header

 

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

 

but don't think this was the correct direction since my google analytics events has not picked up anything. Can someone assist me with how I would make the script more specific to the two outbound sites we would like to track that are clicked from our page? Is there a certain section I am supposed to replace with info about the other two links? Both links are accessible = through a dropdown section from our main header.

 

Any basic suggestions are super helpful! Thank you

1 Expert replyverified_user

Re: Event Tracking

Top Contributor
# 2
Top Contributor

Hi,

 

Did you add the the code in bold to your links?

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

Once added, the events should appear in Google Analytics.

 

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

 

Hope this helps.


Arnold Majlath, Google Analytics Top Contributor
Was my response helpful? If yes, please accept it as solution.
Circle Me On Google+ | Visit me @ Redfly Digital