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>
@paulmkoch
paulmkoch / Scroll Tracker
Created May 15, 2014 16:23
Scroll Tracker
// Replace CATEGORY and ACTION with the names that you desire for your events.
<script type="text/javascript">
/**
* @name jQuery.trackScrolls
* @desc Watch for scrolling past certain positions.
*
* @example:
*