I want to measure checkout page using tag manager Enhanced Ecommerce.
I refered https://developers.google.com/tag-manager/enhanced-ecommerce#checkout.
How to add this script.
Thanks.
1 Answer 1
app/design/frontend/{Vendor}/{theme}/requirejs-config.js
var config = {
map: {
'*': {
measuringcheckout: 'js/measuring_checkout'
}
}
};
app/design/frontend/{Vendor}/{theme}/web/js/measuring_checkout.js
define(['jquery'], function($){
"use strict";
//your Google script
return function onCheckout()
{
alert('Google measuring checkout OK');//just for JS loading test
dataLayer.push({
'event': 'checkout',
'ecommerce': {
'checkout': {
'actionField': {'step': 1, 'option': 'Visa'},
'products': [{
'name': 'Triblend Android T-Shirt',
'id': '12345',
'price': '15.25',
'brand': 'Google',
'category': 'Apparel',
'variant': 'Gray',
'quantity': 1
}]
}
},
'eventCallback': function() {
document.location = 'checkout.html';
}
});
}
});
app/design/frontend/{Vendor}/{theme}/Magento_Checkout/templates/onepage.phtml
<script type="text/javascript">
require(['jquery', 'measuringcheckout'], function(,ドル onCheckout) {
onCheckout();
});
</script>
You should also:
clean the cache
clean
var/view_preprocessedcontentclean
pub/staticcontentdeploy the static content :
php bin/magento setup:static-content:deploy -f
I don't test it, but it should work.
-
@Prince its throws some error.Mahi M– Mahi M2019年07月31日 08:34:09 +00:00Commented Jul 31, 2019 at 8:34
-
-
'eventCallback': function() { document.location = 'checkout.html'; }Mahi M– Mahi M2019年07月31日 08:45:12 +00:00Commented Jul 31, 2019 at 8:45
-
Its redirect to checkout.html. after that its throws ..magento2/checkout/checkout.html 404 errorMahi M– Mahi M2019年07月31日 08:46:12 +00:00Commented Jul 31, 2019 at 8:46
-
Its need to redirect checkout.html or other page?Mahi M– Mahi M2019年07月31日 08:47:27 +00:00Commented Jul 31, 2019 at 8:47
Explore related questions
See similar questions with these tags.