Welcome to Part 1 of How to Track User Clicks using Google Analytics. Before we learn how to track clicks we need to review some of the technology behind Google Analytics. In particular, we need to understand how GA creates pageviews. Why? Because we will use the same technology to track clicks. This post may seem off topic, but it lays the foundation for the next post in the series.
It all starts with the Google Analytics tracking code:
urchinTracker. For those of you that don’t know what a function is, it’s a piece of code that actually ‘does stuff’.
- It can appear almost anywhere in your web page. There are certain limitations, but in general you can move it around.
- It can appear more than once.
Applying these characteristics to
urchinTracker means we can place
urchinTracker almost anywhere in a web page AND we can include it multiple times, two important concepts.
urchinTracker: What it Does
We know that
urchinTracker is a function and it ‘does stuff’, but what exactly does it do? While visitors engage with your website,
urchinTracker is collecting information in the background. It identifies things like:
- Where the visitor came from
- How many times they’ve been to your site
- What content they are viewing
- Characteristics of their browsing environment (operating system, browser, etc.)
- The title of the current website page
Please note that
urchinTracker is not collecting any personally identifiable information. It is collecting generic information about the visitor.
After it collects the data, it sends it to Google Analytics in the form of a pageview. So every time
urchinTracker runs, or as programmers say ‘executes’, it creates a pageview in Google Analytics. And, because
urchinTracker is a function, we can add it to a web page multiple times. This means we can create multiple pageviews in Google Analytics every time a single page loads in the visitor’s browser.
‘Naming’ Pageviews with urchinTracker
Another important concept to understand is how
urchinTracker ‘names’ pageviews. When I say ‘names’ a pageview, I mean the way that the pageview is represented in the GA reports. Let’s look at some pageviews in the Top Content report:
Everything in the ‘Content’ column was created by
urchinTracker. Here’s how:
urchinTrackerextracts the information from the location bar of your browser.
- It modifies the value to show only the name of the directories, file and query string variables.
Here’s an example. This URL:
would appear in the top content report as this:
That’s the default behavior of
urchinTracker. Recapping what we’ve learned; whenever a page loads in your browser,
urchinTracker collects all the necessary information, creates a pageview name from the location bar and sends the data off to Google Analytics in the form of a pageview.
Important Stuff Below, Pay Attention :)
What’s really cool is that we can over-ride the default behavior and tell
urchinTracker how to name a pageview. For example, let’s say we want to change the way the pageview for ‘/index.php’ is named in GA. We would modify
urchinTracker as follows:
This modification forces
urchinTracker to name the pageview ‘ski-bum’ rather than ‘/index.php’. This means that when you view the Top Content report you’ll see ‘ski-bum’ and not ‘/index.php’. Whatever you place in the parenthesis of
urchinTracker becomes the name of the pageview in Google Analytics.
There are a few important concepts to take away from this post:
urchinTrackercan appear almost anywhere in a web page
urchinTrackercan appear multiple times in a web page
- By slightly modifying
urchinTrackerwe can change the ‘name’ of pageviews in Google Analytics
In Part two of this series we’ll put our knowledge of
urchinTracker to work and talk about tracking visitor clicks.