Personalized checkout and custom promotions with Shopify Scripts
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?
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.
Hey @wb1 , did you find any equivalent to {{ first_time_accessed }} liquid variable to be used in the new Customer Events? Thanks.
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
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:
On the checkout_completed event I'm logging two lines almost directly at the start of the function (lines 158 & 159):
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.
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.
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
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.
Starting a B2B store is a big undertaking that requires careful planning and execution. W...
By JasonH Sep 23, 2024By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024