A lot of you have asked me how I track things like affiliate link clicks, email signups and such things with Google Analytics.

The short answer is with Google Analytics Event Tracking!

What You Will Learn

  • How to track anything with Google Analytics
  • Including affiliate clicks, email sign ups, shopping funnels & more
  • How to setup event tracking & goal tracking
  • How to work out the monetary value of a conversion easily
  • Get access to my personal custom Google Analytics report

My previous tutorial will teach you how to increase traffic with Google Analytics.

Google Analytics Event Tracking Tutorial

Don’t worry it is much easier than you think! Just follow along with my live example-

Click Here to Read the Transcript

ALERT: Instantly Increase Your Conversion Rate With My Personal Case Studys!

Essentially you can track anything that happens on a website from someone click on a link to someone converting as an email subscription.

Here is a basic example of how to use Google Analytics event tracking to track affiliate links-

The default Analytics event tracking code looks like this-

onclick="_gaq.push(['_trackEvent', 'category', 'action', 'label']);"

We want to replace 3 values-

  • Category – The category/type of event, e.g. Affiliate Click
  • Action – Give the action a name, eg click (I use affiliate programme name here)
  • Label – Anything else you want to include (I use the page URL)

So track an affiliate link click for Ahrefs on the tools of the trade page it would look like this-

onclick="_gaq.push(['_trackEvent', 'Affiliate', 'Ahrefs', '/tools-of-the-trade/']);"

Now we just need to add it to our usual affiliate link that looks like this-

<a href="">Ahrefs</a>

Which ends up looking like this-

<a href="">Ahrefs</a>

Everytime someone clicks on that affiliate link, Google Analytics will log it was an affliate link click for Ahrefs and the page it came from.

Please see the video for more detailed setup instructions and learn how to track other things like email subscriptions, signups & shopping carts!

Custom Reporting With Events & Goals

Once setup you can create custom reports that tell you a bunch of things like-

  • Which traffic source sent the most opt in conversions
  • Which page converts the most affiliate clicks
  • Which affiliate program is performing the best for which traffic source

This is what my custom Google Analytics report looks like (you can get it below)-

Straight away you can see 10.9% of traffic from the WarriorForum signs up to my email list while only 3.4% do from TrafficPlanet.

Equally you can see 46.1% of YouTube traffic clicks an affiliate link compared to just 25.8% from BlackHatWorld.

Take a look at this post or this post to learn more about why that is important to know!

Learn How To Steal  Your Competitors Rankings With My #1 Personal SEO Strategy!
Get instant access to my personal SEO strategy that I use on every single site that I launch time & time again.

109 Responses

  1. 7.5.2013

    dont think the google + share button is working, i shared it and got nothing, the page just reloaded.
    cool tutorial though, im looking forward to trying it out, i want to scale my traffic by buying advertsing slots but I am unsure on how to go about it. this may help a lot.

  2. MixerDJ

    Better if you can show How to set up Google Analytics account for web site with video :P

  3. 7.5.2013

    Matt, good post, one thing you should do is track your email links… I noticed you are not doing it… just a suggestion.

    How are you creating the tracking events? Manually or with Yoast SEO plugin?


    • July 6th, 2013 at 8:01 am


      Yeah my email tracking sucks, I have an old aweber account that doesnt even tell me open rates ^^

      I’m setting it all up manually, Yoast tracks outbound links – but mine redirect through an internal link first

  4. 7.5.2013

    Just seen the full video – Like to point out that in the Email Signups Dashboard, your #5 referer was my other site – SerpChirp xD

  5. Frank

    Hi Matt,
    Isn’t this easier with Google’s URL Builder tool? Or is not the same thing?

    • July 6th, 2013 at 7:59 am


      That is for custom campaign tracking like when you send out an email or buy banner advertising etc

  6. 7.6.2013

    Hello Matt

    That is AWESOME. I was waiting for this

    Thank you so much


    • July 6th, 2013 at 7:58 am

      Cheers Batu

      • July 6th, 2013 at 12:44 pm

        I want to share something for WordPress (aka Php) sites.

        You can use this code for Label .

        onclick=”_gaq.push([‘_trackEvent’, ‘Affiliate’, ‘Amazon’, ”]);”

        • July 6th, 2013 at 12:45 pm

          onclick=”_gaq.push([‘_trackEvent’, ‘Affiliate’, ‘Amazon’, ”]);”

  7. 7.6.2013

    Another top post by Matt. It’s always worth being able to track as much as you can on Analytics.

    • July 12th, 2013 at 9:56 am

      Then you can make awesome posts like the one I’m going to write this afternoon :P

  8. 7.6.2013

    I’m sorry Matt. I cant write php code here. It’s SERVER[REQUEST_URI]

    • July 12th, 2013 at 9:55 am

      I know what you are getting at, but within posts you can execute PHP by default ^^ I use this trick in my siderbar for the RSS link thoguh

  9. Very nice guideline on to have full access one Google analytics report

  10. 7.8.2013

    Hi Matthew,

    I left this question on Google+ but I’ll also ask it here.

    First off, thanks for the tutorial. I’d like to set up event tracking for when a podcast is played. I have 5 audio podcasts files on one page and I’d like to know which one is being played the most and where the traffic is coming from who actually listen to the podcast. How will I use the event tracking code with the HTML5 iFrame embed? 

  11. toobie

    Hey matt, great post!
    How do you lock your contet with social signals like that?
    Could you please give me a search query or something to start with? :)


  12. 7.12.2013

    I love this tutorial.

    It something so simple and yet people often forget to do it.

    I mean there was even a part that you forgot to do.

    Goal tracking. It’s so important.

  13. 7.12.2013

    Are you okay with Google analytics? A lot of people stay away from it now. I found Piwik and it’s fantastic.

    • July 15th, 2013 at 7:54 am


      Yeah have used it for years, why wouldn’t you use it?

  14. Hi Matt

    I have tried to something like this in the past but failed miserably!

    All my affiliate links end “/exit.php’ so I set up a goal in G.A. to record all clicks on URLs containing ‘exit.php’… It’s never recorded a thing.

    Any tips as to how to fix this?


    • July 16th, 2013 at 8:42 am


      Did you put the analytics tracking code within the exit.php file itself?

      If not it can’t register that page was viewed, you need to setup event tracking as per the tutorial here

      • Anonymous Affiliate
        July 16th, 2013 at 8:47 am

        Ah ok, I didn’t know that.

        That might be one I’ll have to get my developer to try and look at that, unfortunately I am not so technical as to be amending that type of file!

        Thank you

  15. 7.16.2013

    Thank you for this tutorial. I don’t really track much in general, just use statcounter to see what queries or where the traffic come from.
    But now you convince me to us GA and it’s free. Can’t beat that.

    Question: What is the plugin you use to display the “Subscribe to my award winning blog now” ? I like how it goes down when you scroll.
    ( I subscribed btw : )

  16. 7.22.2013

    Hey Matt, what did you eat in the morning?? Gallo pinto?? Share your secret please, how can you be so smart?? I have to stop reading your blog, because it make me fill i miss something every day. Thx for your share buddy!!

    • August 13th, 2013 at 4:18 pm

      Hahah hopefully in a couple more weeks I will be =D

  17. Carolyn

    Hi matt,

    How can I set this up to show if my clients SEO is working. They are confused with PPC and SEO and he is spending 4200 a month on PPC also. It has its own landing page and phone number. But, her Analytics report is the standard mess that Google gives you.

  18. 10.6.2013

    The best video I’ve watch when it comes to this specific topic Goals, Events and funnels.

    I wish I could find a video about how to insert the onclick=”_gaq.push([‘_trackEvent’, ‘Affiliate’, ‘Ahrefs’, ‘/tools-of-the-trade/’]);” code in the actual page.

    Do you know one?

    And thanks again.

    • October 6th, 2013 at 9:35 am

      The video explains that?

      • October 6th, 2013 at 6:05 pm

        But i think it a little bit different depending on the theme you are using for your site. Right?

        • October 7th, 2013 at 9:08 am

          Nothing to do with theme, just use the post editor that we all have in the back end of worpdress.

  19. Promes

    Hi Matt,
    Thanks for an awesome article. I tried to implement the tracking code, but the links I want to track come from shortcoded buttons (example: [large_button color: red link:x**] ). Do you know how I could manage that without having to lose the shortcodes of my wp theme? Btw, I tried to put the code in the shortcode, but obviously it doesn’t works.

    • November 11th, 2013 at 10:23 am

      You would need to edit the plugin that you are using for the shortcode

  20. 11.9.2013

    Just set up your custom report with my analytics. This is something I’ve been wanted to learn but never got around to actually taking the time to learn how to do it.

    Thanks for sharing, Matt!


  21. 12.18.2013

    If you want to add call tracking for free (so you can see call events), you can add a tel: anchor tag round your number and add the event trigger to that – this will only work on smart phones or Skype, but on some the sites I’m involved with that can be as many as 30% of the visitors, so with a little judicious analysis you can pick out the key phrases that have generated telephone calls (along with everything else)

  22. 1.16.2014

    Tnx nice video, works perfect for me the affiliate clicks. I have one question, at the 3.56 in the video what is the Event Category number 5. Page Exit do? Is the moment when the visitor hit the x button in the browser?

    • January 17th, 2014 at 11:08 am

      This is how many people left the site at that page.

  23. Panks

    Hey thanks a lot , Lots of info provided you, Its a great help . But you didn’t mention about the downloads .

    Is it right that i will track a download by puting the event code on my Download Button and then set up a goal for thank you page.

    I mean when anybody download my software if fire a event and for the successful installation we have thank you page. So should i have to do that.

    I m still very confused ..

  24. Panks

    Hay Matthew ,

    I am doing each and every step as you mentioned , can you please take a look on my Download button and verify it if i have put right code .

    Site is

    One more thing what i have to do to track event for different page , i mean if i have multiple page and i want to tack my download button then on every page i have to put the same code or i need to change something in tracking code. Should i have to create different Events and setup different Goal for every page.

    Please guide


    • February 4th, 2014 at 9:58 am

      Looks ok to me, just check the data comes into analytics tomorrow.

      I’m not a coder by any stretch!

      You should read the official documentation regarding the best way to implement it.

  25. 2.8.2014

    Hi matt. I left a comment on the youtube video, but I’m reposting here in case you miss it. I’d really like to know the answer to this!

    How would this work with an iframe Amazon affiliate link that looks like the one below? There’s no html outbound link as such to which the analytics code can be attached.


    • February 8th, 2014 at 9:41 am

      YouTube really made a mess with the comment management/moderation with the Google+ integration so its likely I missed it sorry.

      Why would you use an iframe?

      • February 8th, 2014 at 9:50 am

        That’s the format that Amazon uses for its enhanaced links. The specific ones I want to track are like those on this page

        Thanks for the quick response :)

        • February 10th, 2014 at 11:34 am

          Ahhh I see – I don’t think so, perhaps you could add the onclick event to the java easy enoguh but im not a coder. I bet someone on fiverr could drop it in though.

          • February 14th, 2014 at 9:17 am

            Thanks, It’s the one piece of info I could really do with, so I’ll try and find a way. I’ll leave a comment if I manage to find anything worthwhile.

          • February 15th, 2014 at 8:00 pm

            Just outsource it – anyone that knows code thats like a 30 second job

  26. 2.13.2014

    You can do same things with more simple event tracking library, by the way :)

  27. 2.22.2014

    Interesting stuff matthew however I got confused why you have mentioned you put affiliate links as event AND goals. ?

    • February 24th, 2014 at 9:32 am

      An event is basically just a fabricated pageview.

      If you want to measure conversion rates/conversion value etc then you need to map an event as a goal

  28. Rajesh

    I didn’t found custom report

  29. 3.5.2014

    Hi Matt,

    Are you going to do an updated version with the new universal analytics? The track event won’t work if any user updates from ga.js to analytics.js. I’ve had these problems a few times over the last month or so.

    • March 6th, 2014 at 8:01 am


      Yes I will do at some point

    • March 18th, 2014 at 10:56 pm

      Glad you mentioned that as I was wondering the same thing.

      I’m new to GA, so I don’t want to assume, but the way I’m interpreting it this is the “old” (ga.js) code:
      ga(‘send’, ‘event’, ‘category’, ‘action’);

      …and this would be the “new” Universal Analytics (analytics.js) code:
      onclick=”_gaq.push([‘_trackEvent’, ‘category’, ‘action’, ‘label’]);”

      Please correct me if I’m wrong. :) Thanks in advance!

      • March 19th, 2014 at 3:16 pm

        Sorry, swap the two lines of code so top is new and bottom is old (changed the wording/structure of the post midway through).

  30. 3.6.2014

    Hi, Matthew.

    How can one get in contact with you? what’s the best way

    I have some questions regarding ‘How To Track Anything With Google Analytics’.

    I;m new to GA and so my questions would be elementary and possibly boring for you so you obviously don’t have to answer them if you don’t want to although it would really help me with conquering the learning curve

  31. 3.13.2014

    Hi Mathew sorry just wondering how come you mention affiliates wouldn’t have thought it would be as relevant…

  32. 3.26.2014

    Hi Matthew,

    Very good your video about tracking anything with Google Analytics… What’s about google “no provided” issue.


    • March 28th, 2014 at 9:03 am

      Nothing we can do about that – keywords are so 2012 anyway :P

  33. 4.29.2014

    Hello Matthew,

    I find your video is really helpful to me. But still got one more question. I want to track the click events of my “Submit Form Button” which I used a third-party service like MachForm.

    How am I going to track that or simply how am I going to paste the tracking code inside the webpage?

    Please help me and thank you very much for the help.

    – Felix

    • April 30th, 2014 at 6:22 pm

      You will have to ask MachForm devs about that if you cant control the code

      • April 30th, 2014 at 7:01 pm

        After the creation of the form, their form editor will then generate the codes for me to paste it in my webpage. I am thinking what part of script I will paste the tracking code.

  34. 6.28.2014

    What is the plugin you are using for the popup that comes to subscribe to your blog? I really like it..

  35. 7.23.2014

    Hey Matthew,

    I had this tutorial bookmarked. Went back to into implemented the tactics. Then realized after 2 weeks of not checking. This is the old way and this doesnt work with Universal Analytics. Would you mind doing an update with the new version?

    • July 25th, 2014 at 4:17 pm

      Ahhh I haven’t moved to universal myself yet sorry, but I will update it when I do :)

  36. 8.14.2014

    Hi Matt,

    Whats the best way to add events to a wordpress website. Everytime i change it in my posts it gets reset by the WYSIWYG editor. The only solution I came up with is use a plugin like Google Analytic Events or using RawHTML to prevent it from changing. Thoughts?

  37. 8.19.2014

    Hi Matt,

    Is it possible to track Contact Form Submission as the last step in a funnel WITHOUT a thank you page? That is, I have 2 Google AdWords Campaigns, each with their own landing page. I set up the goal to track from AdWords to the landing page to the Contact page but I cannot tell if the contact form page was submitted as there is no subsequent thank you page – only text that pops up on the contact page. If I set up an event I can’t add it to the end of the previously described funnel, cany I?

    • August 20th, 2014 at 3:07 pm

      Hmmm I think if you got the submit button to fire off an event, you can set that up as a goal

  38. 9.29.2014

    Hi Matt, awesome guide, is it possible to use the affiliate tracking code for image clicks (banners) (in wordpress that go to custom urls) that redirect to the affiliate page?
    Thanks for your help dude.

    • September 29th, 2014 at 4:17 pm

      You sure can – you can add the code to pretty much anything!

  39. 11.21.2014

    Hi Matt,

    Awesome tutorial. This cleared up a few things from the Analytics front.

    We have our own landing page which we drive ppc traffic, and the thing that I’m pretty stuck on at the moment is how to track conversions (postback/pixel fire on affiliate link LP) and attributing them back to the keywords that generated the conversions in the first place from adwords.

    Lets say we are using our own affiliate tracking platform such as HasOffers, how can I dynamically populate the keywords into the affiliate links and postbacks/pixels?

    Do you have any suggestions on this?

  40. 1.2.2015

    WOW! Thanks for showing us how to use Google Analytics like a pro!

    This is exactly what I need to do on my blog, your email happened to pop up at the right time, too.

  41. 1.5.2015

    Great video Matt,

    Do you know if it’s possible to add an event to an embedded youtube video, to track how many people press play?

    I’m going to look into this now, but figured I’d ask here too.

  42. 2.3.2015

    When I add event tracking code in WP text editor and switch back to visual editor, WP automatically strips out that code. Do you know why that’s happening? My wp is up to date.

    • February 3rd, 2015 at 11:11 am

      I never use the visual editor

      • Abhay
        February 3rd, 2015 at 11:16 am

        That’s strange! But then what do you do if you need to add a shortcode or something using the navigation that we see in visual editor?

  43. 2.5.2015

    Hi Matt,
    Tracking affiliate links still works right?
    I’m having trouble getting it to work, but not just if something is conflicting with something, or perhaps because the links are PrettyLin links.

    • February 6th, 2015 at 8:14 am

      Yeah it does no problem

      • February 7th, 2015 at 11:34 am

        Finally, figure it out.
        I was using “Google Analytics by Yoast”, for some reason the code you have above and code i found on other sites didn’t work.

        I had to use the following code:
        onclick="__gaTracker('send', 'event', 'affiliate link', 'product name', '/url-slug/');" rel="nofollow" target="_blank"

        Not sure if code will display in comment so here is screen shot.

        Thanks again.

        • February 8th, 2015 at 11:45 am

          Are you using legacy or universal analytics?

          • February 9th, 2015 at 10:27 am

            Using universal, but for some reason only the code I posted works with Yoast.
            Even the code generated with wouldn’t work.

          • February 11th, 2015 at 9:56 am

            There is a very handy Google Analytics debugger addon from Chrome that might help you out

        • March 19th, 2015 at 5:46 am

          I’ve had a similar issue as well. I’m using Yoast for SEO and Analytics, but not all of my affiliate links are being tracked with the filter you can configure to track internal links as external links.

          I came here to find a workaround, so thanks for the comment. I’ll give it a try.

  44. 2.10.2015

    Thanks for the great tutorial Matt.

    Do you know of any WP plugins that can automate adding the tracking code values to links? I’m thinking of something similar to ThirstyAffiliates, which I’m already using for affiliate links.


What are your thoughts?

* Name, Email, Comment are Required