A recent client acquisition lead to a good question in the office…. ‘Is it possible to track clicks on # Anchors in Google Analytics?’ The question arose due to the client’s website utilising a single page format with tabs anchor linking to sections further down the page.
What are # Anchors?
Many websites use ‘Named Anchors’ on their pages for quick linking to specific areas of the page. For example, say you had an ‘About Us’ area at the bottom of the page and you wanted to have a tab at the top of the page link directly to that area:
In Source View, a completed anchor link would normally take the following form:
<a name=”about”> </a> (This code is placed where the clickable link will direct the user to)
<a href=”#about”>About Us</a> (The clickable link itself)
By default, Google Analytics will not report the pageview as index.htm#about, but rather just index.htm as Analytics does not track anything after # in a URL. So for our client’ website, which utilises #Anchors for all of the tabs on their website, a clear issue arose, ‘how do we then track when a user clicks one of these #Anchors?’
In order to track the hashtag in Analytics we need to make an amendment to the Tracking Code and include the ‘location.hash’ property.
Traditional tracking code:
Revised tracking code:
_gaq.push([‘_trackPageview’, location.pathname + location.search + location.hash]);
Note the inclusion of location.hash parameter above. This will request that Analytics now trigger a pageview that includes the #. It will now appear in the Content Drilldown report as index.htm#about
Without this customised code Analytics would show multiple index.htm pages each with a different number of Pageviews, but no # advising which #Anchor was clicked.
It is highly important to be able to track each #Anchor, otherwise you cannot track visitor behaviour accurately or how they interact with your website.
Using this solution with PPC Campaigns
It is possible to include the ‘#’ within the Destination URL of an Adwords ad and, once clicked, it will direct the user to the relevant #Anchor. However, Analytics will not record the #Anchor as the landing page; it will record the landing page as ‘/’. As Analytics records it in this way, you will see an inflated Visits figure for ‘/’.
You can verify this by comparing Landing Page Visits to the previous period deducting the No. Clicks received from the linked AdWords account. For example:
In AdWords there was 514 clicks during the period Mar 7, 2014 – Mar 11, 2014. Deduct 514 from 609 (below) and you are left with 95 which relates closely to the Organic Visits of 97 (below) for the previous period which did not have PPC active.
Side effects of this solution
Okay, so as you may be aware, the average time on site is calculated from entry to entry. This means, if the user does not visit another page, the time on site becomes zero, irrespective of the time spent on the Landing Page. So, because the #Anchors in this case are still within the same page, Analytics is not recording an Avg. Time on Page as the visitor is, in essence, not visiting other pages, but rather just ‘/’.
The only way that Analytics will track this is if the #Anchor link is on a separate page. This will negatively impact the Avg. Time on Page value attributed to the ‘/’ index page as shown below:
This solution can be used on both single-page sites where Tabs are present, and also multi-page sites where the requirement to track #Anchors is needed. With multi-page sites comes the opportunity for cross-page linking, which will provide more data for Avg. Time on Page.
I hope you have found this post useful. What are your experiences with tracking #Anchors in Google Analytics? I’d love to hear your comments and suggestions.
Main image courtesy of Roberta Cortese