Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.


Make sure that both the Mopinion deployment script and Optimizely are being loaded on the page. The following code must also be added to the page. This can be done using a tag manager or by hosting this script and then linking to it.


If you are on an Enterprise license, than we can host this script for you. In that case, please contact us at

The code snippet

Code Block
// Optimizely integration for Mopinion

// Check if optimizely object exists
function getMopinionOptimzelyData(){
    let results = [];
    if (typeof optimizely === 'object') {
        // Get experiment ID and variant ID from page, if available
        let state = optimizely.get('state')
        let activeExperiments = state.getActiveExperimentIds();
        let experimentStates = state.getExperimentStates();
        activeExperiments.forEach(id => {
            let result = {optimizely_experiment_id: id};
            result.optimizely_variant_id = experimentStates[id];
    return results;

// Make these ID's available for Mopinion website data element
var mopOptimizelyData = getMopinionOptimzelyData();

// Run once

function onCampaignDecided(event) {
    // Update results for activity where Optimizely activates a campaign or experiment
// Eventlistener
window["optimizely"] = window["optimizely"] || [];
type: "addListener",
filter: {
    type: "lifecycle",
    name: "campaignDecided"
handler: onCampaignDecided