It looks like a problem in the GoogleAnalytics/view/frontend/web/js/google-analytics.js file, line 54 on, which calls ga('send', 'pageview'... twice:
`
ga('send', 'pageview' + config.pageTrackingData.optPageUrl);
// Process orders data
if (config.ordersTrackingData) {
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');`
I can confirm the same issue on 2.2.0.
I changed as below and it seems to resolve the specific issue, it may have other consequences that I'm not yet aware of. At least with the Google Tag Assistant recording, I don't get the duplicate hits issue any more.
Step 1. : Change the GoogleAnalytics/view/frontend/web/js/google-analytics.js file
/**
* Removed this line
* ga('send', 'pageview' + config.pageTrackingData.optPageUrl)
*/
// Process orders data
if (config.ordersTrackingData) {
ga('require', 'ec', 'ec.js');
// 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 {
// added it here instead
ga('send', 'pageview' + config.pageTrackingData.optPageUrl);
}
Step 2: Remove deployed content and deploy it again, resolve any permission issues depending on your installation and language issues as well
I guess those issues are pretty unique to me... but in principle rm -R pub/static/* and deploy static content again.
The error message in Google tag assistant recording, Google analytics report-tab prior to applying above:
This hit was preceded by an identical pageview hit. It's likely that this hit is a duplicate. If you have consecutive duplicate pageview hits, your bounce rate and pageview numbers could be inaccurate.
I had made exactly the same change to mine as KarlComSe, and it resolve the issue from the pageview point of view.
I've not looked more, but it does seem to be failing to track ecommerce though, with sales values not showing.
@alexhadley I didn't test conversion tracking / sales tracking with the tag manager recording yesterday, but can see several orders from yesterday in Google Analytics. Those orders were made after the change to the .js-file. Hence, my conclusion is that above changes still tracks transactions.
@alexhadley, thank you for your report.
We've created internal ticket(s) MAGETWO-84155 to track progress on the issue.
@magento-engcom-team, is there any update on this fix? We just moved to magento 2.2 and are seeing the same issue as above. Pageviews are being tracked twice which is causing bounce rates and pages per session to be incorrect. Ecommerce Tracking of transactional data is coming through correctly.
Working on fixing this issue #MM18IN
@bhargavmehta thank you for joining. Please accept team invitation here and self-assign the issue.
Hi @alexhadley. Thank you for your report.
The issue has been fixed in magento/magento2#13034 by @bhargavmehta in 2.2-develop branch
Related commit(s):
The fix will be available with the upcoming patch release.
Hi @alexhadley. Thank you for your report.
The issue has been fixed in magento-engcom/magento2ce#1351 by @magento-engcom-team in 2.3-develop branch
Related commit(s):
The fix will be available with the upcoming 2.3.0 release.
I think that fix is not fully right because config.ordersTrackingData on the Success page is an object, so we can't check the 'length' property for this
Conversion doesnt work here too. Ravinsky is right I guess.
You have to modify the ga.phtml file to get the ecommerce tracking because as @ravinsky said you can't use .lenght on an object so you have to keep the old statement in the js file too:
<?php
/**
* Copyright 漏 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
// @codingStandardsIgnoreFile
?>
<?php /** @var $block \Magento\GoogleAnalytics\Block\Ga */ ?>
<?php $accountId = $block->getConfig(\Magento\GoogleAnalytics\Helper\Data::XML_PATH_ACCOUNT) ?>
<?php $orderTrackingData = $block->getOrdersTrackingData() ?>
<!-- BEGIN GOOGLE ANALYTICS CODE -->
<script type="text/x-magento-init">
{
"*": {
"Magento_GoogleAnalytics/js/google-analytics": {
"isCookieRestrictionModeEnabled": <?= (int)$block->isCookieRestrictionModeEnabled() ?>,
"currentWebsite": <?= (int)$block->getCurrentWebsiteId() ?>,
"cookieName": "<?= /* @escapeNotVerified */ \Magento\Cookie\Helper\Cookie::IS_USER_ALLOWED_SAVE_COOKIE ?>",
<?php if (!empty($orderTrackingData)): ?>
"ordersTrackingData": <?= /* @escapeNotVerified */ json_encode($orderTrackingData) ?>,
<?php else: ?>
"ordersTrackingData": false,
<?php endif; ?>
"pageTrackingData": <?= /* @escapeNotVerified */ json_encode($block->getPageTrackingData($accountId)) ?>
}
}
}
</script>
<!-- END GOOGLE ANALYTICS CODE -->
Hi @alexhadley. Thank you for your report.
The issue has been fixed in magento/magento2#15765 by @torhoehn in 2.2-develop branch
Related commit(s):
The fix will be available with the upcoming 2.2.6 release.
Hi @alexhadley. Thank you for your report.
The issue has been fixed in magento/magento2#15847 by @torhoehn in 2.3-develop branch
Related commit(s):
The fix will be available with the upcoming 2.3.0 release.
Most helpful comment
I think that fix is not fully right because config.ordersTrackingData on the Success page is an object, so we can't check the 'length' property for this