Skip to content

Instantly share code, notes, and snippets.

@aSadhankar aSadhankar/Shopify_UA_example Secret
Created Apr 25, 2014

Embed
What would you like to do?
<head>
...
<script type="text/javascript">
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-47822619-1', 'auto', {'allowLinker': true});ga('send', 'pageview');
(function(){
ga('require', 'linker');
function addListener(element, type, callback) {
if (element.addEventListener) {
element.addEventListener(type, callback);
}
else if (element.attachEvent) {
element.attachEvent('on' + type, callback);
}
}
function decorate(event) {
event = event || window.event;
var target = event.target || event.srcElement;
if (target && (target.action || target.href)) {
ga(function (tracker) {
var linkerParam = tracker.get('linkerParam');
document.cookie = '_shopify_ga=' + linkerParam + ';';
});
}
}
addListener(window, 'load', function(){
for (var i=0; i<document.forms.length; i++) {
if(document.forms[i].action && document.forms[i].action.indexOf('/cart') >= 0) {
addListener(document.forms[i], 'submit', decorate);
}
}
for (var i=0; i<document.links.length; i++) {
if(document.links[i].href && document.links[i].href.indexOf('/checkout') >= 0) {
addListener(document.links[i], 'click', decorate);
}
}
})
}());
</script>
...
</head>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.