How To Track Anything With Google Analytics

How To Track Anything With Google Analytics

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

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="/get/ahrefs/">Ahrefs</a>

Which ends up looking like this-

<a href="/get/ahrefs/" onclick="_gaq.push(['_trackEvent', 'Affiliate', 'Ahrefs', '/tools-of-the-trade/']);">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!

Get My Latest Posts

Subscribe to the blog to get the latest updates delivered direct to your inbox.


Connect With Me...

Circle me on Google+ so we can chat and I can put a face to a name!

76 Responses

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.

Reply

Matthew Woodward Reply:

Hi,

Fixed :)

Reply

MixerDJ
7.5.2013

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

Reply

Matthew Woodward Reply:

Hi,

Just install http://yoast.com/wordpress/seo/

Reply

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?

Thanks!

Reply

Matthew Woodward Reply:

Hi,

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

Reply

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

Reply

Matthew Woodward Reply:

Winning =D Thanks for the traffickz!

Reply

7.5.2013

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

Reply

Matthew Woodward Reply:

Hi,

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

Reply

7.6.2013

Hello Matt

That is AWESOME. I was waiting for this

Thank you so much

Batu

Reply

Matthew Woodward Reply:

Cheers Batu

Reply

Batuhan SASI Reply:

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

You can use this code for Label .

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

Reply

Batuhan SASI Reply:

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

Reply

7.6.2013

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

Reply

Matthew Woodward Reply:

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

Reply

7.6.2013

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

Reply

Matthew Woodward Reply:

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

Reply

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

Reply

Matthew Woodward Reply:

Cheers Ade!

Reply

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? 

Reply

Matthew Woodward Reply:

Hi,

You need to setup the onclick event on the button control itself. Eg you need to register the onclick when someone clicks the play button. I have no idea how you do that my coding skills suck.

Have a look at http://www.elisa-dbi.co.uk/blog/how-to-integrate-google-analytics-in-video-html5-and-goodbye-to-flash/ though?

Reply

toobie
7.12.2013

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? :)

Thanks

Reply

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.

Reply

Matthew Woodward Reply:

Which part did I forget to do?

Reply

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.

Reply

Matthew Woodward Reply:

Hi,

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

Reply

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?

Cheers

Reply

Matthew Woodward Reply:

Hi,

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

Reply

Anonymous Affiliate Reply:

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

Reply

Matthew Woodward Reply:

Let me know if you get stuck!

Reply

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 : )
Thanks!

Reply

Matthew Woodward Reply:

Hi,

That is http://wordpress.org/plugins/q2w3-fixed-widget/

Thanks

Reply

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!!

Reply

Matthew Woodward Reply:

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

Reply

Carolyn
9.4.2013

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.

Reply

Matthew Woodward Reply:

What are the goals of the campaign?

Reply

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.

Reply

Matthew Woodward Reply:

The video explains that?

Reply

luigi Reply:

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

Reply

Matthew Woodward Reply:

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

Reply

Promes
10.29.2013

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:xxx] ). 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.
Thanks!

Reply

Matthew Woodward Reply:

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

Reply

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!

Casey

Reply

Matthew Woodward Reply:

No worrys glad it helped you out :)

Reply

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)

Reply

Matthew Woodward Reply:

Now that is a sweet tip :)

Reply

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?

Reply

Matthew Woodward Reply:

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

Reply

Panks
1.31.2014

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 ..

Reply

Matthew Woodward Reply:

Hi,

Just tag them the same as an affiliate link.

Reply

Panks
2.3.2014

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 http://goo.gl/cmvZrw

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

Regards

Reply

Matthew Woodward Reply:

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.

Reply

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.



Reply

Matthew Woodward Reply:

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?

Reply

Ken McMahon Reply:

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

http://gopaintshoppro.co.uk/paintshop-pro-x6-for-photographers.html

Thanks for the quick response :)

Reply

Matthew Woodward Reply:

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.

Reply

Ken McMahon Reply:

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.

Reply

Matthew Woodward Reply:

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

Reply

2.13.2014

You can do same things with more simple event tracking library, by the way :) https://developers.google.com/analytics/devguides/collection/analyticsjs/events#implementation

Reply

Matthew Woodward Reply:

Thats what we are doing :)

Reply

2.22.2014

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

Reply

Matthew Woodward Reply:

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

Reply

Rajesh
3.5.2014

I didn’t found custom report

Reply

Matthew Woodward Reply:

Try reading the post properly

Reply

3.5.2014

Hi Matt,

Are you going to do an updated version with the new universal analytics? https://developers.google.com/analytics/devguides/collection/analyticsjs/events 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.

Reply

Matthew Woodward Reply:

Hi,

Yes I will do at some point

Reply

Matt Reply:

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!

Reply

Matt Reply:

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

Reply

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

Reply

Matthew Woodward Reply:

Hi,

Start here – http://www.matthewwoodward.co.uk/forums/ or ask in the comments

Reply

3.13.2014

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

Reply

Matthew Woodward Reply:

I’m a full time affiliate ^^

Reply

3.26.2014

Hi Matthew,

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

thanks

Reply

Matthew Woodward Reply:

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

Reply

What are your thoughts?

* Name, Email, Comment are Required

Welcome To My Blog!

Let me introduce myself, my name is...

No not Matt Cutts, but I am better at SEO than him :P I make a great living online with SEO and I will teach you how you can as well...

You Can Find Me On...

Get My Latest Posts

Sign up for my newsletter to get the latest blog updates direct to your inbox.



WARNING! I do not send ANY 'Guru' spam or affiliate promotions.

Sponsors

My Friends


Advertise Here.