Skip to content

Instantly share code, notes, and snippets.

@iTonyYo
Last active October 25, 2015 14:59
Show Gist options
  • Save iTonyYo/9927606 to your computer and use it in GitHub Desktop.
Save iTonyYo/9927606 to your computer and use it in GitHub Desktop.
Google analytics code snippet with jade template engine. Jade ' include ' allows you to insert the contents into another jade file simply.
//
Build Passing.
Doctype: HTML5
Jade: 1.3.0+
#TODO[x]: Google analytics References
https://developers.google.com/analytics/ →_→ Optimize Your
Business Using the Google Analytics Platform
https://developers.google.com/analytics/devguides/collection/
Google Analytics provides easy to use APIs and SDKs to send
data to Google Analytics.
http://mathiasbynens.be/notes/async-analytics-snippet →_→ Opti-
mizing the asynchronous Google Analytics snippet
script.
var trackID, domainID;
trackID = ''; //eg: 'UA-34398778-4'.
domainID = ''; //eg: 'studio7designs.com'.
(function (i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r;
i[r] = i[r] || function () {
(i[r].q = i[r].q || []).push(arguments);
},
i[r].l = 1 * new Date();
a = s.createElement(o),
m = s.getElementsByTagName(o)[0];
a.async = 1;
a.defer = 1;
a.src = g;
m.parentNode.insertBefore(a,m)
})(window, document, 'script','//www.google-analytics.com/analytics.js', 'ga');
ga('create', trackID, domainID);
ga('send', 'pageview');
@nedzen
Copy link

nedzen commented Feb 18, 2015

so how do you include it in your page?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment