Purchase webhook

Hey!

Due to redirect delays from the payment provider, many users never go back to the shop after payment, so I really need to fill in the blanks with webhook data.

I have some trouble converting the payload claimed by the Data Client into a format that will be properly digested by GA4.

Which tag would you recommend for that purpose? Any tips?

In this case, you can send events directly via the measurement protocol: Measurement Protocol(Google Analytics(分析)4)  |  Google for Developers.

You can do it directly, or you can use sGTM and send events first to sGTM and then from there to GA4 and other platforms. But this makes sense if you want to send it to other platforms as well.

Note that in order for this to work correctly you must have session cookies and user id cookie of the user who made the purchase available in the webhook.

Hi Dawid,

I usually create a custom template to map one event data format to another.

For example I used this function in custom template to map ga4 items to Klaviyo event properties:

const itemsInput = data.itemsArray; // Ensure 'itemsArray' is defined as the input in your template configuration

const klaviyoItems = itemsInput.map(item => {
  // Build an array of categories, filtering out undefined or null values
  const categories = [];
  if (item.item_category) categories.push(item.item_category);
  if (item.item_category2) categories.push(item.item_category2);
  if (item.item_category3) categories.push(item.item_category3);
  if (item.item_category4) categories.push(item.item_category4);
  if (item.item_category5) categories.push(item.item_category5);

  return {
    ProductID: item.item_id,
    SKU: item.item_id,
    ProductName: item.item_name,
    Quantity: item.quantity || 1,
    ItemPrice: item.price,
    RowTotal: item.quantity ? item.quantity * item.price : item.price,
    ProductURL: item.url || '', // Assuming URLs can be directly taken from the item data
    ImageURL: '', // If image URLs are available, they should be handled similarly
    Categories: categories,
    Brand: item.item_brand
  };
});

return klaviyoItems;

You can create a similar template in server GTM using your webhook event data and transforming it into items array.

1 Like

This plugin does not send session number value and that’s my main problem here apparently :sweat_smile: