Examples

Extended Google Analytics measuremet.

E-commerce tracking

Set up an e-commerce tracking in Google Analytics is quite simple. Passed parameters are exactly the same as the parameters described in a Google Analytics e-commerce documentation. A sample code is below:

<script type="text/javascript" src="/analytics.js"></script>
<script type="text/javascript">
    _gas.setDomainName('.ga-script.org');
    _gas.create('UA-12345-1', 't1');

    // create a transaction
    _gas.push(['_addTrans',
        '1234', // unique order ID - required
        'Acme Clothing', // affiliate / shop name
        '11.99', // total price, without tax and transport - required
        '1.29', // tax - total amount
        '5', // amount used for transport
        'San Jose', // town / city
        'California', // state or province
        'USA' // country
    ]);

    // for all items in cart
    _gas.push(['_addItem',
        '1234', // transaction ID - used for association with the transaction, required
        'DD44', // SKU or other unique product ID - required
        'T-Shirt', // name of product - showed in Google Analytics
        'Olive Medium', // category or variant of product
        '11.99', // price per unit, without tax and transport - required
        '1' // count of units - required
    ]);
    
    // send a transaction
    _gas.push(['_trackTrans']);
</script>

If some parameter cannot be provided or you do not want to do it, use an undefined value instead of real value.

Event tracking

Passed parameters are exactly the same as the parameters described in a documentation of event tracking in Google Analytics. Here is example of event tracking when user click the link.

<script type="text/javascript" src="/analytics.js"></script>
<script type="text/javascript">
    _gas.setDomainName('.ga-script.org');
    _gas.create(['UA-12345-1', 't1']);
</script>
<a href="#" onClick="_gas.push(['_trackEvent', 'Click', 'Link text: CLICK HERE!'])">CLICK HERE!</a>

Setting custom variables

Passed parameters are exactly the same as the parameters described in a documentation of event tracking in Google Analytics. Sample code is here:

<script type="text/javascript" src="/analytics.js"></script>
<script type="text/javascript">
_gas.setDomainName('.ga-script.org'); _gas.create(['UA-12345-1', 't1']); _gas.push(['_setCustomVar', 1, 'Role', 'Administrator', 1]); </script>

It is also possible to push custom variables before a track pageview.

<script type="text/javascript" src="/analytics.js"></script>
<script type="text/javascript">
    _gas.setDomainName('.ga-script.org');
    _gas.push(['_setCustomVar', 1, 'Role', 'Administrator', 1]);
    _gas.create(['UA-12345-1', 't1']);
</script>

Tracking on multiple stages

Mesurement into multiple profiles

Just call the method _gas.create multiple times with appropriate parameters. First, you need to set the configuration for all trackers, then you need call the _gas.create method for each of the configured trackers.

<script type="text/javascript">
    // all configuration
    _gas.push(['_setDomainName', '.ga-script.org']);
    _gas.push(['new._setCustomVar', 1, 'Some name', 'Some value']);
    
    // create all trackers
    _gas.create('UA-123456-7', 'orig');
    _gas.create('UA-765432-1', 'new');
    </script>

Measurements on multiple subdomains

You need to call the method _gas.setConfigType. For measurements on multiple subdomains you need to enter the value 2. You must set the domain too.

<script type="text/javascript">
    _gas.setConfigType(2);
    _gas.push(['_setDomainName', '.ga-script.org']);
    _gas.create('UA-123456-7', 't1');
</script>

You must provide a valid form of all measured subdomains (e.g. '.ga-script.org' and not www.ga-script.org).

Measurement on multiple domains

You need to call the method _gas.setConfigType. For measurements on multiple domains you need to enter the value 3. You must set the domain too.

<script type="text/javascript">
_gas.push(['_setDomainName', '.ga-script.org']);
_gas.create('UA-123456-7', 'orig');
</script>

Placing more general shape of the domain is recommended (e.g. .ga-script.org and not www.ga-script.org).

Changing the sample for measuring the speed of the web

You can set a sample by _gas.push method with _setSiteSpeedSampleRate parameter. The value means a sample rate of tracked visitors, must be in range between 1 and 100. Google does not allow set more than 10 %. Google also does not allow sending more than 10 thousand hits per day. If the number of pageviews on your site is lower than 100 thousand per day, you can set some higher value up to 10 %. It is recommended to increase value to highest possible - according to the traffic on your site.

<script type="text/javascript">
    _gas.push(['_setSiteSpeedSampleRate', 50]);
    _gas.push(['_setDomainName', 'ga-script.org']);
    _gas.create('UA-123456-7', 'orig');
</script>

Add other search engine

Can be set by _gas.push method with _addOrganic parameter. Second value in array is search engines domain, third one is URL query parameter with query term.

<script type="text/javascript">
    _gas.push(['_addOrganic', 'novy-engine.com', 'q']);
    _gas.push(['_setDomainName', '.ga-script.org']);
    _gas.create('UA-12345-6', 'name');
</script>