JSFiddle - React, Tailwind, and code Playground

by nicomiceli

HTML

<html>
<head>
    <script>
// 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','//www.google-analytics.com/analytics.js','ga');
 
//The sites UA code which is different then the profile of the data you want to track 
        ga('create', 'UA-11111111-1', 'nicomiceli.com');
        ga('send', 'pageview');
    </script>
</head>
 
<body>
    <h1>Click the button</h1>
    <button id='button'>click me</button>
 
    <script>
var site = window.location.hostname
  	var url = "http://www.google-analytics.com/collect"
//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
        document.getElementById("button").addEventListener("click",
            function () {
                //function that loads after every click
                var xhr = new XMLHttpRequest();
                xhr.open("POST", url, false);
                xhr.onload = console.log('loaded')
                xhr.send(data)
                // Uncomment the following line for debugging
                //console.log("sent to " + data)
            },
            false
        );
    </script>
</body>
 
</html>