One can add note
, attributes
and ref
vars to Shopify URLs for conversion tracking as described here:
Shopify Conversion Tracking Documentation
How can I execute extra code if one of these vars exists in the URL? I need to run code right when the URL is initially visited and I also need to run code if the customer completes the purchase.
Supposedly if I have a Shopify Plus plan then I can create my own layout/checkout.liquid
templates and write some JavaScript code that will do what I need. But we don’t have a Shopify Plus plan.
I’ve also heard that I can write code in Admin > Settings > Checkout > Order Processing > Additional Scripts
in order to respond to these URL vars but supposedly this option will only allow me to respond on the purchase finished page but not when the URL is initially visited.
Are there any other options? Can I do all of this with a Shopify app?
2
Answers
Yes, it would be much simpler if you are on Shopify Plus plan. Nonetheless it is still possible to do so.
If you go to
You can add JavaScript code there that will be loaded on all pages. But it allows limited number of characters , so be aware of that.
To implement the solution, listen to the page load event and then look for any desired variables in the URL. If you find any such variable, you may save it in the Local Storage or Session Storage depending on your use case. For subsequent page visits and page reloads, only write value if does not exist already.
For the scenario when customer completes a purchase, you may add the code in
But make sure to use the first time accessed condition to prevent duplicate processing.
Shopify suggests us to use landing_site_ref to put the condition on thank you page.
The customer comes to your website having this parameter in their URL
Put following code(dummy sample) on Additional scripts of Checkout Section.
Note: You can explore referring_site & landing_site fields available on Thank You page and use contain condition of Shopify e.g. if landing_site contains ‘abc’.