0

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.

PЯINCƎ
11.8k3 gold badges27 silver badges85 bronze badges
asked Jul 31, 2019 at 5:28

1 Answer 1

0

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_preprocessed content

  • clean pub/static content

  • deploy the static content : php bin/magento setup:static-content:deploy -f

I don't test it, but it should work.

answered Jul 31, 2019 at 6:09
7
  • @Prince its throws some error. Commented Jul 31, 2019 at 8:34
  • What's that error ? Commented Jul 31, 2019 at 8:44
  • 'eventCallback': function() { document.location = 'checkout.html'; } Commented Jul 31, 2019 at 8:45
  • Its redirect to checkout.html. after that its throws ..magento2/checkout/checkout.html 404 error Commented Jul 31, 2019 at 8:46
  • Its need to redirect checkout.html or other page? Commented Jul 31, 2019 at 8:47

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.