Tracker Functions

There are a number of functions built into the GoSquared Tracker that you can use to customise its behaviour on your site.

GoSquared.load

If you assign a function to this property, it will be called as soon as the tracking code has loaded.

As the tracker is loaded asynchronously, you may want to know exactly when it has finished loading, before you can fire off custom events. By integrating this function into your site's JavaScript, you receive a callback as soon as the tracking code has loaded, but before it executes the TrackView function. This way you can set any extra custom parameters just before the page view is tracked.

The default tracker object is passed to this function as an argument, so you can cancel the default tracking behaviour or track any custom data.

Tracker.TrackView(url,title)

Use this function to track custom page views. If your site is heavily AJAX-based, and your visitors navigate around the site without actually leaving or reloading the page, you can use this function to fire a custom page view event, which will be seen by our tracking engine exactly like a normal page view.

This function is available on all Tracker objects, so can be called on GoSquared.DefaultTracker or any tracker created by GoSquared.Tracker.

GoSquared.Tracker(acct,name)

The GSTC automatically creates a tracker in GoSquared.DefaultTracker, but if you want to create a custom tracker object for better integration with your existing JavaScript, you can use this function to create your own.

The new tracker needs a GoSquared Account Code (found in the 'Tracking Code' section of the settings app), and a name, a unique identifier, which can be any string you want.

If the name you specify is the same as for a tracker you've created previously, this function will return that tracker. So if you call this function twice with the same name, the first time it'll create a new tracker, and the second time it'll return that same tracker.

Tracker.Cancel()

If you're using GoSquared.load to fire a callback once the tracking script has loaded, you may want to stop the tracker automatically tracking the page view, so you can fire custom page views later. Call this function on the tracker to stop this default behaviour.

An Example

Here's an example of how you might use some of these functions in your JavaScript:

<script>
    var GoSquared = {}, myAwesomeTracker;
    GoSquared.acct = 'GSN-0000000-A';
    GoSquared.load = function(tracker){
        // cancel the default tracker and create our own
        tracker.Cancel();
        myAwesomeTracker = GoSquared.Tracker(GoSquared.acct, 'my tracker');
    };
    (function(w){
        ... all the other tracking code ...
    })(window)

    ... later on in your script ...
		
    myAwesomeTracker.TrackView('/custom_url', 'Custom Page Title');
</script>
Last modified: 4 April 2011 09:52
Get Satisfaction
Follow us on Twitter
Send us an Email
Call us +44 (0) 20 8144 0401