K

Shopify Tracking Script Setup

Step-by-step instructions for adding the Revshare tracking script to your Shopify store to track visitors and attribute sales.

Emil Klitmose

Written by Emil Klitmose

Updated recently

To track affiliate clicks and attribute sales, you need to add a small tracking script to your Shopify theme. This script runs in the background and ensures that when a customer makes a purchase, we know which affiliate sent them.

This guide walks you through the process of adding the script to your Shopify theme code.

Why is this script needed?

The tracking script performs several essential functions:

  • Detects when a visitor arrives from an affiliate link
  • Stores a secure tracking cookie in the visitor's browser
  • Maintains the tracking data across different pages of your store
  • Attaches the necessary tracking IDs to the Shopify checkout session

Adding the Script

Follow these steps to add the script to your Shopify store:

1. Open Theme Code Editor

In your Shopify Admin, go to Online StoreThemes.

Click the "..." button next to your active theme and select Edit code.

2. Find theme.liquid

In the sidebar, locate the Layout folder and click on theme.liquid.

3. Paste the Script

Scroll down until you see the closing </head> tag (usually near the top of the file). Paste your unique tracking script directly above this tag.

<script
  async
  src="https://www.revshare.so/shopify-tracking.js"
  data-program-id="YOUR_PROGRAM_ID"
  data-domain=".yourdomain.com"
  data-cookie-duration="30"
></script>
</head>

4. Save Changes

Click the Save button in the top right corner of the editor.

Password Protected Stores

If your store is currently password protected (e.g., during pre-launch), you should also add the script to your password.liquid file.

This ensures that if an affiliate sends traffic to your store before it's officially open, the visitor's click is still tracked and credited if they return to buy later.

Verifying Installation

To verify the script is working correctly:

  1. Open your store website in a browser
  2. Right-click anywhere and select Inspect
  3. Go to the Console tab
  4. Type window.revshare and press Enter. If it returns an object, the script is loaded.
  5. Alternatively, go to the Application tab (or Storage), check Cookies, and look for a cookie named _rs_ref after clicking an affiliate link.

Custom Domains

The data-domain attribute in your script is vital for tracking. It should be your store's primary domain (e.g., .yourstore.com).

Note: Always include the leading dot (e.g., .mysite.com). This allows tracking to work across subdomains, ensuring that clicks on www.mysite.com are tracked even if the checkout happens on a different subdomain.

Need more help? See our Webhook Setup Guide or contact support.