anchor tags

How To Track Anchor Tags in Google Analytics

In most cases, installing Google Analytics to track your websites traffic is as simple as copying and pasting the tracking code.

The Problem

The above code is a simple example of the Universal Tracking code that Google Analytics uses to track each page view. Each time the page is loaded, the script sends a notification to Google to track the page view along with various other information. This however poses a problem for parallax or single page websites as the tracking code does not track the users clicks on the anchor tags that they use to scroll through the page.

The Solution

Until Google updates their analytics to take this issue into consideration, we’ll have to hack the code a little. We’ll start by editing the following two lines in the analytics code:



By adding in the following code, we are telling Google Analytics to track the entire URL including the anchor tag and we can link users directly via an anchor and it will be added the the statistics. This however does not solve the issue of users clicking on the menu links that scrolls through various other content on the page. As mentioned previously, the tracking code is sent to Google once when the page is loaded. To fix this, we simple add the following javascript code to the footer of the page.


By doing this, we’re telling the browser that each time a link within the class of “menu” is clicked, send a notification to Google Analytics with the anchor tag.

Google Analtics Anchor Tag

Questions? Comments? Leave a note in the comments below or reach out us at Follow us on Facebook and Twitter for more nonprofit marketing tips, and sign up for our newsletter for a monthly update from our nonprofit marketing pros!