How to track clicks in sidebar or in any element with Google Analytics

By: Ilkka Mäkinen | Published: 6 September, 2016 | In: Google Analytics

Do you know how many of your visitors actually click the links in your sidebar? Or those social sharing buttons? How about those related articles under your blog posts?

Here’s how to find out with Google Analytics, enjoy!

How to track clicks in sidebar or inside any element

Yo brochacho, we didn't forget to track those clicks in our sidebar did we? 

Why should you track these metrics in the first place?

My answer is, if you want to improve your website in order to grow your audience, leads or sales, you need to know how every part of your website is performing and make decisions based on facts instead of personal preferences and guessing.

You might love the design of your site. The sidebars, content sliders, images, all of it. Maybe it’s the best you’ve ever seen. Or maybe you hate it, doesn't matter.

You are not the target audience of your website.

Decisions based on personal preferences and opinions rarely correlate with what actually works for the visitors.

So it's best not to get attached to anything on your website. Be prepared to question everything. Keep asking things like:

  • What is the purpose of that element?
  • Are people actually clicking the links in it?
  • If not, should we ditch it?
  • Is it hurting conversion my rates?
  • How do mobile users interact with the it?
  • And so on...

In order to get better, constantly track how every part of your site is performing and change things that are not working. Sometimes you need to do a little bit of extra work to do this, but it's well worth the effort.

This brings us to tracking click events in you sidebar or inside any element. This is not possible out of the box in Google Analytics, but you can do it with the help of Google Tag Manager, without wrangling with code.

So here's how to set up custom event tracking:

Step 1: check the class or the id attribute of the element you want to track

Open a page containing an element you want to track, right click on the element/area and select “inspect element” (works out of the box in Chrome and Firefox).

In the opening panel you can locate the class or id of that element by hovering your mouse over the elements. For example here a sidebar has a class “sidebar”:


Copy the class or id for later use.

Step 2: Login to Google Tag Manager and create a trigger

If you haven’t used Google Tag Manager before, you will be prompted to create an account for your site (you can create accounts for all of your sites anytime later on). Add your site information and embed the tracking code to your site according to the instructions.

Once you’ve created the account,

  1. head on to Variables down in the left hand menu and
  2. click Configure to enable the Click Element in default variables


In the opening view activate the Click element:


Then head out to Triggers and create a new trigger. Give it a descriptive name and select type “Just Links” from under “Click”:


Configure the trigger with following settings:

  1. Enable wait for tags
  2. Enable check validation
  3. Add a filter where you want the trigger to fire, in my example here the page url has to contain “/news/”
  4. Select “just some links” and select conditions: click element that matches CSS selector which is “.yourelementclass a” for targeting all links inside element which has a class “yourelementclass”. If you have an element with an id, type “#yourelementid a”


Step 3: Create a tag and connect it with your trigger

After saving your trigger head out to the tags and create a new tag. Configure the settings:

  1. Select universal analytics to tag type
  2. Add your GA tracking ID
  3. Set track type to Event
  4. Give a descriptive event category and action (which you will see in you Analytics)
  5. For label you can select {{Page Url}}
  6. Select TRUE for the non-interaction hit if you don’t want event tracking to interfere with your bounce rates (if you don’t want to count it as a bounce if a visitor doesn’t click a link in the sidebar and fire the trigger)


Subscribe to our newsletter

Get the latest expert advice from our blog on Excel, WordPress, search engine optimization, Google analytics and Adwords straight to your email.

Next, select the trigger to fire with your new tag:


Save and preview to test for problems. When all is set publish to get your new event metrics to your live site.

Step 4: Check real-time event tracking in Google Analytics

Sign in to your Google Analytics and open up the events monitoring from under real-time. If you go to your site and click on the links in your sidebar/selected element, you will see it in the real time events tracking:


Step 5: Monitor click events in your sidebar

After a few weeks when you’ve gained enough data, you can analyse how visitors click the links in your sidebar. You can see the number of events per pages in Behaviour > Events > Pages.

To see more than just the bulk of events per page, select for example the event category to your secondary dimension. Then you’ll see the page on the first column and event category on the second column:


To find out how many page views have included clicks in the sidebar, it’s useful to first create a new calculated metric that gives us events per pageviews.

Head out to the admin section and select calculated metric:


Create a new calculated metric with the following details:

  • Name: Events per Pageviews (or some other descriptive name)
  • Formatting type: Percent
  • Formula: {{Total Events}} / {{Pageviews}}


After saving, go to customization and create a new custom report with the following settings:


In the metric groups, select for example the total events, pageviews and your new events per pageviews.

Add Event Category to dimension drilldown.

Save and you will be prompted to you custom report. Now you will be able to see the total events, page views and the share of events per page views like this:


In this example case, about 20% of page views in news articles have included a click in the sidebar. That's not a bad performance, but the next thing I would do is to A/B test whether or not having a sidebar is hurting my conversion rates on certain pages.

If you want to see a more detailed breakdown of events triggered on your pages, you can select “page” as your secondary dimension.

Note that you can’t see pageviews or events per pageviews with this setting (page as your secondary dimension), so you have to calculate events per pageviews by hand.

That's it for this article. If you enjoyed it, be sure to subscribe to our newsletter to get all the latest articles directly into your email. Thanks for reading and until next time!

By: Ilkka Mäkinen | Published: 6 September, 2016 | In: Google Analytics

Sign up to our newsletter

Get the latest posts on Excel, WordPress, SEO, Google analytics and Adwords directly into your inbox.

Want to stop messing about and learn to use Excel efficiently?

Save your spot in our Excel Essentials course and learn how to make Excel rock!

Terms & Conditions

Conditions: Minimum number of participants is 3 persons on each course. If the course you are enrolling in does not reach the minimum number of participants it will be cancelled or postponed. We will inform enrolled participants in case there are not enough participants on a course.

Cancellations and substitutes: a) Cancellations confirmed more than 21 days prior to the date of the course are fully refundable and free of charge. Cancellations are to be made in writing to 

b) Cancellations made within 21 days of the date of the course may not be cancelled without incurring course charges fully.

c) Substitutes may be made at any time free of charge. TalentWire should be informed of any changes.

Pricing and invoicing: Payment for each course is to be received no later than 14 days prior to the course start date. We will send an invoice after your booking has been confirmed. Inform us of any special arrangements you require for your invoices.

All prices are as stated and are exclusive of VAT which will where appropriate be charged at the current rate.