Duplicated Purchase Events

Hi everyone, I keep having customers going back to my order page (thank you page) or refreshing it and it triggers another purchase event, even though I set my GA4 tag to fire once per page, does anyone know how to resolve this? Same for the Facebook purchase tag, would like that to fire only once per user.

Hi Claudio,

Ideally, this should be restricted at the dataLayer push level, so that it is only triggered once for a specific order id for example.

But if you don’t have that option, you can reduce the number of duplicate purchases as follows:

  • Using Data Tag (available in GTM gallery) at Purchase event, save order ID in user’s cookie (there is a save function).

  • Use Data Variable (also available in the gallery) to retrieve the saved order ID from cookie/local storage.

  • Use custom JS variable to check if order id from cookie is the same as order id from dataLayer push
    For example like this:

function(){
  if ({{DV - order_id}} === {{DLV - orderId}}) {
    return true;
  }
  else {
    return false
  }
}
  • Add an additional check to the purchase trigger on custom JS so that it only triggers if false.

But unfortunately this won’t work if the user has made a purchase on one device and re-entered the page from another device.

Thanks @Alex that definitely solves the problem! Just out of curiosity, and it might be helpful for other people here in the community, how would you restrict that at the dataLayer push level?
This is what I have:

It depends on what you have inside (order_summary). If you send me a screenshot from GTM preview with dataLayer on purchase event I might be able to suggest it.

So I think I found a solution that works well for what I needed, customers reloading the thank you page or navigating back to it via the back button resulted in duplicated purchase events.
First create a Custom JS variable that outputs the value of navigation true if it’s the first time the user navigates to that page


Then apply a condition on your purchase event to only fire if the variable = true
No more duplicated purchases because of page reloads.
However this will not solve all problems, for example if the user copies the url and pastes it on another browser window, for that the cookie solution given by Alex would work better, but for some reason I couldn’t set that up properly.

Hey Claudio,

Listening for ‘first visit’ is the best idea here, that concept ideally should be applied in code-base where that dataLayer is pushed. I don’t think customer copying ty-page URL is a very common occurrence.

You can always use what Alex has suggested though, the only thing it would not cover is cross-device but that’s the edgiest of cases I believe :slight_smile: