Skip to content

Instantly share code, notes, and snippets.

@paulmkoch
paulmkoch / Event Category, Action, or Label of Existing Data Attribute
Created May 15, 2014 16:52
Event Category, Action, or Label of Existing Data Attribute
// replace the attribute with the appropriate data attribute
// if the attribute is divided with something other than commas, change tracking.split
// change the number to 0, 1, or 2, depending on whether you want the category, action, or label
function() {
var tracking = {{element}}.getAttribute('data-track-event');
tracking = tracking.split(',');
@paulmkoch
paulmkoch / Element Has an Existing Data Attribute
Created May 15, 2014 16:51
Element Has an Existing Data Attribute
// This macro looks for elements with data-track-event.
// To look for other attributes, replace "data-track-event" below.
// Note that it applies only to a specific element, and doesn't appropriately bubble.
function() {
var tracking = {{element}}.getAttribute('data-track-event');
if (tracking) {
return true;
} else {
return false;
@paulmkoch
paulmkoch / Viewport Dimensions
Created May 15, 2014 16:31
Viewport Dimensions
<script>
if (window.$) {
var width = $(window).width();
var height = $(window).height();
ga('send', 'event', 'Viewport', 'Size', width + 'x' + height, 0, {'nonInteraction': 1});
}
</script>
<!-- Google Tag Manager -->
<noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-TGVFDQ"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-TGVFDQ');</script>
<!-- End Google Tag Manager -->