dojox/analytics/Urchin (version 1.10)

Summary

A Google-analytics helper, for post-onLoad inclusion of the tracker, and dynamic tracking during long-lived page cycles.

A small class object will allows for lazy-loading the Google Analytics API at any point during a page lifecycle. Most commonly, Google-Analytics is loaded via a synchronous script tag in the body, which causes dojo.addOnLoad to stall until the external API has been completely loaded. The Urchin helper will load the API on the fly, and provide a convenient API to use, wrapping Analytics for Ajaxy or single page applications.

The class can be instantiated two ways: Programatically, by passing an acct: parameter, or via Markup / dojoType and defining a djConfig parameter urchin:

IMPORTANT: This module will not work simultaneously with the core dojox.analytics package. If you need the ability to run Google Analytics AND your own local analytics system, you MUST include dojox.analytics._base BEFORE dojox.analytics.Urchin

Usage

var foo = new Urchin(args);
dojox/analytics/Urchin
Parameter Type Description
args undefined

See the dojox/analytics/Urchin reference documentation for more information.

Examples

Example 1

// create the tracker programatically:
var tracker = new dojox.analytics.Urchin({ acct:"UA-123456-7" });

Example 2

// define the urchin djConfig option:
var djConfig = { urchin: "UA-123456-7" };

// and in markup:
<div dojoType="dojox.analytics.Urchin"></div>
// or code:
new dojox.analytics.Urchin();

Example 3

// create and define all analytics with one tag.
<div dojoType="dojox.analytics.Urchin" acct="UA-12345-67"></div>

Property Summary

  • acctyour GA urchin tracker account number.

Method Summary

  • _gotGA() initialize the tracker
  • GAonLoad() Stub function to fire when urchin is complete
  • trackPageView(url) A public API attached to this widget instance, allowing you Ajax-like notification of updates.

Properties

acct

your GA urchin tracker account number. Overrides djConfig.urchin

Methods

_gotGA()

initialize the tracker

GAonLoad()

Stub function to fire when urchin is complete

This function is executed when the tracker variable is complete and initialized. The initial trackPageView (with no arguments) is called here as well, so remeber to call manually if overloading this method.

Examples

Example 1

Create an Urchin tracker that will track a specific page on init after page load (or parsing, if parseOnLoad is true)

dojo.addOnLoad(function(){
    new dojox.ananlytics.Urchin({
        acct:"UA-12345-67",
        GAonLoad: function(){
            this.trackPageView("/custom-page");
        }
    });
});
trackPageView(url)

A public API attached to this widget instance, allowing you Ajax-like notification of updates.

Parameter Type Description
url String

A location to tell the tracker to track, eg: "/my-ajaxy-endpoint"

Examples

Example 1

Track clicks from a container of anchors and populate a ContentPane

// 'tracker' is our `Urchin` instance, pane is the `ContentPane` ref.
dojo.connect(container, "onclick", function(e){
    var ref = dojo.attr(e.target, "href");
    tracker.trackPageView(ref);
    pane.attr("href", ref);
});
Error in the documentation? Can’t find what you are looking for? Let us know!