The value of the integration
Enhanced loyalty
Marketing automation and personalized messages enable webshops to engage visitors and customers with tailored content, creating a deeper connection and increased loyalty.
Improved customer experience
By sending timely and relevant messages based on real-time data, online stores can improve the overall experience by offering valuable information, promotions, and offers that match customer interests and needs.
Targeted communication
Advanced segmentation enables targeted communication, allowing webshops to reach specific target groups with personalized messages tailored to their demographics, preferences, and behavior.
Churn prediction and prevention
Marketing automation tools help identify members at risk of churn by analyzing their engagement and visitor behavior, and they enable proactive strategies to retain them through targeted campaigns and incentives.
Streamlined processes
By automating marketing processes and using personalized messages, webshops can streamline operations, save time and resources, and at the same time deliver relevant and impactful messages to their target audience.
Turn your webshop visitors into loyal customers. With the two-way integration between Heyloyalty and Shopify, you can create effective email marketing and marketing automation based on data from your webshop.
Before you begin
To make it easier for you, we recommend that you read the frequently asked questions and gather the various documents, IDs, login information, etc. that you will need for the setup. See more below.
Frequently asked questions
Do I need a developer?
No. But if you’re unsure how to install an extension from the Shopify app, it might make sense to team up with a colleague.
How long does it take to finish setting up the integration?
Five minutes, plus a few minutes of preparation beforehand to find the items in the list below.
Does the integration retrieve historical data?
Yes – you just need to click a single button during setup.
Do I need access to other systems?
It’s easiest if you already have an active account with Heyloyalty. However, you can create a Heyloyalty account when setting up the integration. You will need your company name, first name, last name, email, phone number and company registration number to set up the integration.
Which data is being imported?
Read the Fields in the integration section at the bottom of this page for the full overview.
Can I segment on data coming through the integration?
Yes. Any data that comes through the integration can be used to segment your future communication. You can also use this data to start and stop your flows.
What you need to set up the integration
Do I need a developer? No
Can I set it up myself? Yes
You should have Heyloyalty and the Shopify shop open in separate tabs in your browser. In Heyloyalty, you’ll need the following:
- If you have a Premium or Premium+ license in Heyloyalty:
Tracking integration from the aforementioned list
If you have a Basic license, you can ignore this.
- API key (in Heyloyalty: Settings → Account information → API key)
- API secret (in Heyloyalty: Settings → Account information → API secret)
The integration operates via Shopify’s API and Heyloyalty’s tracking database. Read more about Tracking here.
Setting up the integration
With the above preparation, you’re now ready to set up the integration between Shopify and Heyloyalty.
Tracking (if your license is either Premium or Premium+)
Before you set up the integration with Shopify, you need to set up a tracking integration. You can read how to set it up here. When setting up the tracking integration, you need to choose which list the tracking data should be transferred to. Since no list has been created from the integration yet, just use a temporary list. If you don’t have a list, you can read how to create one here.
Skip this step if you have a Basic license.
Set up Tracking by clicking Integrations → List Integrations → Tracking → Setup Integration → Create new Tracking.

Fill in the fields. Make sure to link a product feed. The number of category visits and days visited are important to consider, as they affect when a category interest is triggered. A rule of thumb – which may fit more or less well depending on your guests’ typical purchasing patterns and frequency – is to set the Number of visits per category to three and the Number of days visits are over to seven.
Session time should be a number, and it should be the same as in your script. We typically recommend 45 minutes, so if you follow that recommendation, enter 45 in that field.
Setting up the integration
Find the Heyloyalty app in Shopify. Log in to Shopify → Apps → Add apps → Explore more in Shopify App Store.


A new window opens.
Search for Heyloyalty and click Install. Another new window opens, where you click Install again.


Another new window opens.
Do you already have an account with Heyloyalty?
You now need to consider whether you have an active account with Heyloyalty or not.
You already have an account with Heyloyalty
Choose Click here to setup if you already have an active account.

Click Click here to log in and log in to Heyloyalty to find your API key and API secret – you should already have found these in the section What you need to set up the integration.
Fill in API Key and API Secret, and finish by clicking Save connection info.

It will now load for a few seconds. When you see this message, click Close.
Then go to Activate webhooks.
You don’t have an account with Heyloyalty
If you don’t have an active account with Heyloyalty, choose Create my account and fill in the fields:

Activate webhooks
You now need to activate webhooks by clicking Activate webhooks.

After this, you should be able to see the message Shopify Webhooks is active.
Importing historical data
To import historical data, simply click Import all data.

Depending on how much data you have in your webshop, it may take some time. However, the import is now queued, and you can proceed to insert your tracking script.

Insert tracking script
To get data into Heyloyalty about which products your users visit, which products they add to their cart and which products they buy, you need to insert the following tracking script on your webshop.
APIKey can be found here in Heyloyalty:
User menu 👤⚙️ → Account information → API information → API key
Tracking id can be found here in Heyloyalty:
Integrations → List integrations → Tracking → Edit integration → *Find your Tracking id in the fourth column*
(function () {
// Helper function to generate a unique ID
function generateUUID() {
return 'xxxxxxxx-xxxx-xxxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
const r = (Math.random() * 16) | 0;
const v = c === 'x' ? r : (r & 0x3) | 0x8;
return v.toString(16);
});
}
// Helper function to get or set a cookie
function getOrSetCookie(name, value, minutes) {
const existingCookie = document.cookie.split('; ').find((row) => row.startsWith(name + '='));
if (existingCookie) {
return existingCookie.split('=')[1];
}
if (value) {
const expires = new Date();
expires.setTime(expires.getTime() + minutes * 60 * 1000);
document.cookie = `${name}=${value}; expires=${expires.toUTCString()}; path=/;`;
return value;
}
return null;
}
// Generate or retrieve the CookieID (persistent for 1 year)
const HLcookieID = getOrSetCookie('HLcookieID', generateUUID(), 365 * 24 * 60); // 1 year in minutes
// Generate or retrieve the SessionID (valid for 5 minutes)
const HLsessionID = getOrSetCookie('HLsessionID', generateUUID(), 45); // 45-minute lifetime
// Log the IDs for debugging
//console.log('HLCookieID:', HLcookieID);
//console.log('HLSessionID:', HLsessionID);
const APIkey = "XXXXXXXX";
const integrationId = "XXXXX";
// Example: Dispatch a custom Shopify event with the IDs
analytics.subscribe('page_viewed', () => {
const eventPayload = {
event_name: 'page_viewed',
HLsessionID: HLsessionID,
HLcookieID: HLcookieID,
};
//console.log('Custom Page Viewed Event:', eventPayload);
});
var productView = false;
analytics.subscribe("product_viewed", event => {
// Example: Send this data to an external tracking service (optional)
const productId = event.data.productVariant.id;
const url = event.context.window.location.href;
productView = true;
protocol = "https:" == document.location.protocol ? "https://" : "http://",
source = protocol + 'tracking.heyloyalty.com/' + "visit" + '/' + APIkey + '?' + "cookie=" + HLcookieID + "&session=" + HLsessionID + "&integrationId=" + integrationId + "&productId=" + productId + '&url=' + url,
xhr = new XMLHttpRequest();
xhr.open('GET', source, true);
xhr.send();
if (url.indexOf("hlId=")>-1){
const queryString = window.location.search;
const urlParams = new URLSearchParams(url);
const email = urlParams.get('hlId')
protocol = "https:" == document.location.protocol ? "https://" : "http://",
source = protocol + 'tracking.heyloyalty.com/' + "pairEmail" + '/' + APIkey + '?' + "cookie=" + HLcookieID + "&session=" + HLsessionID + "&integrationId=" + integrationId + "&email=" + email + '&url=' + url,
xhr = new XMLHttpRequest();
xhr.open('GET', source, true);
xhr.send();
}
});
analytics.subscribe("page_viewed", event => {
const url = event.context.window.location.href;
//console.log(productView)
if(productView){
return
}
protocol = "https:" == document.location.protocol ? "https://" : "http://",
source = protocol + 'tracking.heyloyalty.com/' + "visit" + '/' + APIkey + '?' + "cookie=" + HLcookieID + "&session=" + HLsessionID + "&integrationId=" + integrationId + '&url=' + url,
xhr = new XMLHttpRequest();
xhr.open('GET', source, true);
xhr.send();
console.log("side-set");
if (url.indexOf("hlId=")>-1){
const queryString = window.location.search;
const urlParams = new URLSearchParams(url);
const email = urlParams.get('hlId')
protocol = "https:" == document.location.protocol ? "https://" : "http://",
source = protocol + 'tracking.heyloyalty.com/' + "pairEmail" + '/' + APIkey + '?' + "cookie=" + HLcookieID + "&session=" + HLsessionID + "&integrationId=" + integrationId + "&email=" + email + '&url=' + url,
xhr = new XMLHttpRequest();
xhr.open('GET', source, true);
xhr.send();
}
});
analytics.subscribe("product_added_to_cart", event => {
const productId = event.data.cartLine?.merchandise.product.id;
const url = event.context.window.location.href;
const basketId = event.data.cartLine?.merchandise.id;
const itemAmount = event.data.cartLine?.quantity;
const categoryId = event.data.cartLine?.merchandise.product.type;
protocol = "https:" == document.location.protocol ? "https://" : "http://",
source = protocol + 'tracking.heyloyalty.com/' + "addtobasket" + '/' + APIkey + '?' + "cookie=" + HLcookieID + "&session=" + HLsessionID + "&integrationId=" + integrationId + "&productId=" + productId + "&amount=" + itemAmount + "&categoryId=" + "&basketId=" + basketId + '&url=' + url,
xhr = new XMLHttpRequest();
xhr.open('GET', source, true);
xhr.send();
});
analytics.subscribe("product_removed_from_cart", event => {
const productId = event.data.cartLine?.merchandise.product.id;
const url = event.context.window.location.href;
const basketId = event.data.cartLine?.merchandise.id;
const itemAmount = event.data.cartLine?.cost.totalAmount.amount;
const categoryId = event.data.cartLine?.merchandise.product.type;
protocol = "https:" == document.location.protocol ? "https://" : "http://",
source = protocol + 'tracking.heyloyalty.com/' + "removefrombasket" + '/' + APIkey + '?' + "cookie=" + HLcookieID + "&session=" + HLsessionID + "&integrationId=" + integrationId + "&productId=" + productId,
xhr = new XMLHttpRequest();
xhr.open('GET', source, true);
xhr.send();
});
analytics.subscribe("checkout_completed", event => {
const basketAmount = event.data.checkout.subtotalPrice?.amount;
const url = event.context.window.location.href;
const basketId = event.data.checkout.order?.id;
protocol = "https:" == document.location.protocol ? "https://" : "http://",
source = protocol + 'tracking.heyloyalty.com/' + "purchasebasket" + '/' + APIkey + '?' + "cookie=" + HLcookieID + "&session=" + HLsessionID + "&integrationId=" + integrationId + "&basketPrice=" + basketAmount + "&order_number=" + basketId + '&url=' + url,
xhr = new XMLHttpRequest();
xhr.open('GET', source, true);
xhr.send();
});
})();
Once you’ve inserted APIkey and IntegrationId, you’re ready to insert the script in your Shopify shop. To do this, go to your Shopify shop and then to settings:

Then go to Customer events → More views → Custom pixels and click Add custom pixel:

Then name your pixel. We recommend calling it Tracking Heyloyalty. Then click Add pixel.

On this page, you can insert your tracking script in the code field:

Once the script is inserted, you can save it. When you’ve clicked save, you’ll be able to click Connect:

After the script is connected, you need to add the list newly created by the integration to your tracking integration. To do this, go to: Integrations → List integrations → Tracking → Set up integration → Create new Tracking.
Once the list has been changed, you can check whether events are coming in from your webshop. You can see this in the activity feed, which you can find here: statistics → activity feed.
Products in your campaigns
To insert your products into your campaigns, you need a Shopify app that can generate a product feed. You may already have an app for this – if not, you can ask your web agency.
Alternatively, there’s a free module available here: https://apps.shopify.com/product-feeds-generator. With it, you can generate a product feed.
When you’ve generated your product feed, you can set up the feed in Heyloyalty. You can read how to set up your feed here.
General information about the integration
Worth knowing about the integration
When the integration is set up, you can retrieve all historical purchase data with a single click.
Heyloyalty creates a contact when a contact who has agreed to receive the newsletter is created in Shopify.
- The contact is automatically updated in the Tracking database. This means that you can, among other things, segment by whether the contacts in Heyloyalty have purchased within the last seven days or not, have spent more than a given amount or have purchased more than a certain number of times, to name just a few of your options.
- Data is tracked on unknown members, and when an unknown member subscribes to the newsletter, Heyloyalty automatically pairs all of this person’s data retroactively, so you get the complete history when a member subscribes to the newsletter.
Fields in the integration
If you want a complete overview of the fields in the integration, you can find it among the fields of the list you have connected the integration to.
Lists → ⋮ → Edit list. Scroll to the bottom to see all the custom fields that you have mapped as part of the integration.

If you need information or help that you cannot find here on the guide site, you are always welcome to contact our support!
support@heyloyalty.com