Hi checkout script first_time_accessed condition not return the order number. getting null

Hi i am tracking the conversions tracking code in checkout script page.

hoverever now i am getting the order number undefined when i am move out the code from the first_time_access it was the working fine.

{% if first_time_accessed %}

   (['trackEvent', 'purchase: { 
order_id : {{ order.order_number }}
}']);
{% endif %}

Hi @1080
Can you kindly share your store link (with the password, if any) with us? We will check it and suggest you a solution if possible.

1 Like

@BSS-Commerce

Thanks for the replay
https://sanjay-test-shop.myshopify.com/
store prewview password : stinow

i am to load the gtm script and push the data to gtm

now i want send the data.

but
i was not able to get the all the data like {{order.number}}

i need to get the all the order detail and sent to the GTM.

I hope this information batter to understand my questions.

The {{order.order_number}} object will sometimes be null depending on payment provider used. It is not reliable; don’t use it. See the order_number object description: https://shopify.dev/docs/api/liquid/objects/checkout

Instead, you should use “id” if you are just needing a unique number attached to the order.

{% if first_time_accessed %}

   (['trackEvent', 'purchase: { 
order_id : {{ order.id }}
}']);
{% endif %}

If you actually do need the order number, I’m not aware of any way to get it other than to use a webhook.

Hope that helps!

2 Likes

@mthdvd Thanks for the answers Yes it was happen few of the case. I tested with test payment with bogus payment gateway it was work almost some of the case i am getting

{{ order.order_number }}

but this is happens with the production payment gateway.

@mthdvd as per this Shopify liquid documents.

https://shopify.dev/docs/api/liquid/objects/order#order-order_number

they mention order_number

do you have any idea why some store is not working?

@BSS-Commerce I shared the Store link please check if you can help.

@1080 , again – this is the expected behavior as far as I know. It will load some of the time, but not all the time.

1 Like

@mthdvd can you suggestion working solution if you can., that was really help me.