Google Tag Manager and dataLayer Events for WooCommerce

Last updated

Revenue First Analytics pushes page views, product views, add to cart, begin checkout and purchase events to window.dataLayer on every site where tracking is enabled; there is no setting to turn on. The pushes use a flat payload with an items array for checkout and purchase, so you can build Google Tag Manager triggers and GA4 e-commerce tags on them. The plugin itself never sends anything to Google.

Think of it as a mirror. Everything the plugin records for its own reports is also announced on the page, and your Google Tag Manager container decides what to do with it. If you do not use Tag Manager or GA4, you can ignore this page; the pushes are harmless and cost nothing.

Which events are pushed to the dataLayer?

eventWhen it firesKeys in the push
rfa_page_viewEvery pageview, including single-page navigationpage_path, page_referrer; utm_source, utm_medium, utm_campaign on the first pageview of a visit with UTM parameters
view_itemA WooCommerce single product page loadsproduct_id
view_item_listA WooCommerce product category or tag page loadscategory_id or tag_id
add_to_cartA product is added through WooCommerce’s classic AJAX add-to-cart button, or through the EDD AJAX cartproduct_id, product_name, quantity, price, source: "rfa"
begin_checkoutThe checkout page opens with items in the cart, once per sessioncart_total, item_count, currency, items, source: "rfa"
purchaseThe WooCommerce thank-you page or EDD receipt page, once per orderorder_id, total, currency, tax, shipping, item_count, items, source: "rfa"
rfa_Any custom event: window.rfa('signup_click') becomes rfa_signup_click, a data-rfa-goal click uses its goal name, scroll depth sends rfa_scroll_25 to rfa_scroll_100 with depth, and data-rfa-scroll-goal sends rfa_scroll_goal with labelThe data you passed to window.rfa()

Each entry in items has item_id, item_name, quantity and price. After the visitor has given statistics consent (or in Full tracking), every push from the tracker also carries rfa_visitor_id, the value of the _rfa_vid cookie; before consent that key is absent. The source: "rfa" key on the e-commerce pushes lets you tell them apart from pushes made by other plugins.

Custom events and goals are described in Tracking Button Clicks and Custom Events and Creating Goals.

On which pages do the pushes happen?

  • Page, product and custom events are pushed by the tracker script on the page where they happen, at the moment they happen.
  • add_to_cart is pushed by a small inline listener in the footer that reacts to WooCommerce’s added_to_cart jQuery event or EDD’s edd_cart_item_added event. Add-to-cart actions that do not fire those events (the WooCommerce block cart, a plain form submit that reloads the page) are recorded in your reports but are not pushed to the dataLayer.
  • begin_checkout and purchase are generated on the server and printed as an inline script in the footer of the checkout page and the thank-you or receipt page. A purchase is pushed once per order; refreshing the thank-you page does not push it again.

Is the payload in GA4 e-commerce format?

Not exactly. GA4’s recommended format wraps everything in an ecommerce object and uses value and transaction_id. The plugin pushes flat keys named total and order_id instead, while the items entries already use GA4’s item parameter names. A purchase push looks like this:

window.dataLayer.push({
  "event": "purchase",
  "order_id": "1842",
  "total": 79.9,
  "currency": "EUR",
  "tax": 13.32,
  "shipping": 4.9,
  "item_count": 2,
  "items": [
    { "item_id": "311", "item_name": "Linen shirt", "quantity": 1, "price": 59 },
    { "item_id": "87",  "item_name": "Gift wrap",   "quantity": 1, "price": 16 }
  ],
  "source": "rfa"
});

Because the keys are flat, you map them to GA4 parameters in Tag Manager rather than reading ecommerce from the data layer. That takes a few extra variables, described next.

Build a GTM trigger and a GA4 purchase tag

  1. In Tag Manager, create four Data Layer Variables named after the keys: order_id, total, currency and items.
  2. Create a Custom Event trigger with the event name purchase. Optionally add the condition source equals rfa so pushes from other plugins do not fire it.
  3. Create a Google Analytics: GA4 Event tag with the event name purchase. Add the event parameters transaction_id = {{order_id}}, value = {{total}}, currency = {{currency}} and items = {{items}}.
  4. Attach the trigger, preview a test order on the thank-you page, then publish the container.

Repeat the pattern for begin_checkout (map cart_total to value) and add_to_cart (build a single-item items array from product_id, product_name, quantity and price with a custom JavaScript variable, or send them as plain parameters). For the plugin’s own pageview push you normally do not need a tag, since GA4 counts page views itself.

Does the plugin send data to Google?

No. The plugin writes objects into window.dataLayer, which is a JavaScript array on the page. It does not load Tag Manager, gtag.js or any Google script, and nothing leaves the visitor’s browser unless your own container sends it. Consent for whatever your tags do is therefore your container’s job: the pushes happen in every tracking mode, including before the visitor has consented, because the push alone transmits nothing. Use GTM’s consent settings to gate your tags, and connect your banner to the plugin as described in Connecting Your Cookie Banner if you want rfa_visitor_id to appear only after consent.

The pushes are skipped for logged-in administrators when Exclude admin users is on, unless Debug mode is also on. For server-side event delivery to Meta instead of Google, see Facebook Conversions API and Pixel for WooCommerce.

How do I see the pushes while testing?

Turn on Debug mode in the Developer Tools card of Settings and open your site’s frontend as an administrator. The debug panel in the bottom-right corner has a dataLayer tab that lists every object currently in window.dataLayer, including the plugin’s pushes and anything your own container added. Tag Manager’s Preview mode shows the same events on its side. If a purchase shows in the panel but your GA4 report stays empty, the gap is in the container, not in the plugin.

Frequently Asked Questions

Do I need to enable the dataLayer integration?
No. The pushes happen whenever tracking is enabled, in every tracking mode. There is no toggle for them, and they do nothing unless a Tag Manager container or your own script reads window.dataLayer.
Does the plugin load Google Tag Manager or GA4 for me?
No. It only writes into window.dataLayer. You add the Tag Manager container or gtag.js yourself, and your tags decide what is sent to Google.
Why is add_to_cart missing when I use the WooCommerce block cart?
The add_to_cart push listens for WooCommerce's classic added_to_cart jQuery event and EDD's edd_cart_item_added event. Block-based and page-reload add-to-cart actions do not fire those events, so they are recorded in your reports but not pushed to the dataLayer.
Why does rfa_visitor_id appear only sometimes?
The key is added only once the visitor is identified: after statistics consent in Consent mode, or always in Full tracking. In Privacy mode and before consent it is never included.
Will a refreshed thank-you page push a second purchase?
No. The plugin marks the order as pushed the first time the thank-you or receipt page renders, so a refresh or a return visit to that page does not repeat it.
Browse our plugins

Lightweight WooCommerce plugins built for speed. No bloat, no frameworks -- just clean code that works.

View all plugins
Stay in the loop

Get notified when we launch new plugins. No spam, just product updates.