Explanation of the {{order_number}} value in the checkout script. - For Affiliate Marketing.

MP7
Tourist
3 0 1
I am reaching out to you on behalf of one of our clients using Shopify for their eCommerce Platform. They are utilizing our AvantLink scripts in order to attribute commissions to their Affiliate Marketers.
 
Essentially we are using the following script to pass the necessary information to calculate commission values from Affiliate influenced transactions:

 

<script type="text/javascript">
var _AvantMetrics = _AvantMetrics || [];
_AvantMetrics.push(['order',{ order_id:'{{order_number}}', amount:'{{subtotal_price | money_without_currency}}', state:'{{billing_address.province_code}}', country:'{{billing_address.country_code}}' }]);
{% for line in line_items %}
_AvantMetrics.push(['item',{ order_id:'{{order_number}}', variant_sku:'{{line.product.id}}', price:'{{line.price | money_without_currency}}', qty:'{{line.quantity}}' }]);
{% endfor %}
</script>

 

 
This script has been works well in most cases for all of our Shopify Clients and returns a unique 4 or 5 digit ID from {{order_number}}.  However, the variable we are using sometimes sends us a 15 digit number other than the 4 or 5 digit unique order ID.
In the table below, are 5 transactions from this week that sent us a 15 digit order ID instead of the normal 5 digit ID.
Shopify ID {{order_number}} in array Amount Date Time Payment type
74219#18593199685831$424.001/3/202116:16Shopify Payments Discover
74194#18588183560391$384.001/3/20211:15Shopify Payments Mastercard
74193#18587732574407$424.001/2/202123:33Shopify Payments Mastercard
74153#18585112674503$439.001/2/202114:52Shopify Payments AmEx
74093#18574231666887$145.001/1/20214:09PayPal Express -

Can you give us context on what this 15 digit code is, and why it is sometimes substituted in for the {{order_number}} variable?
Thank you for your assistance
0 Likes
CalD
Shopify Staff
Shopify Staff
136 19 28

Hey @MP7,

It could be related to the fact that when importing orders into Shopify via API, you can specify an order name (i.e. a "name" string when POSTing to https://shopify.dev/docs/admin-api/rest/reference/orders/order#create-2021-04, which can be up to 255 chars long).

I can't seem to find those particular order_numbers to fully validate, however. Could you DM me the specific shop(s) that those came from?

CalD | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

0 Likes
jordann
Shopify Partner
3 0 2

This is also occurring for us, did you find a solution to make it always pass the order id rather than the invoice id?

0 Likes
MP7
Tourist
3 0 1

CalD explained to me:

After some investigation, the behaviour you're seeing is related to deferred order processing in some instances when Shopify's database is under significant load.

When this happens, Shopify momentarily postpones parts of the order creation process in the backend after customers complete checkouts on the online store to allow us to maintain checkout throughput while protecting overall checkout health. Customers will still be able to checkout normally and see the "Thank you" page however the order name (eg. #1001) and things reliant on the order creation will likely be delayed (eg. order confirmation email, order creation webhooks).

What this means for your scenario is that the "checkout_id" may be sent instead of the normal order_number, you can see an example of this key and its value in the order response from the API: https://shopify.dev/docs/admin-api/rest/reference/orders/order, although it's worth mentioning that this checkout_id is a read-only property, and is a non-null number only when the customer completes checkout on the online store (i.e. if an order is created via the Admin API, it will have "checkout_id":null).

Hope that helps!

This was enough of an explanation to explain the scenario.  As far as resolving the issue, Shopify would need to reduce the 'load' on their database.

 

RAd_Tag_Team
Tourist
4 0 1

Wow, I'm glad that I found this thread as we as affiliate network have the exact same problem. We did a lot of debugging and used merchant credentials to investigate orders via the orders API and found out that some orders with a weird hashed prefix order ID were actually tracked with Shopify's checkout.name (https://shopify.dev/docs/themes/liquid/reference/objects/checkout#checkout-name) though we never use this variable in our code.

We use a combination of liquid code in the checkout script section and JavaScript on the confirmation page to fire our conversion pixel and send the order ID back to us.

The liquid code creates a global JavaScript object and populates the client facing order ID:

 

window.ourShopifyObj = {
    orderName: "{{ order_number }}",
    ...
};

 

 The JavaScript on the confirmation page then uses that object to populate and fire the conversion pixel.:

 

var UNDEFINED = '';
var useOrderName = UNDEFINED || true;
var ourShopifyObj = window.ourShopifyObj || {};
var ourTrans = {
    orderid: (useOrderName && ourShopifyObj && ourShopifyObj.orderName) ? ourShopifyObj.orderName : Shopify.checkout.order_id,
...
};

 

As you can see we either use the client facing order ID from ourShopifyObj or (if the merchant doesn't add the additional script to the checkout script section) the internal order ID from Shopify.checkout.order_id. But still in our transaction logs for Shopify clients we occasionally see order IDs with the format #12345678901234. This is the checkout.name as mentioned above which we never use in our code but causing issues as the merchants cannot relate a tracked order ID to their orders.

So is there any solution to this besides waiting for Shopify to fix load issue?

We don't remember having that seen prior and it has only started a couple of months ago (but might be wrong and it only surfaced then). But we have got more and more complaints from merchants about incorrect order tracking.,

0 Likes
MP7
Tourist
3 0 1

Unfortunately I haven't had any other solutions.  It has however, been a relief however to understand and be able to explain the cause.

Cald may be able to shed light on Shopify's future solutions for high loads. 

I can assume though that this last holiday season was an all-time peak online purchasing time. 

0 Likes
RAd_Tag_Team
Tourist
4 0 1

Thanks @MP7 . We feel the same and glad the we could prove it's not a code issue on our end as that was driving us mad.

@CalDLet us know if you have any updates.

If not we have to think if we have to create backend processes which filter those specific order IDs, perform orders API look-up, get the correct order.name and overwrite/update the order ID in our system. But this sounds a pain for something that should just work.

 

 

0 Likes