Product

Solutions

Resources

Product

Solutions

Resources

GUIDES

How to configure a purchase event in Google Analytics 4 and Google Tag Manager

First of all you need to setup a GA4 and GTM account, sometimes it already exists to make sure you look for gtm.js in the network tab.

Once you have your account we need to visit the official GA4 documentation of standard events. See here: https://developers.google.com/analytics/devguides/collection/ga4/reference/events?client_type=gtm#purchase

The recommended method is utilizing a datalayer and sending instructions to the web developers responsible of the website.

Here's an example of the Purchase event


dataLayer.push({
  event: "purchase",
  ecommerce: {
    transaction_id: "T_12345",
    value: 72.05,
    tax: 3.60,
    shipping: 5.99,
    currency: "USD",
    coupon: "SUMMER_SALE",
    items: [
    {
      item_id: "SKU_12345",
      item_name: "Stan and Friends Tee",
      affiliation: "Google Merchandise Store",
      coupon: "SUMMER_FUN",
      discount: 2.22,
      index: 0,
      item_brand: "Google",
      item_category: "Apparel",
      item_category2: "Adult",
      item_category3: "Shirts",
      item_category4: "Crew",
      item_category5: "Short sleeve",
      item_list_id: "related_products",
      item_list_name: "Related Products",
      item_variant: "green",
      location_id: "ChIJIQBpAG2ahYAR_6128GcTUEo",
      price: 10.01,
      quantity: 3
    }]
  }
});


Go to Google Tag Manager and select a GA4 event tag. Make sure you add the Event parameters and use the datalayer here.



This is an example of how to capture the transaction ID data from the datalayer.
ecommerce.transaction_id



As always, make sure to QA, debug and run tests so that you are confident enough in your implementation.

If there's no proper test environment I usually create a test purchase in the live production website and then cancel the order straightaway.

Do you need support to remember your Google Tag Manager implementation? Don't forget to add it to your measurementplan so that you and your team mates can trust the data.

Outline your tracking

events, right on your website

Try now, it’s free

No credit card required

Desktop only

Outline your tracking

events, right on your website

Try now, it’s free

No credit card required

Desktop only

Outline your tracking events, right on your website

Try now, it’s free

No credit card required

Desktop only