# Track Shopify Stores

Shopify is a popular online e-commerce store. Before Satisfi Labs can start tracking your store, you will have to manually add the tracking code. This needs to be added any time you start using a new theme.

{% hint style="warning" %}
The below steps should work for a standard Online Store setup and rely on the use of collections for category tracking and product pages for product views. It also relies on the visitor loading the cart or the cart template loading on the page when a visitor adds an item to their cart for Abandoned cart tracking. If you have a setup that skips the “Add to cart” button and goes directly to checkout, then the steps below will not work to track Cart updates.
{% endhint %}

Follow the steps below to set up standard tracking, along with e-commerce tracking of your Shopify website to Satisfi Labs:

1. In the Marketing Engine dashboard, copy your tracking code to a text editor. You will find your tracking code in [**Settings**](https://app.factoreal.com/settings/website-config)

<div data-full-width="true"><figure><img src="/files/8NDQD39NGrU9fWXVgzs1" alt=""><figcaption><p>Step One</p></figcaption></figure></div>

2. Log in to your Shopify store and navigate to **Online Store**, click on **Themes,** and then on the “**Customize**” button in the center of the page.

<div data-full-width="true"><figure><img src="/files/ZgDy7qI4Pg3j95pXVLSu" alt=""><figcaption></figcaption></figure></div>

<figure><img src="/files/FbOxlX01noWghDwAB0qm" alt="" width="274"><figcaption></figcaption></figure>

3. Click on the liquid file in the file navigator on the left

<figure><img src="/files/vqdIuJACgwTsAPAEXB3z" alt="" width="352"><figcaption></figcaption></figure>

4. Find the end of the \<head>tag in the code

<figure><img src="/files/uCxkUEq8XKh8An2xZcYC" alt=""><figcaption></figcaption></figure>

5. Paste the tracking code from your text file above the line that contains \</head>

<figure><img src="/files/Kb3CMhvyUdRAvpNfNviT" alt=""><figcaption></figcaption></figure>

6. Copy the following code into your tracking code block above the **trackPageView** line in the liquid file and click “Save”.

{% code overflow="wrap" %}

```
{% if template == 'collection' %}
{% capture tag_list %}
{% for tag in collection.all_tags limit:5 %}
{{ tag }}
{% if forloop.last == false %}::{% endif%}
{% endfor %}
{% endcapture %}
{% assign tag_array = tag_list | split: '::'%}
_paq.push(['setEcommerceView',
false, // Product name is not applicable for a category view.
false, // Product SKU is not applicable for a category view.
{{ tag_array | json }}, // Product category, or array of up to 5 categories
]);
{% endif %}
{% if template == 'product' %}
{% capture tag_list %}
{% for tag in product.tags limit:5 %}
{{ tag }}
{% if forloop.last == false %}::{% endif%}
{% endfor %}
{% endcapture %}
{% assign tag_array = tag_list | split: '::'%}
_paq.push(['setEcommerceView',
{{ product.id }}, // (Required) productSKU
{{ product.title | json}}, // (Optional) productName
{{ tag_array | json }}, // (Optional) categoryName
{{ product.price | money_without_currency }} // (Optional) price
]);
{% endif %}
```

{% endcode %}

A complete example would look like the following:

<figure><img src="/files/iIgG2rOaAbENGhE6lsuS" alt=""><figcaption></figcaption></figure>

7. Click on the sections/main-cart-items.liquid file in the left navigation menu under the “Sections” folder to open it
8. Insert the following code block at the top of the file and click “Save”

{% code overflow="wrap" %}

```
<script>
var _paq = window._paq = window._paq || [];
{% for item in cart.items %}
{% capture tag_list %}
{% for tag in item.product.tags limit:5 %}{{ tag }}
{% if forloop.last == false %}::{% endif%}{% endfor %}{% endcapture %}
{% assign tag_array = tag_list | split: '::'%}
_paq.push(['addEcommerceItem',
{{ item.product_id }}, // (Required) productSKU
{{ item.title | json }}, // (Optional) productName
{{ tag_array | json }}, // (Optional) productCategory
{{ item.final_price | money_without_currency }}, // (Recommended) price
{{ item.quantity }} // (Optional, defaults to 1) quantity
]);
{% endfor %}
_paq.push(['trackEcommerceCartUpdate', {{ cart.total_price | money_without_currency }}]);
</script>
```

{% endcode %}

<figure><img src="/files/iDymECvI919AR0WOohVp" alt=""><figcaption></figcaption></figure>

9. Click “Exit” in the top left corner to return to the Admin page and click “Settings” in the bottom left corner
10. Click on “Checkout”

<figure><img src="/files/Sxlbqprr8UfCt1VcY3MM" alt=""><figcaption></figcaption></figure>

11. Scroll all the way to the bottom of this page where it shows “Order status page” and copy your tracking code script from your text file

<figure><img src="/files/RGyzdqzPzorECzJ5ikoQ" alt=""><figcaption></figcaption></figure>

12. Paste the following code:

{% code overflow="wrap" %}

```
<!-- Factoreal -->
<script>
var _paq = (window._paq = window._paq || []);
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(["setCookieDomain", "*.store.combifam.com"]);
_paq.push(["setDoNotTrack", true]);
_paq.push(["trackPageView"]);
_paq.push(["enableLinkTracking"]);
(function () {
var u = "https://webanalytics.factoreal.com/";
_paq.push(["setTrackerUrl", u + "js/tracker.php"]);
_paq.push(["setSiteId", "60"]);
var d = document,
g = d.createElement("script"),
s = d.getElementsByTagName("script")[0];
g.async = true;
g.src = u + "js/tracker.php";
s.parentNode.insertBefore(g, s);
})();
{% for line_item in checkout.line_items %}
{% capture tag_list %}{% for tag in line_item.product.tags limit:5 %}{{ tag }}
{% if forloop.last == false %}::{% endif%}{% endfor %}{% endcapture %}
{% assign tag_array = tag_list | split: '::'%}
_paq.push(['addEcommerceItem',
{{ line_item.product_id }}, // (Required) productSKU
{{ line_item.title | json }}, // (Optional) productName
{{ tag_array | json}}, // (Optional) productCategory
{{ line_item.final_price | divided_by:100 }}, // (Recommended) price
{{ line_item.quantity }} // (Optional, defaults to 1) quantity
]);
{% endfor %}
_paq.push(['trackEcommerceOrder',
{{ checkout.order_id }}, // (Required) orderId
{{ checkout.total_price | divided_by:100 }}, // (Required) grandTotal (revenue)
{{ checkout.subtotal_price | divided_by:100 }}, // (Optional) subTotal
{{ checkout.tax_price | divided_by:100 }}, // (optional) tax
{{ checkout.shipping_price | divided_by:100 }}, // (optional) shipping
{{ checkout.discounts_amount | divided_by:100 }} // (optional) discount
]);
</script>
<noscript
><p>
<img
src="https://webanalytics.factoreal.com/js/tracker.php?idsite=60&amp;rec=1"
style="border: 0"
alt=""
/></p
></noscript>
<!-- End Factoreal Code -->
```

{% endcode %}

A complete example would look like:

<figure><img src="/files/npPf20oYn1NYo4DIp4Sk" alt=""><figcaption></figcaption></figure>

13. Test that the e-commerce tracking is working as expected.\
    – Go to your Shopify store, view some products, and add at least one product to your Cart.\
    – Go to the marketing engine dashboard and check the “[Visits Log](https://matomo.org/faq/reports/the-visits-log-report/)” report and check that the Cart Update is tracked to the marketing engine:

<figure><img src="/files/z2kEsWSLhfBoNxazHoV7" alt=""><figcaption></figcaption></figure>

14. Hover your mouse over the Pageview where you viewed the product to confirm that you’re tracking      Product/Category views:

<figure><img src="/files/IlHY2l5YCEAlMvpomqMg" alt=""><figcaption></figcaption></figure>

– Place an order on your website (Using for example a 100% discount coupon or while your store is placed in “[Test Mode](https://help.shopify.com/en/manual/payments/shopify-payments/testing-shopify-payments)“) and check that the order is tracked in the marketing engine dashboard:

<figure><img src="/files/P3klEiN8Kvi2nXVWvPwz" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
Shopify does not make the Collections or Product Categories available in the Cart or Order Status pages. For that reason, we track the product and collections Tags as the product category in the marketing engine. We support a maximum of 5 product categories per product or category view, so the code blocks above will track the first 5 tags in alphabetical order.
{% endhint %}

## **Integrate Marketing Engine into your Shopify Store (No e-commerce tracking)**

If you don’t want to track e-commerce data in your marketing engine, you can follow the steps below to add a basic tracking code to your Shopify website.

1. In your marketing engine dashboard, copy your tracking code. You will find your tracking code in [**Settings**](https://prime.factoreal.info/settings)/Website Configuration.

<div data-full-width="true"><figure><img src="/files/xuKFJN6p2NYfh4RflAD5" alt=""><figcaption></figcaption></figure></div>

2. Log in to your Shopify store. Select **Online Store**, then choose **Themes** from the dropdown menu. Select **Edit Code** from the **Actions**

<figure><img src="https://cdn-ilafdgl.nitrocdn.com/AoMPzHvoOQtQepOCSwHbvPwRmHsjWvyq/assets/images/optimized/rev-fe681bb/www.factoreal.com/wp-content/uploads/2023/07/shopify-theme-1.png" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/gpLLVd2UGzheVBbJwsjb" alt="" width="274"><figcaption></figcaption></figure>

3. Select **liquid** from the **Layout**.

<figure><img src="https://cdn-ilafdgl.nitrocdn.com/AoMPzHvoOQtQepOCSwHbvPwRmHsjWvyq/assets/images/optimized/rev-fe681bb/www.factoreal.com/wp-content/uploads/2023/07/Group-20.png" alt="" width="375"><figcaption></figcaption></figure>

<figure><img src="/files/djQtupSsNkeYJFHluv6o" alt=""><figcaption></figcaption></figure>

4. Scroll down to where you can see **\</head>**&#x69;n the code. Immediately above this, paste your Factoreal tracking code (Step 1).
5. Click **Save** from the top right of the window.
6. (optional step) If you have Shopify Plus (Shopify enterprise version), reach out to your Shopify Merchant Manager who will be able to install Satisfi Labs on your checkout pages.
7. Open your website in the browser and perform some actions (eg: navigate to different pages)
8. Login to the marketing engine dashboard and check if the website visit is tracked


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.satisfilabs.com/resource-center/marketing-engine/settings-and-integrations/integrations/website-tracking/track-shopify-stores.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
