jQuery Google Analytics plugin
jQuery plugin that uses html5 data attributes for passing the required analytics fields.
by Mohammad Gouse
HTML
<script src="https://raw.github.com/JimBobSquarePants/jQuery-Google-Analytics/master/jquery.googleanalytics.js"></script>
<h1>jQuery Google Analytics tests</h1>
<h2>Event tracking</h2>
<p>
Track event with all attributes added. Triggered on <span class="pre ib">click</span>.
<script async src="https://www.googletagmanager.com/gtag/js?id=GA_TRACKING_ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-123350993-1');
</script>
CSS
body
{
color:#444;
font-family: Segoe UI,verdana,helvetica,arial,sans-serif;
}
.box .wrapper
{
padding:14px;
}
a
{
color:#F68A39;
}
a:hover, a:active
{
text-decoration:none;
}
a:active
{
color:#CE3709;
}
a:visited
{
color:#000;
}
h1
{
font-size:28px;
padding-bottom:14px;
}
h2
{
font-size:22px;
}
p
{
padding:14px 0;
}
.pre
{
font-family: consolas, monospace;
background:#EFEFEF;
padding: 0 2px;
}
.ib
{
display:inline-block;
}