woocommerce / woocommerce-blocks

(Deprecated) This plugin has been merged into woocommerce/woocommerce
https://wordpress.org/plugins/woo-gutenberg-products-block/
GNU General Public License v3.0
404 stars 218 forks source link

Google Analytics tag added twice and prevents page view events from being tracked #7659

Closed CarvinMarvin closed 1 year ago

CarvinMarvin commented 1 year ago

woocommerce-blocks/src/Domain/Services/GoogleAnalytics.php seems to cause the following problem: When the tracking is enabled by a setting of the woocommerce-google-analytics-integration plugin, then this code inserts a Google Analytics Tag with "send_page_view" set to false. The problem with this is that the woocommerce-google-analytics-integration plugin itself also inserts a Google Analytics tag. As a result two tags are inserted in a page which also results in a warning by the Google Tags Assistant Chrome extension. Furthermore because "send_page_view" is set to false, no page view events are sent to GA.

Several people have reported these problems on the support page of the woocommerce-google-analytics-integration plugin, but I think this is something that needs to be fixed in woocommerce-blocks. Some links or people reporting the problem: https://wordpress.org/support/topic/how-to-enable-page-views/ https://wordpress.org/support/topic/ga4-google-tag-manager-gtag-js-showing-twice/#post-16188268

senadir commented 1 year ago

Thank you for reaching out, we made sure not to load the script twice, I will look into it.

senadir commented 1 year ago

I cannot reproduce this running latest WooCommerce Blocks and Google Analytics 1.5.17 How can I see when 2 files are loaded?

I can see that page view is disabled indeed.

kmanijak commented 1 year ago

Hi @CarvinMarvin, I’m going to close this because there still isn’t anything actionable for us on this issue. If/when you have additional details, you can still add them to this issue and if we’re able to reproduce, we can re-open as necessary.

RomanMinkin commented 1 year ago

For those experiencing the issue it seems like it's due the setting ga_event_tracking_enabled being enabled and gets picked up in woocommerce-blocks -> GoogleAnalytics.php, which does not look like it can be controlled with WooCommerce Google Analytics Integration plugin interface.

Disabling the setting with wp-cli solves the issue with double tagging and WP will load only one tag from WooCommerce Google Analytics Integration:

$ wp option patch update woocommerce_google_analytics_settings ga_event_tracking_enabled no
mbkook commented 1 year ago

Also seeing and experiencing this issue. Surprised to see so many Wordpress forum threads on the same thing, but it still hasn't been solved.

The fix as @RomanMinkin suggested works. You can alternatively add some code to your functions.php file:

/** 
 * Fix bug in woocommerce GA4 tracking, causing duplicate gtag embed and disabled page view event
 * Bug source: woocommerce\packages\woocommerce-blocks\src\Domain\Services\GoogleAnalytics.php
 */
$woo_ga_settings = get_option('woocommerce_google_analytics_settings');
if ($woo_ga_settings && $woo_ga_settings['ga_event_tracking_enabled'] == 'yes') {
    $woo_ga_settings['ga_event_tracking_enabled'] = 'no';
    update_option('woocommerce_google_analytics_settings', $woo_ga_settings);
}
przemek-pl commented 1 year ago

I can confirm - this issue still persists when using:

Adding snippet from @mbkook resolved the issue. Bug should be fixed either in WC or proper UI should be added to WooCommerce Google Analytics Integration, so the user can control _ga_event_trackingenabled setting

Aljullu commented 1 year ago

Hey there, I was trying to debug this issue, but hasn't been able to reproduce it yet. Given the number of requests, I will reopen it, but in order to make progress, we might need some assistance from folks who are experimenting it:

  1. Can you please show which settings you have enabled/disabled in WooCommerce > Settings > Integration > Google Analytics? (If you share a screenshot, make sure to cover any private data like Google Analytics Tracking ID)
  2. Can you list any other plugins you have? If there is any that you think might be interfering with GA, can you try disabling it to see if it makes any difference?

Thanks in advance!

mbkook commented 1 year ago

Steps to reproduce

Second embed of GTAG

Aljullu commented 1 year ago

Thanks for the new testing steps, @mbkook! I followed them precisely but haven't been able to reproduce yet, unfortunately. For some reason, I can only see the first snippet.

I have asked another person from the team to take a second look.

Go to the home page

Which page do you have as the home page? You can find it from Settings > Reading > Your homepage displays.

opr commented 1 year ago

Hi, jumping in to say the same, I do not see the second snippet you shared. I see the first one and page_view: false is there.

Could you please provide us with a Site Status Report by going to WooCommerce > Status and click the “Get system report” button then paste the results here?

Thanks!

mbkook commented 1 year ago

Regarding the home page, the same snippets appear on every page, so that likely isn't a relevant detail.

Note that it seems the second snippet will not appear if you are logged into Wordpress admin (e.g. you see the admin top bar when browsing the front end). You need to log out/use a private window.

### WordPress Environment ###

WordPress address (URL): https://xxxxxxxx.com
Site address (URL): https://xxxxxxxx.com
WC Version: 7.4.0
REST API Version: ✔ 7.4.0
WC Blocks Version: ✔ 9.4.3
Action Scheduler Version: ✔ 3.5.4
Log Directory Writable: ✔
WP Version: 6.1.1
WP Multisite: –
WP Memory Limit: 640 MB
WP Debug Mode: –
WP Cron: ✔
Language: en_US
External object cache: –

### Server Environment ###

Server Info: Apache
PHP Version: 8.0.28
PHP Post Max Size: 80 MB
PHP Time Limit: 30
PHP Max Input Vars: 1000
cURL Version: 7.88.0
OpenSSL/1.1.1t

SUHOSIN Installed: –
MySQL Version: 5.7.41
Max Upload Size: 80 MB
Default Timezone is UTC: ✔
fsockopen/cURL: ✔
SoapClient: ✔
DOMDocument: ✔
GZip: ✔
Multibyte String: ✔
Remote Post: ✔
Remote Get: ✔

### Database ###

WC Database Version: 7.4.0
WC Database Prefix: 4a383M_
Total Database Size: 3.64MB
Database Data Size: 2.20MB
Database Index Size: 1.44MB
4a383M_woocommerce_sessions: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
4a383M_woocommerce_api_keys: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
4a383M_woocommerce_attribute_taxonomies: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
4a383M_woocommerce_downloadable_product_permissions: Data: 0.02MB + Index: 0.06MB + Engine InnoDB
4a383M_woocommerce_order_items: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
4a383M_woocommerce_order_itemmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
4a383M_woocommerce_tax_rates: Data: 0.02MB + Index: 0.06MB + Engine InnoDB
4a383M_woocommerce_tax_rate_locations: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
4a383M_woocommerce_shipping_zones: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
4a383M_woocommerce_shipping_zone_locations: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
4a383M_woocommerce_shipping_zone_methods: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
4a383M_woocommerce_payment_tokens: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
4a383M_woocommerce_payment_tokenmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
4a383M_woocommerce_log: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
4a383M_actionscheduler_actions: Data: 0.02MB + Index: 0.11MB + Engine InnoDB
4a383M_actionscheduler_claims: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
4a383M_actionscheduler_groups: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
4a383M_actionscheduler_logs: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
4a383M_commentmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
4a383M_comments: Data: 0.02MB + Index: 0.09MB + Engine InnoDB
4a383M_links: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
4a383M_options: Data: 1.30MB + Index: 0.03MB + Engine InnoDB
4a383M_postmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
4a383M_posts: Data: 0.02MB + Index: 0.06MB + Engine InnoDB
4a383M_termmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
4a383M_terms: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
4a383M_term_relationships: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
4a383M_term_taxonomy: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
4a383M_usermeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
4a383M_users: Data: 0.02MB + Index: 0.05MB + Engine InnoDB
4a383M_wc_admin_notes: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
4a383M_wc_admin_note_actions: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
4a383M_wc_category_lookup: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
4a383M_wc_customer_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
4a383M_wc_download_log: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
4a383M_wc_order_coupon_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
4a383M_wc_order_product_lookup: Data: 0.02MB + Index: 0.06MB + Engine InnoDB
4a383M_wc_order_stats: Data: 0.02MB + Index: 0.05MB + Engine InnoDB
4a383M_wc_order_tax_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
4a383M_wc_product_attributes_lookup: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
4a383M_wc_product_download_directories: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
4a383M_wc_product_meta_lookup: Data: 0.02MB + Index: 0.09MB + Engine InnoDB
4a383M_wc_rate_limits: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
4a383M_wc_reserved_stock: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
4a383M_wc_tax_rate_classes: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
4a383M_wc_webhooks: Data: 0.02MB + Index: 0.02MB + Engine InnoDB

### Post Type Counts ###

attachment: 1
page: 7
post: 2

### Security ###

Secure connection (HTTPS): ✔
Hide errors from visitors: ✔

### Active Plugins (2) ###

WooCommerce Google Analytics Integration: by WooCommerce – 1.6.0
WooCommerce: by Automattic – 7.4.0

### Inactive Plugins (2) ###

Akismet Anti-Spam: by Automattic – 5.0.1
Hello Dolly: by Matt Mullenweg – 1.7.2

### Settings ###

API Enabled: –
Force SSL: –
Currency: USD ($)
Currency Position: left
Thousand Separator: ,
Decimal Separator: .
Number of Decimals: 2
Taxonomies: Product Types: external (external)
grouped (grouped)
simple (simple)
variable (variable)

Taxonomies: Product Visibility: exclude-from-catalog (exclude-from-catalog)
exclude-from-search (exclude-from-search)
featured (featured)
outofstock (outofstock)
rated-1 (rated-1)
rated-2 (rated-2)
rated-3 (rated-3)
rated-4 (rated-4)
rated-5 (rated-5)

Connected to WooCommerce.com: –
Enforce Approved Product Download Directories: ✔
Order datastore: WC_Order_Data_Store_CPT

### WC Pages ###

Shop base: #5 - /?page_id=5
Cart: #6 - /?page_id=6
Checkout: #7 - /?page_id=7
My account: #8 - /?page_id=8
Terms and conditions: ❌ Page not set

### Theme ###

Name: Twenty Twenty-Three
Version: 1.0
Author URL: https://wordpress.org
Child Theme: ❌ – If you are modifying WooCommerce on a parent theme that you did not build personally we recommend using a child theme. See: How to create a child theme
WooCommerce Support: ✔

### Templates ###

Overrides: –

### Admin ###

Enabled Features: activity-panels
analytics
coupons
customer-effort-score-tracks
import-products-task
experimental-fashion-sample-products
shipping-smart-defaults
shipping-setting-tour
homescreen
marketing
multichannel-marketing
mobile-app-banner
navigation
new-product-management-experience
onboarding
onboarding-tasks
remote-inbox-notifications
remote-free-extensions
payment-gateway-suggestions
shipping-label-banner
subscriptions
store-alerts
transient-notices
woo-mobile-welcome
wc-pay-promotion
wc-pay-welcome-page

Disabled Features: minified-js
product-variation-management
settings

Daily Cron: ✔ Next scheduled: 2023-02-14 23:40:03 +00:00
Options: ✔
Notes: 2
Onboarding: -

### Action Scheduler ###

Pending: 3
Oldest: 2023-02-14 23:41:05 +0000
Newest: 2023-02-19 23:21:40 +0000

### Status report information ###

Generated at: 2023-02-19 23:22:27 +00:00
albarin commented 1 year ago

Note that it seems the second snippet will not appear if you are logged into Wordpress admin (e.g. you see the admin top bar when browsing the front end). You need to log out/use a private window.

Thanks, I was able to reproduce the issue after logging out.

For those experiencing the issue it seems like it's due the setting ga_event_tracking_enabled being enabled and gets picked up in woocommerce-blocks -> GoogleAnalytics.php, which does not look like it can be controlled with WooCommerce Google Analytics Integration plugin interface.

The setting can be controlled from the WooCommerce Google Analytics Integration plugins, it is called Add to Cart Events (https://github.com/woocommerce/woocommerce-google-analytics-integration/blob/trunk/includes/class-wc-google-analytics.php#L229-L230)

ralucaStan commented 1 year ago

Closing as the bug was fixed on the extension's side in this PR https://github.com/woocommerce/woocommerce-google-analytics-integration/pull/260.

Thank you to everybody involved in this ticket.