Multiple "checkout_completed" events for same order

Multiple "checkout_completed" events for same order

strothj
Visitor
1 0 2

Hello,

 

We have a "Customer event" that is subscribed to the analytics "checkout_completed" event. For most purchases, things work as expected. A certain percentage of checkouts have a second event that is triggered for the same checkout a few hours later.

 

We're seeing the same issue occur with an "Additional script" attached to the "Order status page". The additional script is wrapped with "{% if first_time_accessed %}". Just like the above event, this one operated correctly for most checkout but occasionally the script is triggered twice, with a similar delay as the custom event.

 

Is this expected behavior or is there something about the setup I missed?

Replies 6 (6)

wb1
Shopify Partner
62 2 16

I'm wondering the same, is there an equivalent to {{ first_time_accessed }} in the new customer events pixels. My testing showed me that liquid is not usable in the new customer events pixels.

khalid1214
Shopify Partner
19 2 1

Hey @wb1 , did you find any equivalent to {{ first_time_accessed }} liquid variable to be used in the new Customer Events? Thanks.

Shopify Freelance Developer with 5 years of experience in Liquid, HTML/CSS, and JavaScript/JQuery and building Shopify stores.
https://www.upwork.com/freelancers/khalidbashir

Dave232
Shopify Staff
2 0 1

Hi, is there a shop I could look at? With web pixels, the checkout_completed event should only fire once on the /thankyou page. A buyer can sometimes re-trigger it but it is rare. With additional scripts, if it is wrapped with "{%if first_time_accessed%}", it shouldn't re-fire but it can in some rare cases. I'll have a look at your shop if that's helpful.

Dave | Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution

Luuk_HH
Visitor
2 0 1

Hi Dave,

 

We are experiencing the same problem. I have subscribed to the checkout_completed event in the customer events with a custom pixel. The function that is subscribed to the checkout_completed event pushes an event to the dataLayer that is used for Google Tag Manager to track conversions. We notice that some conversions are being tracked twice. The information is also pushed to the dataLayer twice, meaning that it isn't a faulty setup in Google Tag Manager, but actually the checkout_completed event that is fired twice. The shop I'm working on is a client of us, their shop is Aligma.nl. It would be great if you could have a look at this.

 

There is something strange with this problem. To debug this issue I've declared an empty array at the start of the custom pixel which I'm using to add transactionIds to. If the checkout_completed event is fired for the first time, we check whether the transation ID is already in the array. If it isn't, all good, push the data to the datalayer. If the transaction ID is already in the array, then don't push events to the datalayer but log a few lines to indicate that this transaction was already pushed to the datalayer.

 

The transactionIds array is declared at start of the custom pixel code:

Luuk_HH_1-1704785412019.png

 

 

On the checkout_completed event I'm logging two lines almost directly at the start of the function (lines 158 & 159):

Luuk_HH_0-1704785236261.png

 

Then, depending on whether the conversion was already tracked, we either log to the console that it was a duplicate or push two events (enhanced_conversion_data and purchase) to the dataLayer used for Google Tag Manager to fire it's tags. After this is done, we push the current transaction ID to the transactionIds array so that if the function runs again for the same transaction, we can prevent the datalayer pushes from being fired again because this would cause duplicate conversion measurement.

Luuk_HH_2-1704785504493.png

 

Now the strange thing is that when making a purchase, I can see that the dataLayer contains 2 purchase events, meaning that the checkout_completed callback ran twice.

Luuk_HH_0-1704791426323.png

 

However, the strange this is that the log lines (lines 158 & 159 of the custom pixel) only show up once in the console. The current transaction ID log line shows correctly and then the "Transaction IDs at the start of checkout_completed" shows up correctly as well and it includes an empty array (so this means it's the first time this function runs, because the transactionIds array is still empty).

 

For some reason part of the code is ran once (the 2 log lines) but another part of the code (the dataLayer pushes) is fired twice.

 

I'd be grateful if you have a chance to dive into this issue.

 

Best,

Luuk

lynth
Shopify Partner
107 5 14

Could you share your GTM implementation and checkout_completed logic? Here is mine:

window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }

(function (w, d, s, l, i) {
  w[l] = w[l] || []; w[l].push({
    'gtm.start':
      new Date().getTime(), event: 'gtm.js'
  }); var f = d.getElementsByTagName(s)[0],
    j = d.createElement(s), dl = l != 'dataLayer' ? '&l=' + l : ''; j.async = true; j.src='https://www.googletagmanager.com/gtm.js?id=' + i + dl; f.parentNode.insertBefore(j, f);
})(window, document, 'script', 'dataLayer', 'GTM-xxxxxxx');


analytics.subscribe("checkout_completed", (event) => {
  console.log("test");
});

It doesn't work. Maybe you know what is wrong. It's inside the customer events code field. It looks like there is no even GTM tag in the source code. 

If my tips are useful, just mark it as the solution. Cheers!
Feeling grateful? Buy me a coffee!