Skip to content

feat(tracking): push Google Ads conversion data to dataLayer on purchase#28

Merged
paulocastellano merged 2 commits into
mainfrom
feat/google-ads-conversion-tracking
May 12, 2026
Merged

feat(tracking): push Google Ads conversion data to dataLayer on purchase#28
paulocastellano merged 2 commits into
mainfrom
feat/google-ads-conversion-tracking

Conversation

@paulocastellano
Copy link
Copy Markdown
Contributor

Summary

  • Wires Stripe Checkout Session data (value, currency, transaction_id) into the purchase dataLayer event so GTM can fire Google Ads Conversion Tracking (AW-18156274196/Dl3oCNKAvKscEJSEy9FD) with accurate per-plan revenue and deduped transaction IDs.
  • BillingController::checkout now appends {CHECKOUT_SESSION_ID} to the Stripe success_url.
  • BillingController::processing lazily retrieves the Checkout Session (closure prop — polling partial reloads don't re-hit the Stripe API) and exposes a conversion prop with value/currency/transaction_id. Uses data_get with dot notation + type guards so Stripe shape changes degrade to null instead of crashing.
  • Processing.vue forwards conversion to trackPurchase.
  • useTracking.trackPurchase pushes conversion_value, conversion_currency, conversion_transaction_id to dataLayer + PostHog.

GTM setup (manual, after merge)

  1. Create 3 Data Layer Variables: conversion_value, conversion_currency, conversion_transaction_id.
  2. Create a Google Ads Conversion Tracking tag:
    • Conversion ID: 18156274196 (digits only, no AW- prefix)
    • Conversion Label: Dl3oCNKAvKscEJSEy9FD
    • Conversion Value: {{conversion_value}}
    • Transaction ID: {{conversion_transaction_id}}
    • Currency Code: {{conversion_currency}}
  3. Trigger: Custom Event = purchase.

Test plan

  • php artisan test --compact --filter=BillingControllerTest — 20 passed
  • Manual checkout in Stripe test mode → confirm purchase event in GTM Preview with populated conversion_* fields
  • Verify Google Ads Conversion Tracking tag fires once per checkout (dedup via transaction_id)
  • Confirm polling partial reloads on /billing/processing don't trigger duplicate Stripe API calls

Wire `value`, `currency`, and `transaction_id` from Stripe Checkout Session
into the `purchase` dataLayer event so GTM can fire Google Ads Conversion
Tracking with accurate per-plan revenue and deduped transaction IDs.

- `BillingController::checkout` adds `{CHECKOUT_SESSION_ID}` to success_url
- `BillingController::processing` retrieves session lazily (closure prop,
  so polling partial reloads don't re-hit Stripe) and exposes
  `conversion` with `value`/`currency`/`transaction_id`
- `Processing.vue` forwards `conversion` to `trackPurchase`
- `useTracking.trackPurchase` pushes `conversion_value`,
  `conversion_currency`, `conversion_transaction_id` to dataLayer +
  PostHog
…er crashes

`$account->stripe()` can throw `\Stripe\Exception\InvalidArgumentException`
(descends from PHP's `InvalidArgumentException`, not `ApiErrorException`)
when the Stripe key is missing/malformed. Since the conversion data is
purely for tracking, any failure must degrade silently — not break the
post-payment success page.
@paulocastellano paulocastellano merged commit 3a3bdec into main May 12, 2026
2 checks passed
@paulocastellano paulocastellano deleted the feat/google-ads-conversion-tracking branch May 12, 2026 18:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant