How to Track Multiple Links to the same URL automatically in Google Analytics
- Eivind Savio
If you have multiple links on a page pointing to the same URL, you are not able to identify in Google Analytics which link were clicked. Neither the In-Page Analytics report or the Navigation Summary report (or what somebody calls a Next Page report) will show you this.
The usual method to overcome this problem is to manually tag links, which is a method that often requires programmers (and may cause SEO problems and duplicate content if done wrongly).
Because of this I have created a script that is easy to implement and configure. The script will automatically track which link the user clicked on, the Anchor Text of the link and the Link ID (number). The information is stored as Events in Google Analytics.
And as a "bonus" I have included a Excel Spreadsheet using the Google Analytics API that makes reports more readable.
How to Automatically track Multiple Links to the same URL
Open up ga-track-link-clicks.js and configure the settings (shown below).
||The name of the page you are going to analyze.
3 different options to identify the page:
||Use Anchor Text of the link to identify which link the user clicked on. If the link is a image and not a text link, the image URL will be used instead. If Anchor Text is missing, the text "Anchor Text Missing" will be used.
||Sometimes there can be several links on the same page pointing to the same URL with the same Anchor Text. In these occations the Link ID can help you to differentiate between the links.
||Should links to external sites also be tracked?
|trimPageName||Should pageName be trimmed for special characters?
- Title Tag will be used to identify the page (pageName).
- Link Anchor Text and Link ID will be used to identify which link the visitor clicked on.
- We are not tracking External Links.
- Special charachters are removed from the pageName.
- var pageName = "title"; // Name of the page you want to track/analyze. title/custom/url
- var trackAnchorText = true; // Track link Anchor Text? true/false
- var trackLinkID = true; // Track Link ID? true/false
- var trackExternalLinks = false; // Track External links? true/false
- var trimPageName = true; // Should pageName be trimmed for special characters? true/false
Implementing the script
The script is loaded as soon as the DOM has finished loading using addDOMLoadEvent.
The adddomloadevent.min.js and ga-track-link-clicks.js file must be implemented just after your Google Analytics Asynchronous script (between <head> and </head>):
- ** Google Analytics Asynchronous tracking script **
The Link Click Report
|Event Category||Link Clicks|
|Event Action||URL/Title Tag or Custom Name for the tracked page|
|Event Label||http://www.domain.com/url-to-page|Anchor Text|LinkID
Below is a screenshot showing the Event Report in Google Analytics with data for Clicked Links, Anchor Text, Link ID and Time spent before Click.
Because the Event Label report in Google Analytics can be a little bit confusing to analyze, I have created an Excel Spreadsheet that splits the Event data into different columns and makes the data more readable.
The Excel Spreadsheet is using the Google Analytics API.
- Download the Excel Spreadsheet (ZIP-file) and unzip the file
- Open the Excel file and activate macros.
- Go to the Settings sheet. Change "Sites" from YourWebsiteName to your site name.
- On the same line as your site name, insert your Google Analytics ID number. This is not your UA-XXXX-X ID, it's the ID in the Google Analytics URL (ex. https://www.google.com/analytics/reporting/dashboard?id=123456)
- Insert your Google Analytics username (email) and password in the Settings sheet.
- Select date period on the Dashboard. If you click on a date cell, a date picker will pop up to make it easier to select dates.
- Click Update Report.
The report works best in Excel 2007 or newer because of Conditional Formatting.
Visualising the data
Since the data isn't very visual, I like to create a kind of "click map", or more correct, a link color map in Excel. The first thing I do is to grab all the links from the page I want to analyze, and insert them into Excel (URL, ID and Anchor Text) as a reference.
Then I use different background color for links belonging to the menu, content, footer etc. using conditional formatting in my report. I have scripted Excel to do this automatically based on the Link ID. This makes it easier to visualise which part of the page the different links belongs to. Filtering by colors can also be very useful since you now can isolate different parts of the page.
The (censored) screenshot above, shows an example where I'm using Link ID to automatically identify the behaviour for different page areas for visitors that have converted. I can now attach outcome (money!) to page areas, links and message (Anchor Text). I've also found it easier to identify different buying modalities using this method.
This method will only work well on pages were the number of links don't change.
NB! The download doesn't include this functionality, but I show the screenshot as an example of how you can improve the spreadsheet.
Why not just use a Link Analysis/Heat Map tool?
The reason I made this solution in the first place was because I had a case where I wanted to know the outcome of the click, not just which links were clicked and how much they were clicked. In addition, I wanted a solution that was easy to implement for Google Analytics so I could avoid implementation of more tools in this specific case.
The Event Tracking report in Google Analytics will show you clicks tracked in connection to Ecommerce values like transactions, revenue and conversion rate.
If your outcome is not tied to Ecommerce, but regular conversion goals, you can find number of conversion by using Advanced Segments. There is already a predefined Advanced Segment called "Visits with Conversions" in Google Analytics.
So even if tools with Click Maps/Heat Maps reports will show you better click information (ex. if visitors clicks in a area they thought were a link), this solution makes it easy to track and connect different link clicks to outcome in Google Analytics.
What to be aware of
Although the script has built in some functions for improving reports like stripping away HTML in the Anchor Text, this is a "quick and dirty" method for identifying link clicks. Below are some points you should be aware of.
If the Page Name (Event Action) you are going to analyze contains some special characters, or you are using URL to identify the page, the Excel spreadsheet may not work properly. I have experienced problems with Norwegian characters, & and / to mention some.
I'm not a programmer, so this solution is maid mainly by banging my head against the wall.
With this in mind, test after you have implemented the script to see if other scripts are affected.
If your content changes or the number of links on the page changes, some of the links will get a different ID.
"Bad" HTML may affect the report. If a image is the "link anchor", src (source) to the image file has to be in single or double quotes to be tracked properly. Ex.
- src="/folder/image.jpg" and src='/folder/image.jpg" will be tracked like IMG-/folder/image.jpg
Sometimes the image anchor text will not be tracked by the URL. Instead the content of the Alternate Tag are used. Although it's not perfect, I can live with that. Feel free to improve the regular expression that grabs the image info.
Visitors using Google Translate or similar will also affect the tracked Anchor Text.
Bounce Rate and Time Spent
- Time spent on page/site can be affected by this script, especially if you set trackExternalLinks to true.
- Bounce Rate will be affected especially if you set trackExternalLinks to true. Since the script will track all type of link clicks, like file downloads and anchor links, this will affect (reduce) your bounce rate as well.
Download the Google Analytics Script and Excel Report
Happy tracking, analyzing and optimization of link clicks and outcome.
If you find some bugs I haven't seen, improves something, or just find the solution useful, feel free to drop a comment below.
- Comments are closed