Tracking Outbound Links
An
outbound link is when a user clicks on a link on your site to another site.
When a user clicks on a link that goes to another page or site, use the following recommended methods:
IMPORTANT: Do not put a 'gator.logEvent' call in the 'onclick' event on a link. This will not work consistently because browsers will sometimes
abort all processing and navigate to the next page before the event can be recorded.
This is INCORRECT and will not work in all cases:
<a href="/somepage" onclick="gator.logEvent('Exited Signup')"> wrong
In order to prevent this problem, there is a special call that will consistently track outbound events:
gator.logOutbound(eventName, destinationUrl, data);
Parameters:
eventName | The name of the event you wish to track. This is the same as the gator.logEvent event name |
destinationUrl | The location to navigate to after the event is recorded. This can a name or a url. |
data | Data to attach to the event. This is the same as the gator.logEvent data parameter. |
Example: Tracking on <a>
tags
<a href="/somepage" onclick="gator.logOutbound('Exited Signup', this.href)">Leave Page</a>
This call will record the 'Exited Signup' event, then navigate to 'this.href', which is the link specified in the tag's HREF attribute.
Example: Tracking on <a>
tags (part 2)
<a href="#" onclick="gator.logOutbound('Exited Signup', '/somepage')">Leave Page</a>
This call will record the 'Exited Signup' event, then navigate to '/somepage'. This call differs from the above call since the HREF attribute is not set on the element and therefore needs
to be specified on the gator.logOutbound call.
Example: Tracking on an image click
<img src="image.gif" onclick="gator.logOutbound('Image Click', '/somepage')">Leave Page</a>
This method can also be used on DIVs or any other element that will navigate the user off the page.
Example: Attaching this call to an event
<a id="myLink" href="#">Click here to track event</a>
<script>
document.getElementById('myLink').onclick = function () {
gator.logOutbound('myLink Clicked', '/somepage')
};
</script>
Example: Attaching this call to an event (using jQuery)
<a id="myLink" href="#">Click here to track event</a>
<script>
$('#myLink').click(function () {
gator.logOutbound('myLink Clicked', '/somepage');
});
</script>
Example: Attaching this call to all <a>
tags (using jQuery)
<a id="myLink1" href="#">Click here to track event called 'myLink1'</a>
<a id="myLink2" href="#">Click here to track event called 'myLink2'</a>
<script>
$(function () {
$('a').click(function () { gator.logOutbound(this.id, this.href) })
})
</script>