Purchase Event DataLayer Injection WordPress Function

On the WooCommerce “Thank You” page, pushes a purchase event into dataLayer with the order number as a string—ready for GTM/GA4 conversion tracking.

19,99 

Request function

View Privacy Policy

Description

Purchase Event DataLayer Injection WordPress Function

What it does?

  • Fires on order completion: Hooks into the thank-you page and safely loads the order.

  • Pushes a clean event: Sends a purchase event to dataLayer with a transactionId equal to the order’s display number (string).

  • Plays nice with custom numbering: Uses the visible order number, so it aligns with any custom order-number scheme you’ve set.

Why it’s useful?

  • Reliable conversion tracking: Ensures GTM/GA4 receives a consistent purchase signal at the exact right moment.

  • Avoids type pitfalls: Stringifying the ID prevents analytics misreads caused by numeric coercion.

  • Works with custom setups: Ideal when you’re rolling your own GTM events or when other plugins are disabled/insufficient.

Notes

If another plugin already pushes a purchase event, disable one to avoid duplicate conversions.