Optimizely Integration
Prerequisites
Before starting, you'll need:
- Your Optimizely Project ID
To find your Project ID, log in to Optimizely, go to Settings >
Implementation, and look for the 8-digit number in your snippet URL. For
example, in https://cdn.optimizely.com/js/12345678.js, your Project ID is
12345678.
Integrate Optimizely with Consenter
Important: Before using this code, verify that the service ID and purpose ID values are up to date. These IDs are specific to your Consenter configuration. To find the correct IDs, go to Consenter Manager → Your Site → Active Banner → Hover over the service and purpose labels and click the copy button in the tooltip. See the Integration Guides page for detailed instructions.
Copy the code below and paste it into your website's <head> section.
Replace the placeholders with your own values:
YOUR_SERVICE_ID→ Your Optimizely service ID from Consenter ManagerYOUR_PURPOSE_ID→ Your purpose ID from Consenter ManagerYOUR_PROJECT_ID→ Your 8-digit Optimizely Project ID
<script>
var serviceId = "YOUR_SERVICE_ID"; // Replace with your service ID from Consenter Manager
var purposeId = "YOUR_PURPOSE_ID"; // Replace with your purpose ID from Consenter Manager
var projectId = "YOUR_PROJECT_ID";
function loadOptimizely() {
var existingScript = document.querySelector(
'script[src*="cdn.optimizely.com"]',
);
if (existingScript) return;
var script = document.createElement("script");
script.src = "https://cdn.optimizely.com/js/" + projectId + ".js";
document.head.appendChild(script);
}
function removeOptimizely() {
window.optimizely.push({ type: "disable" });
var scripts = document.querySelectorAll(
'script[src*="cdn.optimizely.com"]',
);
scripts.forEach(function (script) {
script.remove();
});
window.optimizely = [];
}
window.consenter.subscribe(
function (hasConsent) {
if (hasConsent) {
loadOptimizely();
} else {
removeOptimizely();
}
},
serviceId,
purposeId,
);
</script>Optimizely is now connected to Consenter.
Last updated on