How to track button clicks with Google Analytics

We’ve all seen websites with hotel reservations, affiliate marketing, and webinar signups where in order to make a purchase or become a lead, a visitor needs to go to a third-party page. Well, I have worked with a few like that and in every case tracking is the first thing that needs to be addressed. After all, if we do not know how many people completed the CTA, how could we claim that the campaign is a success?

This kind of tracking has an undeserved reputation of being difficult to implement. But in reality, all you need is Google Analytics code on your site and a little bit (honestly!) of coding.

But before you get started, do yourself a favor and check the following:

1. Make sure you are using the newer version of GA on your site. The on-page script I am using will not work with old Urchin code.

2. If your site is in PHP, GA’s new code may have a syntax conflict. This does not mean you can’t use the new code. It just means that you need to modify it to be

<script src=”“type=”text/javascript”>
<script type=”text/javascript”>
var pageTracker = _gat._getTracker(“UA-XXXXXXX-X”);

3. Make sure you have access to your website and can make code changes (DUH!).

Now, you are ready to get started.

Step 1. Set up the goal.

Let’s say, the goal is to track when a user clicks on your RSS subscribe button. Note: when they click on the button, there’s no guarantee that they’ll actually subscribe. Let’s also assume that at we have just one type of subscription and it is a big RSS button in the upper right.

1. GA Settings Page is your first stop. Click “Edit” for

Goal Setup

From the Conversion Goals and Funnel table, click “Edit” next to one of the not configured Goals.

  • Now, set the URL of the goal to be a non-existent page. For example:
  • Name your goal something like “RSS subscription”.
  • Use head match as your match type.
  • Done

Step 2. Tracking the clicks on the RSS button.

This is the part where you will be coding (just a little bit) and adding a javascript to track the onclick event on the RSS button. To track the button clicks, we need GA to register a “visit” to the fake page we created (

Now, we need to add the on-click tracking code to the RSS button. This is the code to use:

<a href=”/goal/example” onclick=”javascript:pageTracker._trackPageview (‘example’);”target=”blank”>

Step 3. Looking at your data.

Note: it may take time for the data to show so do not get discouraged if you are not seeing it within the first 72 hours.

You should see your RSS button clicks as a goal you set up:



Point It About the author
  • Frank

    This is great info.

    Many marketers are not aware that button clicks can be tracked so this will help many of them.

    March 26, 2010 at 10:32 am
  • xman

    Will this method work on a Submit button?

    June 3, 2011 at 4:23 pm
    • It should work on any clickable button.

      June 9, 2011 at 10:54 am
  • Billy

    Thanks for the great info! i never thought it would be as simple as this ^^,

    June 9, 2011 at 8:45 pm
  • Bente

    This may be a stupid question – but can the on-click tracking code …be put directly in the html?

    I work as a web editor in a cms, so I don´t do the coding, I only have access to the html on the content (text/pictures) that I myself put up.

    I want to track clicks on a button that leads out of the site.

    June 16, 2011 at 5:22 am
  • Shaun

    Is there any way to track button submissions without using Google Analytics?

    December 14, 2011 at 10:19 am
  • This is awesome information.

    Google analytic tracking codes have changed since 2010.
    Anyway we could get some updated code versions?


    March 2, 2012 at 5:28 pm
  • We just built a website that sends visitors to a third party site in order to complete the sign up process. Is there anyone you would recommend to have this done to our site by and what you you expect to pay?

    April 9, 2012 at 5:41 pm
  • Nadeem Siddiqui

    Hi, thank for the post it really helped. I have one question is it possible to track button click without setting up a goal. since there is a high frequency of customer on the website so i have to setup goal for each customer. Is there a way to track button click without goals. Please reply thanks

    May 24, 2012 at 12:09 pm
  • VP


    I have a website and there is button labelled “zip code”. Is it possible to capture data ( meaning zip codes) user enters there ?

    If yes, please provide me more inputs.


    June 12, 2012 at 11:03 pm
  • yes you can track button without setting up a goal, all you need to do is put this code to the page.

    var _gaq = _gaq || [];
    _gaq.push([‘_setAccount’, ‘UA-XXXXXXX-1’]);

    (function() {
    var ga = document.createElement(‘script’); ga.type = ‘text/javascript’; ga.async = true;
    ga.src = (‘https:’ == document.location.protocol ? ‘https://ssl’ : ‘http://www’) + ‘’;
    var s = document.getElementsByTagName(‘script’)[0]; s.parentNode.insertBefore(ga, s);

    August 17, 2012 at 12:29 am
  • Some great info, are the codes mentioned still valid. One of the things mentioned about new analytics is that it was going to be easy to track these thing without developers getting involved to add/remove code. Is there a better workaround now ?

    January 13, 2015 at 1:33 am
  • Hi
    Can you tell me do we need to set up a false page for each button we want to track?



    January 25, 2016 at 11:54 am
  • James

    Hi – I’m very new to this and am trying to work out if this is the same result that you can achieve with Google Tag Manager, or if this is something different. Can you help?

    March 4, 2016 at 8:08 am
  • Hello,
    it is a very interesting way to get around.

    I am actually using a Leadpage where a button click is linked to an external website. I cannot add code to the button but I can add Javascript code in the body of the page create an event handler as you described.
    Any suggestion how to do it? sample code?

    Thank you

    March 13, 2016 at 5:28 pm
  • Hello,

    I’m struggling to get my head around the ‘fake page’ idea.

    We are creating a link to a page that does not exist? Surely clicking that link will then end in 404.

    I am missing something here, but cannot work out what it is.

    Can anyone please help me? Thank you.

    July 12, 2016 at 3:41 am
  • Thanks for this. It was easy to implement, once it’s live I’ll check to see if its working!

    July 28, 2016 at 7:20 am
  • Betty

    This plugins are very good but i prefer to use Google Analytics Counter Tracker plugin on WordPress. It is Very simple and easy to use.You can
    Connect your Google Analytics account and get Google Analytics stats;
    Group stats by hour, day, month and year.

    September 2, 2016 at 3:47 am

Leave a Comment: