5

Google Analytics cheatsheet

 2 years ago
source link: https://devhints.io/google_analytics
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Pageview

// Analytics.js
ga('create', 'UA-XXXX-Y', 'auto');
ga('send', 'pageview');

Track events

// ga.js
// [..., category, action, label, value (int), noninteraction (bool)]
_gaq.push(['_trackEvent', 'Videos', 'Play', 'Birthday video', true])
_gaq.push(['_trackEvent', 'Projects', 'Donate', 'Project name'])
_gaq.push(['_trackEvent', 'Accounts', 'Login'])

// Analytics.js
//       ,        ,  category,  action,  label,         value (int)
ga('send', 'event', 'button',   'click', 'nav buttons', 4);

Variables

// [..., index, name, value, scope (optional)]
_gaq.push(['_setCustomVar', 1, 'Logged in', 'Yes', 2]);

// Scope = 1 (visitor), 2 (session), 3 (page, default)

https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingCustomVariables https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK