A | B | C | D | |
---|---|---|---|---|
1 | Universal Analytics Cheat Sheet - Dev Guide | |||
2 | by Nicholas Blexrud | |||
3 | http://twitter.com/nicholasblexrud | |||
4 | ||||
5 | Advanced Configuration | |||
6 | Create a tracker | ga('create', 'UA-XXXX-Y'); | ||
7 | Sends a pageview | ga('send', 'pageview'); | ||
8 | Set a parameter | ga('set','pageview', '/my-custom-page'); | ||
9 | Create multiple trackers | ga('create', 'UA-XXXX-Y'); ga('create', 'UA-XXXX-Y', { 'name' : 'newTracker'}); // New tracker | ||
10 | Send pageview to both trackers | ga('send', 'pageview'); ga('newTracker.send', 'pageview'); // Send page view for new tracker. | ||
11 | Anonymize IP | ga('set', 'anonymizeIP', true); | ||
12 | User Opt-out | window['ga-disable-UA-XXXX-Y'] = true; | ||
13 | ||||
14 | ||||
15 | ||||
16 | Page Tracking | |||
17 | Sends virtual pageview | ga('send', 'pageview'); | ||
18 | Sends virtual pageview and title | ga('send', 'pageview', { 'page' : '/my-overridden-page?id=1', 'title' : my overridden page' }); | ||
19 | With field names | ga('send', { 'hitType' : 'pageview', 'page' : '/my-overridden-page?id=1', 'title' : 'my overridden page' }); | ||
20 | ||||
21 | ||||
22 | ||||
23 | Event Tracking | |||
24 | Sends event (basic) | ga('send', 'event', 'category', 'action') | ||
25 | Sends event (w/label & value) | ga('send', 'event', 'category', 'action', 'opt_label', opt_value); | ||
26 | Sends event w/o impacting bounce rate | ga('send', 'event', 'category', 'action', {nonInteraction' : 1}); | ||
27 | With field names | ga('send', { 'hitType' : 'event', // Required. 'eventCategory' : 'button', // Required. 'eventAction' : 'click', // Required. 'eventLabel' : 'nav buttons', 'eventValue' : 4 }); | ||
28 | ||||
29 | ||||
30 | ||||
31 | ||||
32 | Ecommerce | |||
33 | load the ecommerce plugin | ga('require','ecommerce','ecommerce.js'); | ||
34 | add transaction data to cart | ga('ecommerce:addTransaction', { 'id' : '1234', // Transaction ID. Required. 'affiliation' : 'Acme Clothing', // Affiliation or store name. 'revenue' : '11.99', // Grand Total. 'shipping' : '5', // Shipping. 'tax' : '1.29' // Tax. }); | ||
35 | add items to the shopping cart | ga('ecommerce:addItem', { 'id' : '1234', // Transaction ID. Required. 'name' : 'Fluffy Pink Bunnies', // Product name. Required. 'sku' : 'DD23444', // SKU/code. 'category' : 'Party Toys', // Category or variation. 'price' : '11.99', // Unit price. 'quantity' : '1' // Quantity. }); | ||
36 | send ecommerce data | ga('ecommerce:send'); | ||
37 | clear shopping cart | ga('ecommerce:clear'); | ||
38 | set currency codes | ga('set','currencyCode','EUR'); | ||
39 | ||||
40 | ||||
41 | ||||
42 | Social Interactions | |||
43 | send a social interactions | ga('send', 'social', 'socialNetwork', 'socialAction', 'socialtarget'); | ||
44 | With field names | ga('send', { 'hitType': 'social', 'socialNetwork': 'facebook', 'socialAction': 'like', 'socialTarget': 'http://mycoolpage.com', 'page': '/my-new-page' }); | ||
45 | ||||
46 | ||||
47 | ||||
48 | User Timings | |||
49 | send user timing data | ga('send', 'timingCategory', timingVar', timingValue, 'opt_timingLabel'); | ||
50 | With field names | ga('send', { 'hitType': 'timing', 'timingCategory': 'jQuery', 'timingVar': 'Load Library', 'timingValue': 20, 'timingLabel': 'Google CDN', 'page': '/my-new-page' }); | ||
51 | ||||
52 | ||||
53 | ||||
54 | Custom Dimensions & Metrics | |||
55 | Send custom dimension for a pageview | ga('send', 'pageview', { 'dimension15' : 'My Custom Dimension' }); | ||
56 | Send custom metric for event | ga('send', 'event', 'category', 'action', { 'metric18' : 8000 }); | ||
57 | Send custom metric with decimals | ga('send', 'event', 'category', 'action', { 'metric19': 24.99 }); | ||
58 | Set custom dimension | ga('set', 'dimension5', 'custom data'); | ||
59 | Set values for both dimensions and metric | ga('set', { 'dimension5' : 'custom dimension data', 'metric5' : 'custom metric data' }); | ||
60 | ||||
61 | ||||
62 | ||||
63 | Domains & Cookies | |||
64 | Modifying Cookie values | ga('create', 'UA-XXXX-Y', { 'cookieName': 'new_cookie_name' 'cookieDomain': 'mynew.domain.com', 'cookieExpires': 60 * 60 * 24 * 28 // Time in seconds. }); | ||
65 | Create Cookie for localhost | ga('create', 'UA-XXXX-Y', { 'cookieDomain': 'none' }); | ||
66 | Create Cookie for multiple sub domains | // Configuration for one.example.com ga('create', 'UA-XXXX-Y' {'cookieDomain': 'example.com'}); // Configuration for two.example.com ga('create', 'UA-1234-5' {'cookieDomain': 'example.com'}); | ||
67 | Modifying Cookie Expiration | ga('create', 'UA-XXXX-Y', { 'cookieExpires': 60 }); | ||
68 | Disabling Cookies | ga('create', 'UA-XXXX-Y', { 'storage': 'none', 'clientId', '35009a79-1a05-49d7-b876-2b884d0f825b' }); | ||
69 |