Optimizely's Notification Listeners</a> to retrieve the Optimizely experiment and variation data and send them to ContentSquare.</p>\n<p>This integration is built to be used with Optimizely's Full Stack client-side SDKs (Javascript, React, React Native). Server-side Optimizely Full Stack SDKs are <em><strong>not</strong></em> supported by this integration.</p>\n<ul>\n<li>Just after calling Optimizely's <code>createInstance()</code> method, run this code:</li>\n</ul>\n<pre><code class=\"language-javascript\">var optimizelyEnums = require('@optimizely/optimizely-sdk').enums;\n\nfunction onDecision(decisionObject) {\n\n\tfunction callback(context) {\n\t\tif (!disableCallback) {\n\t\t\tdisableCallback = true;\n\t\t\tif (window.CS_CONF) {\n\t\t\t\tCS_CONF.integrations = CS_CONF.integrations || [];\n\t\t\t\tCS_CONF.integrations.push(&quot;Optimizely Full Stack&quot;);\n\t\t\t}\n\t\t}\n\t}\n\n\tvar disableCallback = false;\n\t_uxa.push([&quot;afterPageView&quot;, callback]);\n\n\tvar csPrefix = 'AB_OP_', csKey, csValue;\n\tcsKey = csPrefix + decisionObject.experiment.key;\n\tcsValue = decisionObject.variation.key;\n\t\n\twindow._uxa = window._uxa || []; \n\twindow._uxa.push([&quot;trackDynamicVariable&quot;, {key: csKey, value: csValue} ]);\n}\n\n// Replace OptimizelyClient with the name of your Optimizely SDK Instance (where createInstance is used)\noptimizelyClient.notificationCenter.addNotificationListener(\n\toptimizelyEnums.NOTIFICATION_TYPES.ACTIVATE,\n\tonDecision,\n);\n</code></pre>\n<ul>\n<li>That's it!</li>\n</ul>\n<p>On every experiment activation (method <code>activate()</code> or <code>isFeatureEnabled</code> is invoked), then an Optimizely's Notification Listener will execute, grabbing the experiment data from Optimizely and will forward them to ContentSquare.</p>\n<h3>Using the integration</h3>\n<p>If everything works properly, you should see in ContentSquare a Dynamic Variable called <code>AB_OP_</code> followed by the campaign Id and experiment Id.\t\nExample: <code>AB_OP_18180652355_18182752153</code> where 18180652355 is the campaign Id and 18182752153 the experiment Id. The value of this ContentSquare dynamic variable will be the variation Ids of this experiment.</p>\n<p>We recommend to run an A/A experiment to validate that you are able to see data coming through in ContentSquare.</p>\n","labels":"integrations, full stack, analytics","revisionDate":"2020-08-19","resourceFile":null,"resourceFileName":null,"author":null,"repositoryUrl":"https://raw.githubusercontent.com/optimizely/labs/master/labs/contentsquare-integration-full-stack/README.md","labelsLabel":"Labels","publishedLabel":"Published","resourcesLabel":"Resources","repositoryLabel":"Repository","authorLabel":"Author"}" data-redux="false" data-router="false">

ContentSquare Integration

Hello! This integration allows you to send data from Optimizely Full Stack into ContentSquare.

Pre-requisites

You need a ContentSquare and Optimizely account.

Installation

This integration uses Optimizely's Notification Listeners to retrieve the Optimizely experiment and variation data and send them to ContentSquare.

This integration is built to be used with Optimizely's Full Stack client-side SDKs (Javascript, React, React Native). Server-side Optimizely Full Stack SDKs are not supported by this integration.

  • Just after calling Optimizely's createInstance() method, run this code:
var optimizelyEnums = require('@optimizely/optimizely-sdk').enums;

function onDecision(decisionObject) {

	function callback(context) {
		if (!disableCallback) {
			disableCallback = true;
			if (window.CS_CONF) {
				CS_CONF.integrations = CS_CONF.integrations || [];
				CS_CONF.integrations.push("Optimizely Full Stack");
			}
		}
	}

	var disableCallback = false;
	_uxa.push(["afterPageView", callback]);

	var csPrefix = 'AB_OP_', csKey, csValue;
	csKey = csPrefix + decisionObject.experiment.key;
	csValue = decisionObject.variation.key;
	
	window._uxa = window._uxa || []; 
	window._uxa.push(["trackDynamicVariable", {key: csKey, value: csValue} ]);
}

// Replace OptimizelyClient with the name of your Optimizely SDK Instance (where createInstance is used)
optimizelyClient.notificationCenter.addNotificationListener(
	optimizelyEnums.NOTIFICATION_TYPES.ACTIVATE,
	onDecision,
);
  • That's it!

On every experiment activation (method activate() or isFeatureEnabled is invoked), then an Optimizely's Notification Listener will execute, grabbing the experiment data from Optimizely and will forward them to ContentSquare.

Using the integration

If everything works properly, you should see in ContentSquare a Dynamic Variable called AB_OP_ followed by the campaign Id and experiment Id. Example: AB_OP_18180652355_18182752153 where 18180652355 is the campaign Id and 18182752153 the experiment Id. The value of this ContentSquare dynamic variable will be the variation Ids of this experiment.

We recommend to run an A/A experiment to validate that you are able to see data coming through in ContentSquare.

Additional links