Quote Box ArchiveGo to Past Quote Boxes

Nov 30, 2008

Page Tracking a Blog Using Google Analytics

I use the free Google Analytics service to track views of my blog. My pages send tracking information to the GA computers. GA reports how many visitors have read the blog, for how long, and a lot more, but it does not report individual information about who is visiting.

The "GA Tracking Code" is a short JavaScript program provided by GA that is part of each page, indicated by a title at the bottom of the page. You include the tracking code by using the Layout page of the Google blog setup.

This article discusses:

  • How GA determines page view time
  • Installing the GA Tracking Code
  • Setting a filter and cookie to exclude your own page views
  • Time on Page with "/endpage" checkpoints
  • Top Content Report - Time on Page
  • Tracking outbound links
  • Sources

How GA Determines Page View Time

GA is optimized for tracking commercial sites. Each page request generates one log entry (a checkpoint). A commercial site wants to track the progression of a customer from main page, through product pages, shopping cart, and payment. Here is a simplified example of what log entries are like:

                    Check   Time
                    Point   Spent  What Happened
                    -----   -----  ---------------
Page /BuyThings     40:00   0:10   User views site
Page /productA      40:10   1:50   At product A
Page /productB      42:00   2:30   At product B
Page /ShoppingCart  44:30   1:20   At Shopping Cart
Page /CreditCard    45:50   1:00   Provides payment
Page /Confirmation  46:50   0:00   Payment accepted
Page ??                ??          User Disappears

Time Spent is calculated from the differences in the Check Point times. For example, the user looked at the /ProductA page at 40:10, and at the /ProductB page at 42:00, so the /ProductA page displayed for 1:50.

Notice that the time entered for the /Confirmation page is 0:00. We suspect that the user spent at least a few seconds on that page, but we don't know how long, because that was the last page the user looked at. There is no following checkpoint to compute time spent, so GA records 0:00.

This doesn't work out well for tracking blogs. Here is an example:

                    Check  Time
                    Point  Spent   What Happened
                    -----  -----   ---------------
Page /MyBlog        40:00   1:40   User views site
Page /MyBlog/Page1  41:40   0:00   Goes to Page1
Page ??                ??          User Disappears

The user looked at the first page /MyBlog, read some posts, went to /Page1 to read, then went to another site. There is no page view following /Page1, so the time spent is unknown and is entered as 0:00. Your reports will show page views, but you won't know the time spent reading the last page visited.

My solution generates a checkpoint for the artificial page "/endpage" when the page is unloaded. This results in reports that capture almost all of the time spent on each page. The above logfile for MyBlog then looks like this:

                    Check  Time
                    Point  Spent   What Happened
                    -----  -----   ---------------
Page /MyBlog        40:00   1:40   User views site
Page /endpage       41:40   0:00   Leaves /MyBlog
Page /MyBlog/Page1  41:40   1:10   Goes to Page1
Page /endpage       42:50   0:00   Leaves Page1
Page ??                ??          User Disappears

No time is usually assigned to /endpage, because it is immediately followed by another blog page or a disappearance. It is there to determine the display time of the last page read.

Sometimes /endpage accumulates Time Spent. I think this happens when a visitor leaves the site and comes back within 29 minutes. The tracking log has /endpage followed by a blog page, so the time is assigned to /endpage.

Sometimes, pages viewed show zero Time Spent. Possibly the visitor left that page within a few seconds, and GA ignored the page view.

Installing the GA Tracking Code

My blog is on Blogger, so I don't know how this advice adapts to other services.

Go to the Google Analytics sign-in page, create a Google account if needed, and sign in.

GA Overview Page: Click "Add Website Profile" at the lower left.

GA Create New Website Profile Page: Enter your blog URL in the box labeled "Please provide the URL of the site you would like to track". Click Finish. For example, my blog url is
"http://easyopinions.blogspot.com/" .

GA Tracking Code Page: The pale yellow box shows "Tracking Status: Tracking Not Installed". This is expected.

Copy the JavaScript text from the white box farther down the page, and place it into a convenient text file for the moment. Save this as part of your own documentation about your website. (Ignore the link to "Legacy Tracking Code urchin.js" ) Don't add or delete spaces or break up lines. Click Finish.

The tracking code is the same for all sites and all web pages, except for the identifier in blue ("UA-5212345-6") which corresponds to the website URL you just registered. You will get your own identifier in the code generated for you.

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));

<script type="text/javascript">
var pageTracker =

GA Overview Page: You will now see a line for the site URL you have registered. The Status will show a yellow triangle /!\ showing that data from your site has not been received yet. GA will fully recognize your blog after you install the tracking code into your blog pages and it sends some page tracking information.

Go To Your Blog Setup: Navigate to your Blogger setup page: Layout: Page Elements. You will see the block diagram of the parts to your blog page. Click on the short, wide rectangle at the bottom, on the blue link "Add a Gadget".

Pop Up Window: Add a Gadget - Basics: Scroll to about the middle and click on "HTML/JavaScript: Add third-party functionality or other code to your blog".

Pop Up Window: Configure HTML/JavaScript: I suggest the title "Google Analytics" (without the quotation marks), but this is your choice. Paste the saved JavaScript code into the big box. Click the orange Save button.

Layout: Page Elements: Click the orange Save button. A yellow rectangle confirms that "Your Changes Have Been Saved". Click "View Blog". The installation is done.

The GA Overview Page that you visited above will show the yellow triangle for up to 24 hours until GA gets some data from you or others visiting your site. A green check mark indicates data has been received and correct operation. Browse around the GA pages and read the explanations. Click on the View Report link to see the many possible reports of your blog traffic.

Eliminate Self Tracking

The GA tracking code records your own page views along with other views. You may not want your reports to include your own activity.

You can set up a Filter at GA (a rule to include or exclude data) to ignore information from one or more IP addresses. Unfortunately, most people have a changing IP address assigned to them by their Internet Service Provider. It may be constant for a while, but it changes unpredictably.

Instead, I use a Filter Value to exclude activity coming from my account on my computer. A cookie is a text file that holds information stored and used by a website. First you create a custom filter at GA, then you write a Filter Value into the cookie for your blog.

** Create the Filter at GA

Go to GA Settings: click on "Filter Managers" in the lower right corner.

GA Filter Manager Page: See the gray heading "Existing Filters. Click on "Add Filter" at the right of the heading bar.

GA Filter Manager> Create New Filter Page:

Filter Name: Enter "Exclude Cookie", or use another name. Don't include the quotation marks.

Filter Type: Choose "Custom Filter" from the drop-down list. More choices will appear.

List of circle choices: Choose "Exclude"

Filter Field: Choose "User Defined" (showing at the top) about the 10th item in the entire list.

Filter Pattern: [Your Blog Name]. For example, if your blog is WonderfulStuff.blogspot.com then you would enter "WonderfulStuff", or "wonderstuff", or something based on your blog name. If I suggested that you use a particular name "cat", then any other blogger who also used "cat" would not show up in your blog statistics. Just for discussion below, we will assume you used "wonderstuff", but don't use that particular value.

Case Sensitive: No

Apply Filter to Website Profiles: Select your blog in the box on the left, and click "Add" in the middle, to move the name into the box on the right. If you are tracking more than one blog, this filter applies to all blogs that you move to the box on the right.

Save Changes: Click to create the filter.

** Write The Filter Pattern to the Blog Cookie

Cookies are text files with a complicated format and security restrictions, so your Web browser has to write to them. You will write your Filter Pattern (eg "wonderstuff") to the cookie with a blog post, by clicking a link containing a GA JavaScript function call. You do this once to update the cookie, or again if you delete the cookie by mistake. There is no harm in writing the cookie more than once. The link shows an alert "Cookie is set" to confirm that it operated.

Create a blog post that holds the following content. You may include other content or explanation. Give the post a date in the past that hides the post. You may delete the post or make it a draft after use, so that visitors don't use it by mistake. Replace the text "wonderstuff" with whatever value you chose above as your Filter Pattern, and keep single quotes around it as shown.

<p><a href="#x"
onClick="javascript: pageTracker._setVar('wonderstuff');
alert('Filter Pattern is set');">
Write Filter Pattern</a>

Copy and paste this code into your post, publish it to your blog, visit it, and click on the link to write the Filter Value into the cookie. The presence of that value will activate the Exclude Filter you set in GA, keeping your own activities out of your GA reports. You should see this effect within a day.

The link will look like the following on your blog page, and you can click this one to see how it operates. This one shows a message, but doesn't write a cookie.
Write Filter Pattern

You could do this for possibly many users on many computers that you want to exclude from your activity reports. Each user displays the special blog page and clicks on the link to put the Filter Pattern into the cookie for your blog.

You can look at the cookie for further confirmation. For user Dad, using Windows XP, the cookie created for blog WonderfulStuff is located at:

Directory: C:\Documents and Settings\Dad\Cookies
File: dad@WonderfulStuff.blogspot[1].txt
If you click on the cookie, it will display as run-together text with many "small-box" symbols. You will find your Filter Pattern "wonderstuff" in the text somewhere, if all is well. Again, use your own value in place of 'wonderstuff'.

Time on Page with "/endpage" Checkpoints

Navigate to your Blogger setup page: Layout: Page Elements. Click on Edit within the box titled Google Analytics (or the title you gave it), to expose the code. Use cut and paste to add the three green lines in the code group below, with a blank line for readability:

<script type="text/javascript">
var pageTracker = 

function f_unload()
window.onunload = f_unload;

Click the orange Save button to finish. You should see the effect in your reports within a day.

Top Content Report - Time on Page

The GA "Top Content" report shows an overall average Time on Page in the report header, and an individiual average Time on Page for each blog page. This is how they are computed.

 Page  TimeOn  %Exit   Page   Total
Views    Page          Count  Time

    6    1:00  33.33%    4    4:00
    4     :30  25.00%    3    1:30
                       ---    ----
              Totals     7    5:30
    Avg Time on Page           :47  

Columns Page Views, Time On Page, and %Exit are from the GA report. We compute Page Count and Total Time. The figures above are an example containing two pages.

GA accumulates the total time spent on each page from all page views (not unique page views). GA divides this by the number of pages that accumulated a known viewing time. Page views that were interrupted by an "exit" could not be assigned a viewing time, because there is no endpoint available to calculate a time.

We calculate a "Page Count" column as the number of Page Views minus the number of exits = "Page Views" x (1 - "%Exit"). The "Time on Page" is the average viewing time for each one of these pages, so the total time measured for that page is "Time on Page" x "Page Count".

In the example, the first page has 6 Page Views with a 33.33% exit. So, 2 of the page views has no measured time, and the remaining 4 contributed to the 1:00 average viewing time. 1:00 x 4 = 4:00, the total viewing time known for that page. The same calculation for the second page gives 3 page views having a total viewing time of 1:30.

The Total Time for all measured pages is 5:30, and there were 7 measured pages, giving an overall average Time on Page (at the top of a GA report) of 0:47 per measured page. This approach entirely leaves out the unmeasured pages from the averages. This assumes that the unmeasured pages are probably average in the amount of viewing time. You can make your own estimates if you wish, knowing how the averages are computed.

The statistics in the report heading fit the following formula.
   Measured_Pages = PageViews x (1 - Exit%)
   Total Viewing Time = Measured_Pages x TimeOnPage

For example, given these numbers from a report heading:
Pageviews 100,  Unique Pageviews 80,  Time on Page 2:00,  Bounce Rate 30%,  Exit% 40%.
   Measured_Pages = 100 x (1 - 40%) = 60
   2 hours Total Viewing Time = 60 x 2:00

Tracking Outbound Links

You probably have links to other sites included in your blog. Without the Endpage code above, the user just disappears. With the Endpage code, the current time on that page is recorded, and the user disappears. Sometimes, you want to know if a particular link was used.

You can include a bit of JavaScript code in any link that you want to track individually. For example:

<a href="http://www.CoolOtherSite.com"
Goto Other Site</a>
The GA function _trackPageview('/outgoing/Cool') sets a checkpoint for '/outgoing/Cool' when the user clicks "Goto Other Site". The checkpoint can be any text.

This groups together outgoing link information under the artificial page name "/outgoing" . The "/Cool" part is whatever best reminds you of the link that is used, and could be the entire link name. You may use the same text for all links that you are tracking, or a different text for each one.

The Endpage code removes the need to track all outgoing links just to capture the Time Spent on the page. The above code is shown in short lines for display; it may appear in the HTML page as one line if desired.


Analytics Help Forum Archive: Discussions > Tracking Your Site
Questions and answers about site tracking.

Time-On-Page Goals in GA and Website Optimizer
09/05/07 - EpikOne by Justin Cutroni
Using setTimeout() with the older GA UrchinTracker code. The ideas can be applied to the current TrackPageview code.

New GA Tracking Code: GA.JS
09/16/07 - EpikOne by Justin Cutroni
An article about the then "new" TrackPageview code.

Standard Metrics #4 : Time on Page and Time on Site
01/08/2008 - kaushik.net by Avinash Kaushik
How GA and other services determine Time On Page

Google Analytics Tracking Code: Extending Event Tracking
2008 GA - Comprehensive, complicated event tracking with a new library of JavaScript functions.

No comments :

Post a Comment

You can use the HTML tags <b> <i> and <a href="">, but not <p> or <blockquote>. Trouble commenting? Email your comment or problem to Commerce-Try at Comcast.net. Leave out the minus sign. Mention the name of the post in the email.