Skip to content

Instantly share code, notes, and snippets.

View AFT - Google Tag Manager 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 -->
View Element is Link
@paulmkoch
paulmkoch / Event Label from Data Attribute
Created Sep 11, 2014
Event Label from Data Attribute
View 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 Sep 11, 2014
Event Action from Data Attribute
View 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 Sep 11, 2014
Event Category from Data Attribute
View 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 Sep 11, 2014
Get Values from Data Attribute
View 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
SoundCloud Custom Tracking File
View 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=
View URL with hash
function() {
var urlWithHash = location.pathname + location.search + location.hash;
return urlWithHash;
}
View 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
Element URL Matches Current URL with Hash
View Element URL Matches Current URL with Hash
function(){
if ( {{element url}}.indexOf({{url}} + '#') === 0 ) {
return true;
}
return false;
}