Follow the steps below to enable headless mode for Shopify
The headless implementation for Shopify is very easy and consists of 3 parts. Please follow them carefully.
Part 1: Contact support@profitmetrics.io to enable headless mode
Part 2: Install the Server-side Hybrid Universal Integration Custom Pixel in Shopify
Part 1: Contact support@profitmetrics.io to enable headless mode
Please contact support@profitmetrics.io and send the following email:
Hi ProfitMetrics,
Please enable headless mode for our Shopify store [URL].
We will send you a confirmation as soon as it is enabled.
Part 2: Install the Server-side Hybrid Universal Integration Custom Pixel in ShopifyIMPORTANT: You will need to add a script to your website as well as inside Shopify. If you are using Google Tag Manager, please ensure Google Tag Manager is loading correctly on the order confirmation page.
- Click Settings
- Click "Custom event"
- Click "Add custom pixel"
- Set consent to now required and data not qualify as data sale
- Type "PM - Headless mode" in Pixel name and click Add pixel
- Copy and paste the following script. Remember to replace PUBLIC_ID with your actual Public ID found in ProfitMetrics > Website
// Start - ProfitMetrics Serverside Hybrid Universal Integration - (v3)
// Configuration
const pmPublicID = 'YOUR_PUBLIC_ID'; // Your Public ID
const pmEmailInputSelector = '#email'; // Comma-separated CSS Selector
const pmCookieDomain = ''; // Your top-level domain
const pmRememberConsent = false; // Remember consent from previous page
let pmEmail;
// Default consent
let customerPrivacyStatus = init.customerPrivacy;
let cc_statistics = true;
let cc_marketing = true;
// Update consent
function updateConsent() {
if (!pmRememberConsent) {
cc_statistics = customerPrivacyStatus.analyticsProcessingAllowed;
cc_marketing = customerPrivacyStatus.marketingAllowed;
} else {
try {
const pmStorageCookie = document.cookie
.split('; ')
.find(row => row.startsWith('pmStorage='))?.split('=')[1];
if (pmStorageCookie) {
const pmStorage = JSON.parse(decodeURIComponent(pmStorageCookie));
cc_statistics = pmStorage?.cc_statistics ?? cc_statistics;
cc_marketing = pmStorage?.cc_marketing ?? cc_marketing;
if (!cc_statistics && !cc_marketing) return false;
}
} catch {
// Handle errors silently
}
}
}
// Load bundle.js
function pmLoadScript() {
window.profitMetrics = {
pid: pmPublicID,
cookieStatisticsConsent: cc_statistics,
cookieMarketingConsent: cc_marketing,
emailInputSelector: pmEmailInputSelector,
onLoad: () => {
if (pmEmail && pmEmail.includes('@') && pmEmail.includes('.') && !/\s/.test(pmEmail)) {
profitMetrics.setEmail(pmEmail);
}
}
};
if (pmCookieDomain) {
window.profitMetrics.cookieDomain = pmCookieDomain.startsWith('.') ? pmCookieDomain : '.' + pmCookieDomain;
}
const script = document.createElement('script');
script.src = `https://cdn1.profitMetrics.io/${pmPublicID}/bundle.js`;
script.defer = true;
script.onerror = () => console.error('Failed to load ProfitMetrics script.');
document.head.appendChild(script);
}
// Visitor Consent Collected
api.customerPrivacy.subscribe('visitorConsentCollected', (event) => {
customerPrivacyStatus = event.customerPrivacy;
updateConsent();
pmLoadScript();
});
//subscribe to events
analytics.subscribe("checkout_completed", (event) => {
pmEmail = event.data?.checkout?.email;
updateConsent();
pmLoadScript();
});
analytics.subscribe("payment_info_submitted", (event) => {
updateConsent();
pmLoadScript();
});
analytics.subscribe("checkout_shipping_info_submitted", (event) => {
pmEmail = event.data?.checkout?.email;
updateConsent();
pmLoadScript();
});
analytics.subscribe("checkout_address_info_submitted", (event) => {
pmEmail = event.data?.checkout?.email;
updateConsent();
pmLoadScript();
});
analytics.subscribe("checkout_contact_info_submitted", (event) => {
pmEmail = event.data?.checkout?.email;
pmLoadScript();
});
analytics.subscribe("checkout_started", (event) => {
updateConsent();
pmLoadScript();
});
analytics.subscribe("product_added_to_cart", (event) => {
updateConsent();
pmLoadScript();
});
analytics.subscribe("cart_viewed", (event) => {
updateConsent();
pmLoadScript();
});
analytics.subscribe("page_viewed", (event) => {
updateConsent();
pmLoadScript();
});
analytics.subscribe("product_viewed", (event) => {
updateConsent();
pmLoadScript();
});
analytics.subscribe("search_submitted", (event) => {
updateConsent();
pmLoadScript();
});
analytics.subscribe("collection_viewed", (event) => {
updateConsent();
pmLoadScript();
});
// End - ProfitMetrics Serverside Hybrid Universal Integration - Click Save
- Click Add Custom pixel, and connect again