Skip to content

Instantly share code, notes, and snippets.

@MaKleSoft
Created July 2, 2014 10:20
Show Gist options
  • Save MaKleSoft/804fc5ba7dd6e2ad82b2 to your computer and use it in GitHub Desktop.
Save MaKleSoft/804fc5ba7dd6e2ad82b2 to your computer and use it in GitHub Desktop.
<script id="gtm-ga">
(function() {
var prevTag = document.getElementById("gtm-ga"),
prevTagParent = prevTag && prevTag.parentNode;
if (prevTag && prevTagParent) {
prevTagParent.removeChild(prevTag);
}
console.log("executing tag");
// RFC4122-compliant uuid generator
function uuid() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
});
}
if (!window.gaInitialized) {
// Load google analytics code
(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.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://rawgit.com/MaKleSoft/41e042d5f75afb0021e0/raw/9e47a40ae32a8ea3fc0bc258c2d7371fe4023f93/analytics.js','ga');
var supportsLocalStorage = typeof localStorage !== "undefined",
clientId = supportsLocalStorage && localStorage.getItem("ga-clientid") || uuid();
if (supportsLocalStorage) {
localStorage.setItem("ga-clientid", clientId);
}
ga('create', 'UA-28744302-3', 'auto', {
storage: "none",
clientId: clientId
});
window.gaInitialized = true;
console.log("custom ga loaded. client id: " + clientId);
}
console.log("sending event {{event}}");
ga("send", "event", "Helpling Mobile", "{{event}}", {hitCallback: function() {
console.log("event {{event}} sent!");
}});
})();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment