Follow the steps below to install the Serverside Hybrid Universal Integration script on your website.
Last updated: 2025-02-10
The ProfitMetrics Serverside Hybrid Universal Integration is a universal integration which allows for ProfitMetrics to be implemented into any e-commerce platform that is not supported natively. The integration consists of two parts. Part 1 of the integration refers to the sending of orders to ProfitMetrics according to our documentation. Part 2 is to implement the tracking script to capture statistical and marketing-related tracking parameters from the browser and pair these with the orders.
Alternatively, you can set it up via Google Tag Manager.
How to install the Serverside Hybrid Universal Integration script in Google Tag Manager.
See this article if you haven't built your integration with ProfitMetrics yet: Sending orders to profitmetrics serverside
Part 1: Implement script on All pages
- Public ID
- Email input selector
- Consent Control
- Cross-Subdomain Tracking
- Klarna Checkout (Optional)
- onLoad Event
- setEmail Event
Part 2: Implement setEmail event to capture email when using a third-party checkout.
Part 3: Complete code for known CMP's
Part 4: Confirm the integration
Part 1: Implement script on All pages
When implementing the tracking script on your website it is important that you know which Consent Management Platform (CMP) you are using. ProfitMetrics script automatically supports the following platforms:
Supported Consent Management Platforms (CMP):
- Cookieinformation.com
- Cookiebot.com
- DanDomain / SmartWeb / ScanNet / WannaFind / HostedShop
-
PUBLIC ID
Copy the following script and place it the <head></head> section of your website. Remember to replace PUBLIC_ID with your Public ID found in ProfitMetrics under Websites and replace .class-name as described in the next step.<!-- Start ProfitMetrics - Script -->
<script>
window.profitMetrics = {
pid: 'PUBLIC_ID', // Your Public ID
}
</script>
<script src="https://cdn1.profitmetrics.io/PUBLIC_ID/bundle.js"
defer></script>
<!-- End ProfitMetrics - Script --> - EMAIL INPUT SELECTOR
The next step is to add the emailInputSelector field like this:
emailInputSelector: '.class-name',
Replace ".class-name" with a comma-separated list of the CSS selectors of those email input fields. You can right-click and inspect the field or you can use a tool like Selector gadget to quickly click and identify the correct CSS selctor.
<!-- Start ProfitMetrics - Script -->
<script>
window.profitMetrics = {
pid: 'PUBLIC_ID', // Your Public ID
emailInputSelector: '.class-name',
}
</script>
<script src="https://cdn1.profitmetrics.io/PUBLIC_ID/bundle.js"
defer></script>
<!-- End ProfitMetrics - Script --> -
CONSENT CONTROL
If you do not use any of the natively supported Consent Management Platforms (CMP) or wish to manually control consent, you can add the following two lines and replace true/false with a boolean value depending on the consent state. This script can also be loaded multiple times as consent change but remember to load the bundle.js every time.cookieStatisticsConsent: true, // Replace with boolean value (true/false)
cookieMarketingConsent: true, // Replace with boolean value (true/false)<!-- Start ProfitMetrics - Script -->
<script>
window.profitMetrics = {
pid: 'PUBLIC_ID', // Your Public ID
emailInputSelector: '.class-name',
cookieStatisticsConsent: true,
cookieMarketingConsent: true,
}
</script>
<script src="https://cdn1.profitmetrics.io/PUBLIC_ID/bundle.js"
defer></script>
<!-- End ProfitMetrics - Script --> - CROSS-SUBDOMAIN TRACKING
If you have multiple subdomains like en.example.com and de.example.com, or simply have a subdomain like blog.example.com or your checkout is located on checkout.example.com, you might want to set up Cross Domain Tracking. You can do this by including cookieDomain and set the value to match your your TLD (Top-level domain). This will enable cross-subdomain tracking for headless implementations and third-party checkouts. Remember to add a '.' before the domain.
Correct way: '.example.com' // Starts with a dot
Wrong way: 'example.com' // Does not start with a dot
Warning: Enabling this might cause issues if your site uses a subdomain structure for different countries or languages like en.example.com
cookieDomain: '.example.com', // CORRECT
cookieDomain: 'example.com', // WRONG<!-- Start ProfitMetrics - Script -->
<script>
window.profitMetrics = {
pid: 'PUBLIC_ID',
emailInputSelector: '.class-name',
cookieStatisticsConsent: true,
cookieMarketingConsent: true,
cookieDomain: '.example.com',
}
</script>
<script src="https://cdn1.profitmetrics.io/PUBLIC_ID/bundle.js"
defer></script>
<!-- End ProfitMetrics - Script --> - KLARNA CHECKOUT
Add the following lines inside the script to automatically capture the customer's email from within the Klarna Checkout
enableKlarnaTracking: true, // Enable Klarna tracking
checkoutPath: '/checkout', // URL path of your checkout pagesExample:
<!-- Start ProfitMetrics - Script -->
<script>
window.profitMetrics = {
pid: 'PUBLIC_ID',
emailInputSelector: '.class-name',
cookieStatisticsConsent: true/false,
cookieMarketingConsent: true/false,
cookieDomain: null,
enableKlarnaTracking: true,
checkoutPath: '/checkout',
}
</script>
<script src="https://cdn1.profitmetrics.io/PUBLIC_ID/bundle.js"
defer></script>
<!-- End ProfitMetrics - Script -> - ON LOAD EVENT
Copy and paste the onLoad event into the script on the pages where the customer email is available. This usually includes order confirmation, login, and newsletter signup.
onLoad event:onLoad: () => {
const pmEmail = 'EMAIL'; // Insert customer email
if (pmEmail?.match(/^[^\s@]+@[^\s@]+\.[^\s@]+$/)) {
profitMetrics.setEmail(pmEmail);
}
}Example:
<!-- Start ProfitMetrics - Script -->
<script>
window.profitMetrics = {
pid: 'PUBLIC_ID', // Your Public ID
emailInputSelector: '.class-name', // Email input CCS selector
cookieStatisticsConsent: true/false, // Replace with boolean value
cookieMarketingConsent: true/false, // Replace with boolean value
cookieDomain: null, // Your top-level domain
onLoad: () => {
const pmEmail = 'EMAIL'; // Replace with customer email
if (pmEmail?.match(/^[^\s@]+@[^\s@]+\.[^\s@]+$/)) {
profitMetrics.setEmail(pmEmail);
}
}
}
</script>
<script src="https://cdn1.profitmetrics.io/PUBLIC_ID/bundle.js"
defer></script>
<!-- End ProfitMetrics - Script --> - setEmail Event
For any situation where the customer email is available AFTER ProfitMetrics script has loaded, but the email is not able to be capture using the email input selector, you can manually trigger the setEamail event like this:
profitMetrics.setEmail('name@example.com');
Example:
<script>
profitMetrics.setEmail('name@example.com');
</script>
Part 2: OPTIONAL: Implement setEmail event to capture email when using a third-party checkout.
- Copy the following script and paste it AFTER the main script on the order confirmation page and replace example@example.com with a variable containing the customer email. The script will retry to set the customer email every 500 milliseconds ontil the email becomes available.
<!-- Start ProfitMetrics - setEmail -->
<script>
function _pm_tryemailorderconfirmation() {
if (null != window.profitMetrics && null != window.profitMetrics.setEmail && typeof window.profitMetrics.setEmail === 'function') {
window.profitMetrics.setEmail('example@example.com');
} else {
setTimeout(_pm_tryemailorderconfirmation, 500);
}
}
_pm_tryemailorderconfirmation();
</script>
<!-- End ProfitMetrics - setEmail -->
Part 3: Special code for known CMP's
Cookiebot
Native support. No additional changes are needed.
CookieInforation
Native support. No additional changes are needed.
CookieYes
<!--Start ProfitMetrics - Script for CookieYes -->
<script>
// Configuration
let pmPublicID = ''; // Replace with your Public ID
let pmEmailInputSelector = '.class-name'; // Email input CCS selector
let pmCookieDomain = ''; // Your top-level domain for cross-subdomain tracking
let pmEmail = ''; // Dynamically fetch email if available
// Default consent
let cc_statistics = true;
let cc_marketing = true;
// Function to load the ProfitMetrics script
function pmLoadScript() {
window.profitMetrics = {
pid: pmPublicID,
cookieStatisticsConsent: cc_statistics,
cookieMarketingConsent: cc_marketing,
emailInputSelector: pmEmailInputSelector,
onLoad: () => {
if (pmEmail && /^[^\s@]+@[^\s@]+\.[^\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);
}
// CookieYes - Get consent
if (typeof getCkyConsent !== 'undefined' && getCkyConsent()?.categories) {
cc_statistics = getCkyConsent().categories.performance;
cc_marketing = getCkyConsent().categories.advertising;
pmLoadScript();
}
// CookieYes - Add event listener
document.addEventListener("cookieyes_consent_update", (event) => {
cc_statistics = event.detail.accepted.includes("analytics");
cc_marketing = event.detail.accepted.includes("advertisement");
pmLoadScript();
});
// CookieYes - Fallback
if (typeof getCkyConsent === 'undefined') {
pmLoadScript();
}
</script>
<!-- End ProfitMetrics - Script for CookieYes -->
CookieFirst
<!--Start ProfitMetrics - Script for CookieFirst -->
<script>
// Configuration
let pmPublicID = ''; // Replace with your Public ID
let pmEmailInputSelector = '.class-name'; // Email input CCS selector
let pmCookieDomain = ''; // Your top-level domain for cross-subdomain tracking
let pmEmail = ''; // Dynamically fetch email if available
// Default consent
let cc_statistics = true;
let cc_marketing = true;
// Function to load the ProfitMetrics script
function pmLoadScript() {
window.profitMetrics = {
pid: pmPublicID,
cookieStatisticsConsent: cc_statistics,
cookieMarketingConsent: cc_marketing,
emailInputSelector: pmEmailInputSelector,
onLoad: () => {
if (pmEmail && /^[^\s@]+@[^\s@]+\.[^\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);
}
// CookieFirst
function updateConsent(consent) {
cc_statistics = consent.performance;
cc_marketing = consent.advertising;
pmLoadScript();
}
// CookieFirst - Get consent
if (typeof CookieFirst !== 'undefined' && !!CookieFirst?.consent) {
updateConsent(CookieFirst.consent);
}
// CookieFirst - Add event listener
window.addEventListener('cf_consent', (event) => updateConsent(event.detail));
window.addEventListener('cf_consent_loaded', (event) => updateConsent(event.detail));
// CookieFirst - Fallback
function checkAndLoadCookieFirst() {
if (typeof CookieFirst === 'undefined') {
setTimeout(() => {
if (typeof CookieFirst === 'undefined') {
pmLoadScript(); // Load the script if still undefined
}
}, 500); // Wait 500 milliseconds and check again
}
}
</script>
<!-- End ProfitMetrics - Script for CookieFirst -->
CookieScript
<!--Start ProfitMetrics - Script for CookieScript -->
<script>
// Configuration
let pmPublicID = ''; // Replace with your Public ID
let pmEmailInputSelector = '.class-name'; // Email input CCS selector
let pmCookieDomain = ''; // Your top-level domain for cross-subdomain tracking
let pmEmail = ''; // Dynamically fetch email if available
// Default consent
let cc_statistics = true;
let cc_marketing = true;
// Function to load the ProfitMetrics script
function pmLoadScript() {
window.profitMetrics = {
pid: pmPublicID,
cookieStatisticsConsent: cc_statistics,
cookieMarketingConsent: cc_marketing,
emailInputSelector: pmEmailInputSelector,
onLoad: () => {
if (pmEmail && /^[^\s@]+@[^\s@]+\.[^\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);
}
// CookieScript - Update
function updateConsent(consent) {
cc_statistics = consent.includes('performance');
cc_marketing = consent.includes('targeting');
pmLoadScript();
}
// CookieScript - Get consent
if (typeof CookieScript !== 'undefined' && CookieScript?.instance?.currentState()?.categories) {
updateConsent(CookieScript.instance.currentState().categories);
}
// CookieScript - Add event listener
window.addEventListener('CookieScriptCategory-strict', () => {
updateConsent(CookieScript.instance.currentState().categories);
});
// CookieFirst - Fallback
if (typeof CookieScript === 'undefined') {
pmLoadScript();
}
</script>
<!--End ProfitMetrics - Script for CookieScript -->
OneTrust
<!--Start ProfitMetrics - Script for OneTrust -->
<script>
// Configuration
let pmPublicID = ''; // Replace with your Public ID
let pmEmailInputSelector = '.class-name'; // Email input CCS selector
let pmCookieDomain = ''; // Your top-level domain for cross-subdomain tracking
let pmEmail = ''; // Dynamically fetch email if available
// Default consent
let cc_statistics = true;
let cc_marketing = true;
// Function to load the ProfitMetrics script
function pmLoadScript() {
window.profitMetrics = {
pid: pmPublicID,
cookieStatisticsConsent: cc_statistics,
cookieMarketingConsent: cc_marketing,
emailInputSelector: pmEmailInputSelector,
onLoad: () => {
if (pmEmail && /^[^\s@]+@[^\s@]+\.[^\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);
}
// OneTrust - Update
function updateConsent(consent) {
cc_statistics = consent.includes("2");
cc_marketing = consent.includes("4");
pmLoadScript();
}
// OneTrust - Get consent
if (typeof OneTrust !== "undefined" && typeof OnetrustActiveGroups !== "undefined") {
updateConsent(OnetrustActiveGroups);
}
// OneTrust - Add event listener
window.addEventListener("OneTrustGroupsUpdated", (event) => {
updateConsent(event.detail || []);
});
// OneTrust - Fallback
if (typeof OneTrust === "undefined") {
pmLoadScript();
}
</script>
<!-- End ProfitMetrics - Script for OneTrust -->
Part 4: Confirm the integration
- Check if the pmStorage cookie exists.
- Create a test order and complete it. On the order confirmation page, check if the pmStorage cookie has an "etid" value and / or if the "em" value contains you email. The cookie value should look like this:
{"etid":172978336,"pid":"A1B2C3D4E5F6G7H8","referer":null,"cc_statistics":true,"cc_marketing":true,"gacid":"GA1.1.1608251768.1705563035","gacid_source":"gacookie","uid":null,"gclid":null,"fbp":"fb.1.1705563034698.1103141032","fbc":null,"cip":"0.0.0.0","gbraid":"","wbraid":"","ga4SessionId":"5DP76XVKEZ:1705568293","ga4SessionNumber":"DP76XVKEZ5:2","em_md5":null,"em_sha256":null,"em":"example@example.com"}