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

Prevent duplicate conversion and purchase event tracking #2734

Merged
merged 4 commits into from
Dec 18, 2024

Conversation

mikkamp
Copy link
Contributor

@mikkamp mikkamp commented Dec 17, 2024

Changes proposed in this Pull Request:

Because of a strict comparison check for the _gla_tracked meta we were allowing the conversion and purchase snippets to show again if the order thank you page is refreshed (not loaded from cache).

This PR converts the meta value to an integer before doing the strict comparison. I've also added some unit tests to confirm that the tracking snippet isn't output in conditions where it should not. The WP proxy class had to be used to facilitate mocking of some WP functions.

Closes #2733

Detailed test instructions:

  1. Setup your site fully onboarded with an Ads account to enable tracking.
  2. Go through the checkout flow in an anonymous browser window until you reach the order thank you page
  3. Check the page source and confirm it has two inline snippets
    1. Starting with gtag("event", "conversion"
    2. Starting with gtag("event", "purchase"
  4. Hard refresh the page
  5. Check the page source and confirm this time the snippets are no longer included

Changelog entry

  • Fix - Prevent duplicate conversion and purchase event tracking.

@mikkamp mikkamp self-assigned this Dec 17, 2024
@github-actions github-actions bot added type: bug The issue is a confirmed bug. changelog: fix Took care of something that wasn't working. labels Dec 17, 2024
@mikkamp mikkamp requested a review from a team December 17, 2024 17:24
Copy link

codecov bot commented Dec 17, 2024

Codecov Report

Attention: Patch coverage is 25.00000% with 6 lines in your changes missing coverage. Please review.

Project coverage is 67.0%. Comparing base (79fcca7) to head (c43a34d).
Report is 10 commits behind head on develop.

Files with missing lines Patch % Lines
src/Proxies/WP.php 0.0% 4 Missing ⚠️
src/Google/GlobalSiteTag.php 50.0% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             develop   #2734     +/-   ##
===========================================
+ Coverage       66.6%   67.0%   +0.4%     
- Complexity      4691    4693      +2     
===========================================
  Files            479     479             
  Lines          19608   19612      +4     
===========================================
+ Hits           13064   13136     +72     
+ Misses          6544    6476     -68     
Flag Coverage Δ
php-unit-tests 67.0% <25.0%> (+0.4%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/Google/GlobalSiteTag.php 25.6% <50.0%> (+25.6%) ⬆️
src/Proxies/WP.php 23.2% <0.0%> (-1.8%) ⬇️

Copy link
Member

@eason9487 eason9487 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing the issue quickly!

Confirmed that gtag snippets won't be included in the order thank you page after an order is marked as tracked. LGTM.

tests/Unit/Google/GlobalSiteTagTest.php Outdated Show resolved Hide resolved
@mikkamp mikkamp merged commit 03a3290 into develop Dec 18, 2024
12 checks passed
@mikkamp mikkamp deleted the fix/2733-prevent-duplicate-purchase-event-tracking branch December 18, 2024 07:32
@eason9487 eason9487 mentioned this pull request Dec 18, 2024
22 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: fix Took care of something that wasn't working. type: bug The issue is a confirmed bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Duplicate reporting due to incorrect meta value comparison
2 participants