Skip to content

Google analytics pageview being triggered twice #12221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
alexhadley opened this issue Nov 13, 2017 · 14 comments
Closed

Google analytics pageview being triggered twice #12221

alexhadley opened this issue Nov 13, 2017 · 14 comments
Assignees
Labels
Fixed in 2.2.x The issue has been fixed in 2.2 release line Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release

Comments

@alexhadley
Copy link

Preconditions

  1. Set Analytics code in admin
  2. Load any page

Steps to reproduce

  1. None

Expected result

  1. pageview is triggered once

Actual result

  1. pageview is triggered twice

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');`
@magento-engcom-team magento-engcom-team added the Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed label Nov 13, 2017
@KarlComSe
Copy link

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.

@alexhadley
Copy link
Author

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.

@KarlComSe
Copy link

@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.

@magento-engcom-team magento-engcom-team added Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed 2.2.x Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release labels Nov 20, 2017
@magento-engcom-team
Copy link
Contributor

@alexhadley, thank you for your report.
We've created internal ticket(s) MAGETWO-84155 to track progress on the issue.

@cball87
Copy link

cball87 commented Jan 3, 2018

@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.

@bhargavmehta
Copy link
Member

Working on fixing this issue #MM18IN

@magento-engcom-team
Copy link
Contributor

@bhargavmehta thank you for joining. Please accept team invitation here and self-assign the issue.

@magento-team
Copy link
Contributor

Hi @alexhadley. Thank you for your report.
The issue has been fixed in #13034 by @bhargavmehta in 2.2-develop branch
Related commit(s):

The fix will be available with the upcoming patch release.

magento-team pushed a commit that referenced this issue Jan 11, 2018
…geview Triggered twice #13034

 - Merge Pull Request #13034 from bhargavmehta/magento2:2.2-dev-fix
 - Merged commits:
   1. 149d08f
   2. e851948
magento-team pushed a commit that referenced this issue Jan 11, 2018
@magento-engcom-team
Copy link
Contributor

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.

@magento-engcom-team magento-engcom-team added the Fixed in 2.3.x The issue has been fixed in 2.3 release line label Feb 6, 2018
@ravinsky
Copy link

ravinsky commented Feb 9, 2018

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

@paddy194
Copy link

Conversion doesnt work here too. Ravinsky is right I guess.

@mokadev
Copy link

mokadev commented May 18, 2018

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

@magento-engcom-team
Copy link
Contributor

Hi @alexhadley. Thank you for your report.
The issue has been fixed in #15765 by @torhoehn in 2.2-develop branch
Related commit(s):

The fix will be available with the upcoming 2.2.6 release.

@magento-engcom-team
Copy link
Contributor

Hi @alexhadley. Thank you for your report.
The issue has been fixed in #15847 by @torhoehn in 2.3-develop branch
Related commit(s):

The fix will be available with the upcoming 2.3.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fixed in 2.2.x The issue has been fixed in 2.2 release line Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release
Projects
None yet
Development

No branches or pull requests

10 participants