Skip to content

Instantly share code, notes, and snippets.

@paulmkoch
paulmkoch / Element is Link
Created September 11, 2014 22:25
Element is Link
@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:
*
@paulmkoch
paulmkoch / Event Label from Data Attribute
Created September 11, 2014 22:24
Event Label from Data Attribute
// This macro looks for data attributes whose values are separated by a pipe ('|'). Replace the pipe with the separator your data attribute uses, such as a comma.
function() {
tracking = {{Get Values from Data Attribute}};
tracking = tracking.split('|');
return tracking[2];
}
@paulmkoch
paulmkoch / Event Action from Data Attribute
Created September 11, 2014 22:23
Event Action from Data Attribute
// This macro looks for data attributes whose values are separated by a pipe ('|'). Replace the pipe with the separator your data attribute uses, such as a comma.
function() {
tracking = {{Get Values from Data Attribute}};
tracking = tracking.split('|');
return tracking[1];
}
@paulmkoch
paulmkoch / Event Category from Data Attribute
Created September 11, 2014 22:22
Event Category from Data Attribute
// This macro looks for data attributes whose values are separated by a pipe ('|'). Replace the pipe with the separator your data attribute uses, such as a comma.
function() {
tracking = {{Get Values from Data Attribute}};
tracking = tracking.split('|');
return tracking[0];
}
@paulmkoch
paulmkoch / Get Values from Data Attribute
Created September 11, 2014 22:16
Get Values from Data Attribute
// Returns: Values of data attribute
// Replace 'data-track-gtm' with the data attribute you're seeking
function() {
var isSet = function(val) {
return val !== null && val !== '';
};
var el = {{element}};
var val = el.getAttribute('data-track-gtm');
@paulmkoch
paulmkoch / SoundCloud Custom Tracking File
Created May 15, 2014 17:17
SoundCloud Custom Tracking File
<script>
(function(){var requirejs,require,define,__inflate;(function(e){function a(e,t){var n=t&&t.split("/"),i=r.map,s=i&&i["*"]||{},o,u,a,f,l,c,h;if(e&&e.charAt(0)==="."&&t){n=n.slice(0,n.length-1),e=n.concat(e.split("/"));for(l=0;h=e[l];l++)if(h===".")e.splice(l,1),l-=1;else if(h===".."){if(l===1&&(e[2]===".."||e[0]===".."))return!0;l>0&&(e.splice(l-1,2),l-=2)}e=e.join("/")}if((n||s)&&i){o=e.split("/");for(l=o.length;l>0;l-=1){u=o.slice(0,l).join("/");if(n)for(c=n.length;c>0;c-=1){a=i[n.slice(0,c).join("/")];if(a){a=a[u];if(a){f=a;break}}}f=f||s[u];if(f){o.splice(0,l,f),e=o.join("/");break}}}return e}function f(t,n){return function(){return u.apply(e,s.call(arguments,0).concat([t,n]))}}function l(e){return function(t){return a(t,e)}}function c(e){return function(n){t[e]=n}}function h(r){if(n.hasOwnProperty(r)){var s=n[r];delete n[r],i[r]=!0,o.apply(e,s)}if(!t.hasOwnProperty(r))throw new Error("No "+r);return t[r]}function p(e,t){var n,r,i=e.indexOf("!");return i!==-1?(n=a(e.slice(0,i),t),e=e.slice(i+1),r=
@paulmkoch
paulmkoch / URL with hash
Created May 15, 2014 17:05
URL with hash
function() {
var urlWithHash = location.pathname + location.search + location.hash;
return urlWithHash;
}
@paulmkoch
paulmkoch / Pageview onhashchange
Created May 15, 2014 17:04
Pageview onhashchange
<script>
var pageView = function() {
_gaq.push(['_trackPageview', {{url with hash}}]);
};
if (!('onhashchange' in window)) {
var oldHref = location.href;
setInterval(function() {
var newHref = location.href;
@paulmkoch
paulmkoch / Element URL Matches Current URL with Hash
Created May 15, 2014 16:53
Element URL Matches Current URL with Hash
function(){
if ( {{element url}}.indexOf({{url}} + '#') === 0 ) {
return true;
}
return false;
}