Skip to content
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

Enhanced Google Analytics 4 Integration and Ecommerce Tracking Improvements #3305

Merged
merged 21 commits into from
Jun 14, 2023
Merged

Enhanced Google Analytics 4 Integration and Ecommerce Tracking Improvements #3305

merged 21 commits into from
Jun 14, 2023

Conversation

empiricompany
Copy link
Contributor

Description (*)

Improve Google Analytics 4 integration and ecommerce tracking
PS: Apologies for not splitting into single issues/PRs for better comparison/readability. I've had to refactor multiple parts and am short on time.

New Features

  • add debug mode to view real time events in analytics (only for developer ip)
  • add user_id tracking

Fixed Issues

  • follow guidelines for item_* props names from GA4 Events Reference
  • remove unnecessary generic item_list_name
  • fix begin_checkout events firing twice on order success page
  • add index position in view_item_list
  • added product category and removed some unecessary generics
  • fix missing price value for some events
  • fix missing sku value if is not set as "used_in_product_listing"
  • wrap tracking in its own function like Universal Analytics
  • add support for firecheckout to event purchase

Manual testing scenarios (*)

  1. Set Analytics 4 mode and measurement ID
  2. Enable debug mode and view real-time events in GA4; events are also written in googleanalytics4.log (add your IP as a developer)
  3. Enable user_id tracking, log in to frontend, and verify that it is set correctly with customer_id

Questions or comments

  • Is it safe and in compliance with GA4 guidelines to send a customer ID as user_id?
  • If the manufacturer attribute is not set to "used_in_product_listing", the value is empty. We haven't fixed this for performance reasons, but maybe we can add some info like "To track item_brand, set the manufacturer to 'used_in_product_listing'"?
  • For the manufacturer, we can add a configuration to select another attribute
  • For performance reasons, we've added the category only if it's "ready" without other loaders

We have tested it at some production sites, and it's working correctly for us as is.

@github-actions github-actions bot added Component: GoogleAnalytics Relates to Mage_GoogleAnalytics Template : base Relates to base template labels Jun 6, 2023
@fballiano fballiano changed the base branch from next to main June 6, 2023 11:14
@fballiano fballiano changed the base branch from main to next June 6, 2023 11:14
@fballiano
Copy link
Contributor

fballiano commented Jun 6, 2023

rebasing on main doesn't work but we've to do it :-)

PS: thanks for this great new additions!

@fballiano fballiano changed the base branch from next to main June 7, 2023 08:08
@github-actions github-actions bot added Component: Adminhtml Relates to Mage_Adminhtml Component: Catalog Relates to Mage_Catalog Component: CatalogSearch Relates to Mage_CatalogSearch Component: Checkout Relates to Mage_Checkout Component: Contacts Relates to Mage_Contacts Component: Core Relates to Mage_Core Component: Customer Relates to Mage_Customer Component: lib/Varien Relates to lib/Varien Component: lib/* Relates to lib/* Component: Newsletter Relates to Mage_Newsletter Component: Oauth Relates to Mage_Oauth Component: Page Relates to Mage_Page labels Jun 7, 2023
@empiricompany
Copy link
Contributor Author

empiricompany commented Jun 12, 2023

someone is a ga4 expert? seems we can't get products revenue by categories, always show category "others" in explore reports or in looker studio, maybe we have to pass the item_category in the purchase events. we have skipped adding it like in universal for performance reason and because we thought that ga4 was able to aggregate the data with item_view and item_view_list where we pass item_category, i dont know if is one of millions of bugs affected by ga4 or it's normal, but if is an important data i can add it. in the future we want to implement caching for item_view and item_view_list events and include all data like item_category1-2-3-4 and manufacturer (if not is used_in_product_listing)

@empiricompany
Copy link
Contributor Author

someone is a ga4 expert? seems we can't get products revenue by categories, always show category "others" in explore reports or in looker studio, maybe we have to pass the item_category in the purchase events. we have skipped adding it like in universal for performance reason and because we thought that ga4 was able to aggregate the data with item_view and item_view_list where we pass item_category, i dont know if is one of millions of bugs affected by ga4 or it's normal, but if is an important data i can add it. in the future we want to implement caching for item_view and item_view_list events and include all data like item_category1-2-3-4 and manufacturer (if not is used_in_product_listing)

also because item_category can be ambiguous, if the product is assigned to multiple categories

@empiricompany
Copy link
Contributor Author

someone is a ga4 expert? seems we can't get products revenue by categories, always show category "others" in explore reports or in looker studio, maybe we have to pass the item_category in the purchase events. we have skipped adding it like in universal for performance reason and because we thought that ga4 was able to aggregate the data with item_view and item_view_list where we pass item_category, i dont know if is one of millions of bugs affected by ga4 or it's normal, but if is an important data i can add it. in the future we want to implement caching for item_view and item_view_list events and include all data like item_category1-2-3-4 and manufacturer (if not is used_in_product_listing)

also because item_category can be ambiguous, if the product is assigned to multiple categories

To have statistics for each event without aggregating data through BigQuery, it is necessary to pass item_category. So, I have implemented it.

fballiano
fballiano previously approved these changes Jun 14, 2023
@fballiano
Copy link
Contributor

we have 1green + 2gray, I'd merge if there's nothing more to change

@fballiano
Copy link
Contributor

nice! I think we're ready for rc5!

@fballiano fballiano merged commit f703211 into OpenMage:main Jun 14, 2023
15 checks passed
@iamniels
Copy link
Contributor

NOTICE: PHP message: PHP Fatal error: Uncaught Error: Call to a member function getLimit() on bool in app/code/core/Mage/GoogleAnalytics/Block/Ga.php:273

$toolbarBlock = Mage::app()->getLayout()->getBlock('product_list_toolbar');
$pageSize = $toolbarBlock->getLimit();

@empiricompany
Copy link
Contributor Author

empiricompany commented Jun 27, 2023

/app/code/core/Mage/GoogleAnalytics/Block/Ga.php:273 contains this line

$result[] = "gtag('event', 'remove_from_cart', " . json_encode($eventData, JSON_THROW_ON_ERROR) . ");";

Please open a separate issue with a detailed information.

@fballiano
Copy link
Contributor

it's probably from the rc5 version but it's impossible to understand

@discountscott
Copy link
Contributor

NOTICE: PHP message: PHP Fatal error: Uncaught Error: Call to a member function getLimit() on bool in app/code/core/Mage/GoogleAnalytics/Block/Ga.php:273

$toolbarBlock = Mage::app()->getLayout()->getBlock('product_list_toolbar');

$pageSize = $toolbarBlock->getLimit();

If you create a new issue for this, tag me on it. Would like a bit more information about the scenario when you received the logged error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: GoogleAnalytics Relates to Mage_GoogleAnalytics Component: PayPal Relates to Mage_Paypal documentation environment JavaScript Relates to js/* Template : base Relates to base template translations Relates to app/locale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants