Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
// Normal Universal 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','//','ga');
//The sites UA code which is different then the profile of the data you want to track
ga('create', 'UA-11111111-1', '');
ga('send', 'pageview');
<h1>Click the button</h1>
<button id='button'>click me</button>
var site = window.location.hostname
var url = ""
//Get the current unix time in JS and assign it to the cid
var cid = (new Date).getTime();
// Parameters of the POST request notice the different UA
var data ="v=1&tid=UA-40202040-2&cid="+cid+"&t=event&ec="+site+"&ea=click&el=button"
//Event listener for clicks on the button
function () {
//function that loads after every click
var xhr = new XMLHttpRequest();"POST", url, false);
xhr.onload = console.log('loaded')
// Uncomment the following line for debugging
//console.log("sent to " + data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment