I am using Magento 2.2.0 Community Edition for one of our project. We have implemented Google Tag Manager And Google Analytics as per the Magento2 Guidelines.
After few days we came to know that our transactions are working properly but Tag Manger is showing 2 times (In Google Chrome Add ON - Google Tag Assistant)
Because of this Google Tag Manager showing twice issue we have implemented the solution as given in this following link.
https://github.com/magento/magento2/issues/12221
Then tag manager is showing only one time but google transactions are not working.
We searched on this then we come to know that this issue has been fixed in Magento v 2.2.6. Hence we just copied their "google-analytics.js" file to our version 2.2.0 .
After that our google tag manager is showing only one time but still transaction is not been send to Google. The transaction tracking is completely stopped. Is there any solution ? Is there any update for Magento v 2.2.0 ? Because we cannot upgrade our magento to latest one.
Please help! Thanks in advanced
Solved! Go to Solution.
Hello @maratheprash
According to Magento core fixes you can edit app/code/Magento/GoogleAnalytics/view/frontend/web/js/google-analytics.js file as:
Find this line if (config.ordersTrackingData.length) { and replace withif (config.ordersTrackingData.hasOwnProperty('currency')) {
https://github.com/magento/magento2/commit/e46e5a5cf49ae5d2d1833b29403d7c2a3af3d5a8
It should work.
Hello @maratheprash
According to Magento core fixes you can edit app/code/Magento/GoogleAnalytics/view/frontend/web/js/google-analytics.js file as:
Find this line if (config.ordersTrackingData.length) { and replace withif (config.ordersTrackingData.hasOwnProperty('currency')) {
https://github.com/magento/magento2/commit/e46e5a5cf49ae5d2d1833b29403d7c2a3af3d5a8
It should work.
Hey @Manish Mittal
Thanks for your help...
Yes We already added source code of google-analytics.js from latest version of Magento 2.2.6.
Instead of "length" the "currency" check is already there. But still transactions are not getting tracked.
Please help !
/** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ /* jscs:disable */ /* eslint-disable */ define([ 'jquery', 'mage/cookies' ], function ($) { 'use strict'; /** * @param {Object} config */ return function (config) { var allowServices = false, allowedCookies, allowedWebsites; if (config.isCookieRestrictionModeEnabled) { allowedCookies = $.mage.cookies.get(config.cookieName); if (allowedCookies !== null) { allowedWebsites = JSON.parse(allowedCookies); if (allowedWebsites[config.currentWebsite] === 1) { allowServices = true; } } } else { allowServices = true; } if (allowServices) { (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'); // Process page info ga('create', config.pageTrackingData.accountId, 'auto'); if (config.pageTrackingData.isAnonymizedIpActive) { ga('set', 'anonymizeIp', true); } // Process orders data if (config.ordersTrackingData.hasOwnProperty('currency')) { ga('require', 'ec', 'ec.js'); //Set currency code ga('set', 'currencyCode', config.ordersTrackingData.currency); // Collect product data for GA if (config.ordersTrackingData.products) { $.each(config.ordersTrackingData.products, function (index, value) { ga('ec:addProduct', value); }); } // Collect orders data for GA if (config.ordersTrackingData.orders) { $.each(config.ordersTrackingData.orders, function (index, value) { ga('ec:setAction', 'purchase', value); }); } ga('send', 'pageview'); }else{ // Process Data if not orders ga('send', 'pageview' + config.pageTrackingData.optPageUrl); } } } });
Here is the source code of google-analytics.js file what we used from latest version 2.2.6 to our own version 2.2.0
@Manish Mittal
Yes If I check in browser and view source code the script is there.
Please share the screenshot of google analytic script or script code in which we are calling google analytic account number.
<script type="text/x-magento-init"> { "*": { "Magento_GoogleAnalytics/js/google-analytics": { "isCookieRestrictionModeEnabled": 0, "currentWebsite": 1, "cookieName": "user_allowed_save_cookie", "ordersTrackingData": [], "pageTrackingData": {"optPageUrl":"","isAnonymizedIpActive":"0","accountId":"UA-1*****"} } } } </script> <!-- END GOOGLE ANALYTICS CODE -->
@Manish Mittal This is our analytics code .
Thanks for your support !
I will suggest try with third party google analytic tool now, if that will work for you then great:
https://www.weltpixel.com/google-analytics-enhanced-ecommerce-tag-manager-magento-2.html
https://marketplace.magento.com/tatvic-enhancedecommerce.html
https://www.mageplaza.com/blog/how-to-configure-google-analytics-in-magento-2.html
https://store.fooman.co.nz/magento-extension-googleanalyticsplus-m2.html
Hello @Manish Mittal
Ok I will try above extensions/tools as per your suggestion.
Thanks for your prompt reply. I really appreciate your help.
I will keep you posted on this !
Thank you so much once again !