Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
Hello all,
We want to add a tracking script for a platform we work with (analytics purposes, order logging). Their script requires some fields, like order id, total order cost, etc, but all fields should be in string format.
What's the proper way to convert, for example, number values to string?
Posting a complete example, in order to give you all a better idea of what we're dealing with:
bp('addOrder', { orderId: '123456', // Order ID (alias: order_id) revenue: '1315.25', // Grand Total (Cost + Tax + Shipping) shipping: '5.45', // Shipping Cost tax: '301.25', // Tax currency: 'euro', });
For example, 'shipping' would be 'shipping_price | money_without_currency', but how can we convert this to string format?
Any help would be greatly appreciated, Shopify Support was unable to answer this seemingly simple question.
Solved! Go to the solution
This is an accepted solution.
Owh, you can actually just pass it directly, as such,
bp('addOrder', {
orderId: "{{ checkout.orderId }}",
revenue: "{{ checkout.revenue | money_without_currency }}",
shipping: "{{ checkout.shipping | money_without_currency }}",
tax: "{{ checkout.tax | money_without_currency }}",
currency: 'euro',
});
is this what you wanted?
Hi,
Can you share your store url
Hai, the short answer for your question is no function to convert, string to numbers or vice versa in liquid. You can refer it here, https://www.shopify.com/ca/partners/shopify-cheat-sheet
I assume the analytics code is in a script tag. So, like what we did on ours is to parseInt the string from liquid object and pass that to the analytics code. For example,
var orderId = parseInt("{{checkout.orderId}}");
var revenue = parseInt("{{checkout.revenue | money_without_currency }}");
var shipping = parseInt("{{checkout.shipping | money_without_currency}}");
var tax = parseInt("{{checkout.tax | money_without_currency }}");
bp('addOrder', {
orderId: orderId,
revenue: revenue,
shipping: shipping,
tax: tax,
currency: 'euro',
});
Hope this helps.
First of all thank you for taking the time to answer.
If I understand correctly, parseInt is used to convert string to int, what if we need to do the exact opposite (number to string), as described in the question?
This is an accepted solution.
Owh, you can actually just pass it directly, as such,
bp('addOrder', {
orderId: "{{ checkout.orderId }}",
revenue: "{{ checkout.revenue | money_without_currency }}",
shipping: "{{ checkout.shipping | money_without_currency }}",
tax: "{{ checkout.tax | money_without_currency }}",
currency: 'euro',
});
is this what you wanted?
Yes, quotation marks seem to have done the trick. Thanks a lot!
In Canada, payment processors, like those that provide payment processing services t...
By Jacqui Mar 14, 2025Unlock the potential of marketing on your business growth with Shopify Academy's late...
By Shopify Mar 12, 2025Learn how to increase conversion rates in every stage of the customer journey by enroll...
By Shopify Mar 5, 2025