Home > Shopify Tutorials > Run Scripts Only on the First Visit on Shopify

How to Run Scripts Only on the First Visit on Shopify

Last updated: August 01, 2024
Written and researched by experts at AvadaLearn more about our methodology

By Sam Nguyen

CEO Avada Commerce

From the order status page that you can view, your analytics will count the sale regardless of the customers just check on their shipments. This might cause wrong analytics. Hence, to prevent them from counting inaccurate, you can learn how to run scripts only on the first visit so that your additional scripts is run only the first time your customers view their order status page.

Related Posts:

How to run scripts only on the first visit

Step 1: Go to Checkout

Log in your Shopify account firstly. Click on Setting which is at the bottom of the admin page. Then, choose Checkout.

How to run scripts only on the first visit

Step 2: Go to the Additional scripts

Scroll down to view the Order processing section. You will see four options in it. Make sure to find out Additional scripts which is the last.

How to run scripts only on the first visit

Step 3: Run the script on order status page

Take a look at the following code. The first thing you need to do is copying the code. Afterward, paste it into the Additional scripts text box. This code is to run the script on the order status page.


{% if first_time_accessed %}
  <!-- Conversion scripts you want to run only once -->
{% endif %}
<!-- Scripts you want to run on every visit -->


Step 4: Run scripts only on the first visit

In this step, take notice of the range which you’ve pasted the code. The sentence I’ve marked with a red rectangle is the script. If you put it between the {% if first_time_accessed %} and {% endif %} tags, it will be run only on the first time the customers access the order status page.

How to run scripts only on the first visit

Otherwise, if you put the script below the {% endif %} tag, then, the script will be run every time the order status page is opened.

How to run scripts only on the first visit

Step 5: Click Save

Finally, make sure you’ve done successfully by clicking Save button.

How to run scripts only on the first visit

To run scripts only on the first visit on Iphone (Click here)

  • Step 1: Click Setting From your Shopify app, click Store. Then, choose Setting.

    How to run scripts only on the first visit
  • Step 2: Go to the Checkout section Make sure that you select Checkout in the Store setting field.

    How to run scripts only on the first visit
  • Step 3: Find the Additional scripts In this step, find the Order processing section. Then, you will see four options appeared. Find out the Additional scripts and click on the text box.

    How to run scripts only on the first visit
  • Step 4: Paste the following code Make sure to copy the below code firstly. Then, you need to paste it in the Additional scripts text box. This action is to run a script when the order status page is accessed.

    
    {% if first_time_accessed %}
    <!-- Conversion scripts you want to run only once -->
    {% endif %}
    <!-- Scripts you want to run on every visit -->
    
    
  • Step 5: Decide how many time the script will be shown If you want the script to be shown only on the first time the customers access the order status page, paste it between the {% if first_time_accessed %} and {% endif %} tags.

    How to run scripts only on the first visit

    Or else, a script will be shown every time the order status page is accessed by pasting it below the {% endif %} tag.

    How to run scripts only on the first visit
  • Step 6: Click Save Scroll down and make sure to select Save after you’ve done.

    How to run scripts only on the first visit

To run scripts only on the first visit on Android one (Click here)

  • Step 1: Click Setting

Log in your Shopify account. From the app, go to Store. Then, choose Setting.

  • Step 2: Go to the Checkout section

Select Checkout in the Store setting field.

  • Step 3: Find the Additional scripts

In this step, look at the Order processing field. Four different options are displayed. Find out the Additional scripts and click on the text box.

  • Step 4: Paste the code

You’d better copy the following code in advance. In the Additional scripts text box, paste the code you’ve copied. This code is to run the script on the order status page.


{% if first_time_accessed %}
<!-- Conversion scripts you want to run only once -->
{% endif %}
<!-- Scripts you want to run on every visit -->

  • Step 5: Decide where to paste the script

In this step, take notice of the range which you’ve pasted the code. The sentence I’ve marked with a red rectangle is the script. If you put it between the {% if first_time_accessed %} and {% endif %} tags, it will be run only on the first time the customers access the order status page.

Otherwise, if you put the script below the {% endif %} tag, then, the script will be run every time the order status page is opened.

  • Step 6: Save

Select Save to make sure that you’ve followed this guide successfully.

Summary

Above are some simple steps you can take to run scripts only on the first visit. After following this, hope you have the accurate analytics. Check out our tutorials for Shopify store owners for more information.


Sam Nguyen is the CEO and founder of Avada Commerce, an e-commerce solution provider headquartered in Singapore. He is an expert on the Shopify e-commerce platform for online stores and retail point-of-sale systems. Sam loves talking about e-commerce and he aims to help over a million online businesses grow and thrive.

People also searched for