Skip to content

Instantly share code, notes, and snippets.

@antlis
Last active November 26, 2019 18:44
Show Gist options
  • Save antlis/56cd3963182ebaeadec55a23efbb60f9 to your computer and use it in GitHub Desktop.
Save antlis/56cd3963182ebaeadec55a23efbb60f9 to your computer and use it in GitHub Desktop.
Google analytics pug mixin
mixin ga(id)
//- Pass your ga id, as an attribute, eg. +ga('yourid12345')
script.
(function(b,o,i,l,e,r){b.GoogleAnalyticsObject=l;b[l]||(b[l]=
function(){(b[l].q=b[l].q||[]).push(arguments)});b[l].l=+new Date;
e=o.createElement(i);r=o.getElementsByTagName(i)[0];
e.src='https://www.google-analytics.com/analytics.js';
r.parentNode.insertBefore(e,r)}(window,document,'script','ga'));
ga('create', !{id});ga('send','pageview');
@antlis
Copy link
Author

antlis commented Aug 28, 2019

Also here is pug google analytics mixin, that will output script like you can find in HTML5 boilerplate.

That makes the code more flexible, thanks a lot! :D

No problem

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