JSFiddle - React, Tailwind, and code Playground
by roberkules
JavaScript
// first thing to do, make sure _gaq is defined:
var _gaq = _gaq || [];
// set your account settings:
_gaq.push(['_setAccount', 'UA-XXXXX-X']);
// queue trackpageview whenever you want :)
_gaq.push(['_trackPageview']);
//////////////////////////////////////////////////////////////////
(function($){
// load the GA script only after the dom is ready
// for simplicity using jQuery, of course you can just listen to the DOMContentLoaded / window.load event
$(function(){
// standard code provided by google to load the GA script
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
});
})(jQuery);
//////////////////////////////////////////////////////////////////
// if the script is already loaded, it will execute the tracking request, otherwise it's in the queue
_gaq.push(['_trackEvent', 'Videos', 'Play', 'Gone With the Wind']);