skip to Main Content

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


  1. 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.

    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

    Online Store > Preferences > Google Analytics account
    

    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

    admin > Settings > Checkout > Order Processing > Additional Scripts
    

    But make sure to use the first time accessed condition to prevent duplicate processing.

    {% if first_time_accessed %}
      <!-- Conversion scripts you want to run only once -->
    {% endif %}
    
    Login or Signup to reply.
  2. 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

    http://www.referingsite.com?ref=abc
    

    Put following code(dummy sample) on Additional scripts of Checkout Section.

    {% if landing_site_ref == 'abc' %}
    <script type='text/javascript' src="https://TestTrack.com/get_order?ORDERID={{order.order_number}}&AMOUNT={{ total_price | money_without_currency }}"></script>
    {% endif %}
    

    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’.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search