Skip Navigation

Web Developer Network Wiki

Google Analytics for the UNL Templates

University Communications has researched options for analytical tracking of all pages on unl.edu. This includes every page in the UNL Template.

Google Analytics has been selected to provide University Communications with site-wide analytical data. The tracking code has been installed into the template dependent files, effective December 12, 2008.

Contents

[edit] Google Analytics Version

As outlined by Google in October 2007, the urchin.js version of Google Analytics is being deprecated. All future changes and advancements will only be made to the latest version (ga.js). If you are using the old version of Google Analytics (urchin.js) you must update immediately to ensure correct analytical tracking.

Google Analytics allows for multiple tracking accounts to be installed on a single page, therefore allowing individual departments the maximum flexibility provided by Google Analytics for specific tracking. This requirement is only found in the latest version (ga.js).

[edit] Implementing Google Analytics on Individual Department Sites

If you would like to implement Google Analytics on your site and your site is not a directory of unl.edu on Frontier, you can simply follow the directions provided by Google Analytics for adding page tracking.

If you would like to implement GA on your site and your site is a directory of unl.edu on Frontier, then additional steps must be taken:

  1. Follow the installation instructions provided by Google Analytics
  2. Add the following lines to the pageTracker code section on each tracked page:
    pageTracker._setDomainName(".unl.edu");
    pageTracker._setAllowHash(false);
    

    The above code should be placed above the other pageTracker calls. For example:

    var pageTracker = _gat._getTracker("UA-XXXXXXX-X"); //replace with your unique tracker id
    pageTracker._setDomainName(".unl.edu");
    pageTracker._setAllowHash(false);
    pageTracker._initData();
    pageTracker._trackPageview();
    

    To include on every page easily, put the code in the footer include file.

[edit] Streamlining the Google Analytics Implementation Code

The current UNL template tracking code is setup in such a fashion to allow the initial loading of the ga.js file to be used multiple times. Therefore, if installing GA on your site, you may opt-out of adding the following code to each of your pages:

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

Though this is not required (functionality will be the same with or without this code), it is recommended to not add this code to your pages. This way, if Google changes the code and University Communications updates the site-wide tracking code, individual departments will not be required to update as well.

[edit] Google Analytics Customization

In this section, tips and tricks used by departments with Google Analytics can be shared.

[edit] Exclude Internal Traffic Filters

When setting up a profile to exclude internal traffic, the following filters must be created and assigned to the profile:

  1. Exclude IP Range: 129.93.X.X
  2. Exclude IP Range: 216.128.208.X
  3. Exclude IP Range: 64.39.240.X
  4. Exclude IP Range: 65.123.32.X

These IP ranges were chosen based on the WDN Forum thread outlining the on campus IP ranges and masks.

[edit] Exclude IP Range: 129.93.X.X

The regular expression to use for this filter:

^129\.93\.

[edit] Exclude IP Range: 216.128.208.X

The regular expression to use for this filter:

^216\.128\.208\.([0-9]|[1-9][0-9])$

[edit] Exclude IP Range: 64.39.240.X

The regular expression to use for this filter:

^64\.39\.240\.([0-9]|[1-9][0-9])$

[edit] Exclude IP Range: 65.123.32.X

The regular expression to use for this filter:

^65\.123\.32\.([0-9]|[1-9][0-9])$

[edit] Setup Local Site Search

If you are using Google Custom Search on your site and would like to track site searches, simply:

  1. Login into your Google Analytics account and edit the profile for which you would like to add the search tracking. Note: Each profile for site search should be tracked must be setup individually.
  2. Click "edit" next to the Main Website Profile Information.
  3. Select the "Do track site search" option under the "Site Search" section
  4. For the "Query Parameter" input box, enter:
    q
  5. Select the "Yes, strip query parameters out of URL" option.
  6. Select "No" for the "Do you use categories for site search?" question

[edit] Track Links to Documents

Google Analytics does not track documents or files that are non HTML based by default. However, with a custom "hack" you can track the interaction when a user clicks the link to a specific document.

To do this, you must add an onclick event to the a tag corresponding to the link to the document you would like tracked. For example:

<a href="/myDocument.pdf" title="My PDF" onclick="javascript:pageTracker._trackPageview('documents/pdf/myDocument');">My Document</a>

The tracking will be available in your content report listed as 'documents/pdf/myDocument'.