Created
October 30, 2018 14:29
-
-
Save timba64/498903b2b0d31b5b2ee8b56d800cf334 to your computer and use it in GitHub Desktop.
Using Enhansed Ecommerce in Google Analytics
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// get elements and push click in google Analitics | |
(function(){ | |
var elems = document.querySelectorAll('.wcat-item'); | |
for (var i = 0; i < elems.length; i++) { | |
elems[i].addEventListener('click', function(e){ | |
var elName = this.querySelector('.name').textContent; | |
var elId = this.querySelector('.name').getAttribute('data-id'); | |
var elPrice = parseInt(this.querySelector('.woocommerce-Price-amount').textContent); | |
//e.preventDefault(); | |
dataLayer.push({ | |
'ecommerce': { | |
'currencyCode': 'BYN', | |
'click': { | |
'actionField': {'list': 'List 77'}, | |
'products': [{ | |
'name': elName, | |
'id': elId, | |
'price': elPrice, | |
'category': 'Category 1/Subcategory 11' | |
}] | |
} | |
}, | |
'event': 'gtm-ee-event', | |
'gtm-ee-event-category': 'Enhanced Ecommerce', | |
'gtm-ee-event-action': 'Product Clicks', | |
'gtm-ee-event-non-interaction': 'False', | |
}); | |
//console.log(elName); | |
}); | |
} // end for | |
})(); | |
//console.log(dataLayer); - can to see dataLayer object |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment