Skip to main content

Setting up the Klar Pixel for Shopify (customer events)

How to set up the Klar tracking pixel by validating your domain, implementing the tracking script, and adjusting UTM parameters.

Written by Maximilian Rast

tl;dr

Do you want to start using the attribution report in Klar? Great choice 🎉

Setting up the Klar Pixel takes a few minutes and involves five steps:

  1. Add the Klar Pixel datasource in Klar and choose Domain Validated (recommended) or Basic tracking

  2. Validate your domain via two DNS records with your hosting provider

  3. Implement the tracking script in Shopify Customer Events

  4. Add URL parameters to your ad accounts so conversions and costs can be matched

  5. Add the data privacy snippet to your data privacy policy if needed.

If you have multiple Shopify stores with separate domains, create a separate Klar Pixel datasource for each.


1️⃣ Add the Klar Pixel datasource

If you have multiple Shopify instances, with separate domains, connected to Klar, you should create a unique Pixel datasource for each of these stores.

  1. Go to Store ConfiguratorData Sources and click Add New Data Source

  2. Select Klar Pixel

  3. Enter a name (e.g. Klar Pixel DE)

  4. Select Shopify as your Shop System

  5. Choose your tracking type:

    1. Domain Validated Pixel (recommended) — you set up a subdomain for your shop's domain with your DNS provider, and Klar delivers the Attribution JavaScript via that subdomain. This leads to more tracked conversions because some browsers block third-party JavaScripts by default

    1. Basic Tracking Script — a third-party script, simpler to set up but less accurate

6. If you selected Basic Tracking Script, skip ahead to Step 3 — your script is already available

7. If you selected Domain Validated Pixel, enter your domain name (exclude https:// and www.), then click Configure


2️⃣ Validate your domain (Domain Validated only)

Klar will show two DNS records that you need to add to your hosting provider's DNS settings.

Shopify, WebGo, All Inkl, Strato users: When adding the DNS records, remove your domain from the Name field. Only enter the numeric prefix.

Correct format:

Record type

Wrong ❌

Correct ✅

CNAME

123456789.your-shop.com

123456789

CNAME IPv4

123456789-4.your-shop.com

123456789-4

  1. Copy and paste the two DNS records into your hosting provider's DNS settings using the copy icon next to each field

  2. Click Validate DNS Records

⚠️ Note: DNS propagation can take anywhere from a few hours to 2 days. Once verified, a green check icon appears next to each record. If you're unsure how to add DNS records, reach out via the support chat — we're happy to help.

Once both records are validated, the Tracking Script appears in the datasource. Copy it for the next step.


3️⃣ Implement the tracking script in Shopify

Remove any existing Klar Pixel code first to avoid double-counting. Check these locations:

  • theme.liquid

  • checkout.liquid (Shopify Plus only)

  • Additional scripts in your checkout settings

3.1 Standard Shopify store

  1. Click Copy Script in the Klar Pixel datasource

  2. In your Shopify Admin, go to SettingsCustomer Events

  3. Click Add Custom Pixel

  4. Give the pixel a unique name (e.g. Klar!)

  5. Delete the default code in the Code window and adjust the privacy settings

  6. Paste your Klar Pixel Customer Events JavaScript into the Code window

  7. Click Save, then click Connect Pixel to activate tracking

⚠️ Note: Shopify Customer Events only fire when the user has accepted the cookie banner — provided a Shopify-compatible cookie solution is in place.

3.2 Shopify Markets with multiple top-level domains

If you use Shopify Markets with multiple TLDs (e.g. shop.de and shop.co.uk):

  1. Create a separate Domain Validated Pixel datasource for each TLD

  2. Replace the standard script with this multi-domain script, updating the getPixelDomain() function with your actual pixel URLs:

function getTLD() {

const hostname = window.location.hostname;

const parts = hostname.split('.');

if (parts.length > 1) {

return parts.slice(-2).join('.');

} else {

return null;

}

}

function getPixelDomain() {

const domain = getTLD();

switch (domain) {

case "domain-a.de":

return "123456789.domain-a.de"; // Address for Domain #1

case "domain-b.de":

return "987654321.domain-b.de"; // Address for Domain #2

default:

return "987654321.domain-b.de"; // Default fallback

}

}

const script = document.createElement('script');

script.type = 'text/javascript';

script.async = true;

script.src = 'https://' + getPixelDomain() + '/javascript/script.js';

document.getElementsByTagName('script')[0].parentNode.appendChild(script);

window._k_s_c_e = true;

window._k_s_c_e_i = init;

window._k_s_c_e_b = browser;

window._k_s_c_e_s = api.settings;

analytics.subscribe('all_events', (event) => {

window._k_s_q = window._k_s_q || [];

window._k_s_q.push(['Shopify:allEvents', event]);

});

You only need to modify the getPixelDomain() function — the rest of the script stays the same:

function getPixelDomain() {

const domain = getTLD();

switch (domain) {

case "domain-a.de":

return "123456789.domain-a.de"; // Address for Domain #1

case "domain-b.de":

return "987654321.domain-b.de"; // Address for Domain #2

default:

return "987654321.domain-b.de"; // Default fallback

}

}

For each additional TLD, add a new case to the switch statement with the corresponding pixel subdomain.


4️⃣ Add the Data Privacy snippet

Add the Klar Data Privacy snippet to your privacy policy to inform customers about the Klar Pixel. You'll find a German and English version inside the Klar Pixel datasource, under the tracking script in the collapsed Data Protection Snippet section.


5️⃣ Implementing Klar URL Parameters

To ensure that conversions and costs can be matched as accurately as possible, you need to implement the pre-defined Klar tracking codes in your ad accounts.

Here are guides on how to do that for each marketing channel:


What happens next?

From now on, Klar tracks visitors and purchase activity on your site. Data will appear in your Attribution reports from the next day onwards — historical data before the script was added is not available.

🎉 Your Klar Pixel is live — you're ready to start using the Attribution reports!

Did this answer your question?