You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Segment makes it simple for Shopify merchants to integrate analytics, email marketing, advertising and optimization tools. Rather than installing all your tools individually, you just install Segment once. We collect your data, translate it, and route it to any tool you want to use with the flick of a switch. Using Segment as the single platform to manage and install your third-party services will save you time and money.
The guide below explains how to install Segment in your Shopify store. All you need to get up and running is copy and paste a few snippets of code into your theme editor. (You don't have to edit the code or be versed in JavaScript.) The following guide will show you how, step by step.
- - -
## Step 1: Segment Account
Start by creating a Segment account. We recommend creating an organization so you can invite teammates to your account in the future.
Once your account is created, add a new project for your store.
## Step 2: Install Segment Code
Once your Segment account is ready to go you'll need to install a few lines of javascript into your Shopify theme templates.
Everything you need can be found in your Shopify Admin under Themes > Customize Theme > Edit HTML/CSS. Each section below includes a reference to one of the folders and liquid templates that can be found on the left side of this page.
If you want to track all events as noninteraction to GA make sure to add an event prop for that.
### 2a: Add Your Snippet to All Pages
- Folder: `Layouts`
- File: `theme.liquid`
Add the following snippet to the line above the `</head>` tag on your main `theme.liquid` template file. Doing this will load the Segment javascript library (Analytics.js) on every page of your Shopify store.
Make sure you replace `YOUR_WRITE_KEY` with the write key found in your setup page (click on the wrench icon from inside your Segment project).
var form = document.getElementById('add-to-cart');
// or your form's ID
analytics.trackForm(form, 'Added Product', {
id: {{ item.id }},
name: "{{ item.title }}",
price: {{ item.price }},
quantity: {{ item.quantity }},
value: {{ item.quantity }}*{{ item.price }}
});
</script>
```
### 2d: Cart Page
- Folder: `Templates`
- File: `cart.liquid`
This script tracks the cart page and events for **Removed Product** and **Updated Product** when a product is removed from the cart or the quantity is updated.
```html
<script type="text/javascript">
analytics.track('Viewed Cart', {
itemCount: {{ cart.item_count }},
totalPrice: {{ cart.total_price }},
totalWeight: {{ cart.total_weight }}
});
</script>
```
### 2f: Thank You Page
This tracks the **Completed Order** event that records all your transaction data to Segment. To add a script to your thank you page, you'll leave the theme editor and go to your checkout settings page: http://myshopify.com/admin/settings/checkout

In the "Additional content scripts" field, shown above, paste the following code: