How to Track External Links using Google Analytics?

Google Analytics allows you to track how often viewers on your website click particular links on your website. Links to internal pages are automatically tracked, however you must add JavaScript code to links that point to pages outside of your own website (Exit Links) in order to track them. There are couple of ways you can track an outbound link in Google Analytics (GA) Using _trackPageview or by utm method. Let us first see the difference between these two methods.

_trackPageview method

The _trackPageview JavaScript creates a fake pageview. This method is most commonly used to track outgoing links or downloads. The _trackPageview attribute is placed within the <a> tag and looks like this: onClick="javascript: pageTracker._trackPageview(’/example/some-blue-link’). The /example/some-blue-link becomes a new pageview and it is tracked in GA as a new pageview – so it will increase your pageview count. These fake pageviews will now show up in your “content” reports.

utm method

The utm method involves telling GA what the campaign name is (you define this), the source (typically something like Google), and the medium (typically something like PPC) – as well as a few other options. This method is most commonly used in tracking PPC campaigns (as Google AdWords does this automatically), email campaigns, and other external campaigns that link back to your site. If you choose to tag your links with utm, it erases all referral information. In other words, if someone arrived at your site via a Google organic search; but they then clicked on an internal link that had the utm tagging, you lose the insight that the visitor originally came from the Google organic search (the source and medium). Instead, you see the new source and medium information that you manually entered. For me, that’s not a good option. I need to know where the visitor came from as much as I need to know what internal links they’re clicking on. Lets track an exit link on a webpage using _trackPageview method.
  1. Open the web pages with the links in your web page editing software. Locate the link you would like to track.
  2. Add the following JavaScript into your “A HREF” tag, before any other code used by Google Analytics: onClick="javascript: pageTracker._trackPageview('/example/some-link.com');" Change the portion in the parentheses to the location you would like to have listed in your tracking report. Thus after adding the onclick event, the link might look like:
    <a href="/some/where/on/internet" onClick="javascript: pageTracker._trackPageview('/some/where/on/internet');">Check this</a>
    Code language: HTML, XML (xml)
  3. Save the web page file. Upload it to your website.
  4. Verify that your links are being tracked by checking your log in Google Analytics after a day or two. Your links appear in the “Top Content” report. The links you added tracking code to should now appear in the report.
With Google Analytics it is very simple and easy to track an outbound link.

View Comments

Share
Published by
Viral Patel
Tags: google analytics seo track link

Recent Posts

  • Java

Java URL Encoder/Decoder Example

Java URL Encoder/Decoder Example - In this tutorial we will see how to URL encode/decode…

5 years ago
  • General

How to Show Multiple Examples in OpenAPI Spec

Show Multiple Examples in OpenAPI - OpenAPI (aka Swagger) Specifications has become a defecto standard…

5 years ago
  • General

How to Run Local WordPress using Docker

Local WordPress using Docker - Running a local WordPress development environment is crucial for testing…

5 years ago
  • Java

Create and Validate JWT Token in Java using JJWT

1. JWT Token Overview JSON Web Token (JWT) is an open standard defines a compact…

5 years ago
  • Spring Boot

Spring Boot GraphQL Subscription Realtime API

GraphQL Subscription provides a great way of building real-time API. In this tutorial we will…

5 years ago
  • Spring Boot

Spring Boot DynamoDB Integration Test using Testcontainers

1. Overview Spring Boot Webflux DynamoDB Integration tests - In this tutorial we will see…

5 years ago