Monday, 1 November 2021

How to use purchase event in google analytics commerce tracking?

I'm trying google analytics measurement in the product checkout process. I've made the steps to checkout step 3, and the checkout status is pending. I'm confused about how to checkout step 4 and the status is done because the payment has been made? I've found a way to do it on the backend that does target the API to google analytics. I got an example from Purchase Event, for the steps and the code below.

Then what I'm confused about and the problem is how to tell google analytics if the transaction want to update is a transaction with transaction id A (for example) not transaction id B? how to specify it so that google analytics knows?

Can anyone can help me to tell step by step?

const measurementId = `G-XXXXXXXXXX`;
const apiSecret = `<secret_value>`;

fetch(`https://www.google-analytics.com/mp/collect?measurement_id=${measurementId}&api_secret=${apiSecret}`, {
  method: "POST",
  body: JSON.stringify({
    "client_id": "client_id",
    "events": [{
      "name": "purchase",
      "params": {
        "currency": "USD",
        "transaction_id": "T_12345",
        "value": 12.21,
        "affiliation": "Google Store",
        "coupon": "SUMMER_FUN",
        "shipping": 3.33,
        "tax": 1.11,
        "items": [
          {
            "item_id": "SKU_12345",
            "item_name": "Stan and Friends Tee",
            "affiliation": "Google Store",
            "coupon": "SUMMER_FUN",
            "currency": "USD",
            "discount": 2.22,
            "index": 5,
            "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": "L_12345",
            "price": 9.99,
            "quantity": 1
          }
        ]
      }
    }]
  })
});


from How to use purchase event in google analytics commerce tracking?

No comments:

Post a Comment