Description
Fixed critical Google Analytics purchase tracking issues. The previous implementation was causing GTM routing failures that prevented conversions from reaching Google Ads correctly.
Key Changes
-
Fixed GTM/Google Ads Routing: Refactored
gaService.tsto separate event handling and event pushed to dataLayer for GTM triggers, and directgtag()call with explicitsend_toarray to guarantee delivery to both Analytics and Google Ads endpoints -
Refactored Purchase Event Tracking: Added dedicated logic for purchase events across services with clear separation of concerns
-
Prevented Duplicate Events: Added useRef check in CheckoutSuccessView component and data validation in gaService to prevent double execution from React StrictMode
-
Maintained useEffect Approach: Kept
useEffectinCheckoutViewas alternative approaches didn't work consistently -
Updated Tests: Comprehensive test coverage for all changes
Related Issues
Related Pull Requests
Checklist
- Changes have been tested locally.
- Unit tests have been written or updated as necessary.
- The code adheres to the repository's coding standards.
- Relevant documentation has been added or updated.
- No new warnings or errors have been introduced.
- SonarCloud issues have been reviewed and addressed.
- QA Passed
Testing Process
Additional Notes
Need a new Env.variable