OSDN Git Service

Regular updates
[twpd/master.git] / google_analytics.md
1 ---
2 title: Google Analytics
3 layout: 2017/sheet
4 tags: [Archived]
5 archived: This sheet describes an older version of Google Analytics (UA).
6 ---
7
8 ### Pageview
9
10     // Analytics.js
11     ga('create', 'UA-XXXX-Y', 'auto');
12     ga('send', 'pageview');
13
14 ### Track events
15
16     // ga.js
17     // [..., category, action, label, value (int), noninteraction (bool)]
18     _gaq.push(['_trackEvent', 'Videos', 'Play', 'Birthday video', true])
19     _gaq.push(['_trackEvent', 'Projects', 'Donate', 'Project name'])
20     _gaq.push(['_trackEvent', 'Accounts', 'Login'])
21
22     // Analytics.js
23     //       ,        ,  category,  action,  label,         value (int)
24     ga('send', 'event', 'button',   'click', 'nav buttons', 4);
25
26 ### Variables
27
28     // [..., index, name, value, scope (optional)]
29     _gaq.push(['_setCustomVar', 1, 'Logged in', 'Yes', 2]);
30
31     // Scope = 1 (visitor), 2 (session), 3 (page, default)
32
33 ### References
34
35 - <https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingCustomVariables>
36 - <https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide>