Step 3: Adding Sales Tracking Code

Modified on Mon, 21 Oct at 4:03 PM

Note: The Sales Tracking Feature is only available for the Pro plan.


This guide will walk you through the process of adding a tracking snippet to your Shopify store to monitor sales generated from AI-recommended products using Streamline Connector.

Step 1: Insert the Code Snippet in the <head> Tag

You need to add the following code to the theme.liquid file, right after the <head> tag in your Shopify theme:

<head>
  {% if template.name == 'product' %}
    <script>
      (function() {
        const urlParams = new URLSearchParams(window.location.search);
        const sourceCode = urlParams.get('ai-recommended');
        if (!sourceCode) return;
        const formData = new FormData();
        formData.append("note", "ai-recommended");
        fetch('/cart/update.js', {
          method: 'POST',
          body: formData
        })
        .then(response => response.json())
        .then(data => console.log('Added source code to cart attributes.', data));
      })();
    </script>
  {% endif %}


What Does This Code Do?

  1. Template Check: The code only runs on product pages ({% if template.name == 'product' %}).
  2. URL Parameter Detection: The script checks the current URL for a query parameter called ai-recommended.some text
    • For example, a URL like https://yourstore.com/product-name?ai-recommended=true.
  3. Cart Update: If the ai-recommended parameter exists, the code will:some text
    • Create a form with a "note" field containing the value ai-recommended.
    • Send this data to Shopify using the fetch() API to update the cart attributes.
  4. Log Confirmation: After updating, it logs a message confirming that the "AI-recommended" source code was added to the cart.

Step 2: Modify Recommended Product URLs

To track sales generated from AI recommendations, you need to modify the URLs of your recommended products.

  1. Locate your AI-recommended product URLs.
  2. Add the query parameter ?ai-recommended=true to the end of each URL.

Original URL: https://yourstore.com/product-name

Modified URL: https://yourstore.com/product-name?ai-recommended=true

Step 3: Enable Sales Tracking in Your App

  1. Go to your app's homepage.
  2. Click "Enable Sales Tracking" to initiate sales tracking for AI-recommended products.
  3. View Results: After confirmation, you will be able to track the revenue generated by AI-recommended products.

Summary

  • Insert the code snippet into your <head> section to track AI-recommended product sales.
  • Append ?ai-recommended=true to the URLs of your recommended products.
  • Enable sales tracking in your app to monitor revenue performance.

This setup will allow you to measure the effectiveness of AI recommendations and track sales generated from them directly in your Shopify store.


Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article