Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tracking link clicks with google analytics?

I'm a complete beginner with Google Analytics, and I need to know how to set it up so that it can track the number of clicks a link on my website gets?

For example I have a link:

<a href="https://google.com">link</a> 

I know I'm supposed to put an onClick event on there somewhere but I don't have any idea how it links to Google Analytics?

Is this the correct Onclick code:

onClick="_gaq.push(['_trackEvent', 'Link', 'Click', 'Banner Advert1']);" 
like image 667
user3191726 Avatar asked Jan 15 '14 20:01

user3191726


People also ask

How do you measure link clicks?

Option #3: Google Analytics Start by clicking on your Behavior tab, then select the events and overview options. Under the Event Category section, you can see how often links are being clicked in relation to other events that you've set your Analytics to track.

What is clicks in Google Analytics?

The Clicks column in your Google Ads reports indicates how many times your advertisements were clicked by users, while Users indicates the number of unique (deduplicated) users who clicked your ads. There are several reasons why these two numbers may not match: A user may click your ad multiple times.


2 Answers

You probably want to use event tracking - this is a simple Javascript function to can fire from the click event on your links. You will need to make sure you have the standard google tracking script on your page too.

From Google Event Tracking Guide

Event Tracking is a method available in the ga.js tracking code that you can use to record user interaction with website elements, such as a Flash-driven menu system. This is accomplished by attaching the method call to the particular UI element you want to track. When used this way, all user activity on such elements is calculated and displayed as Events in the Analytics reporting interface. Additionally, pageview calculations are unaffected by user activity tracked using the Event Tracking method. Finally, Event Tracking employs an object-oriented model that you can use to collect and classify different types of interaction with your web page objects.

Example:

<a href="www.google.com" onclick="_gaq.push(['_trackEvent', 'Google Link', 'Action label', 'Additional info']);">link</a> 

UPDATE

The above is for the older version of the API - ga.js. If you are using the newer Universal tracking please refer to the docs. Effectively the data passed is the same as before, however the call is different.

Example for event tracking using the newer API:

<a href="www.google.com" onclick="ga('send', 'event', 'Google Link', 'Action label', 'Action Value');">link</a> 
like image 168
geedubb Avatar answered Sep 17 '22 22:09

geedubb


Please note that _gaq.push(..) refers to tracking with the legacy Classic Analytics Web Tracking (ga.js). The new standard Universal Analytics Web Tracking (analytics.js) uses a different methodology like:

ga('send', 'event', 'button', 'click', 'nav buttons', 4);

The first two options cannot be changed, they pass the send option with the hit type event to the ga function .

The next two options are required as well, the last two are optional. They represent:

  • button (string | required) : Category
  • click (string | required) : Action
  • nav buttons (string | not required) : Label
  • 4 (Positive Integer | not required) : Value

More information may be found at : https://developers.google.com/analytics/devguides/collection/analyticsjs/events

like image 28
AnuragBabaresco Avatar answered Sep 18 '22 22:09

AnuragBabaresco