Optimizely's Custom Analytics feature</a>.</p>\n<ol>\n<li>Log into Optimizely at optimizely.com</li>\n<li>Navigate to the Optimizely project in which you want to use the integration</li>\n<li>Click on <em><strong>Settings</strong></em> in the left navigation bar, and then <em><strong>Integration</strong></em></li>\n<li>You'll see a blue button titled <em><strong>&quot;Create New Analytics Integration...&quot;</strong></em></li>\n<li>In the dropdown menu, select &quot;Using JSON&quot;</li>\n<li>Paste the following code:</li>\n</ol>\n<pre><code class=\"language-json\">{\n &quot;plugin_type&quot;: &quot;analytics_integration&quot;,\n &quot;name&quot;: &quot;ContentSquare&quot;,\n &quot;form_schema&quot;: [],\n &quot;description&quot;: &quot;This integration allows you to send the experiment and variation data from Optimizely Web to ContentSquare&quot;,\n &quot;options&quot;: {\n &quot;track_layer_decision&quot;: &quot;/*\\n *Name: Optimizely CS Integration\\n *Version: 2.1\\n */\\n(function () {\\n var tvp = \\&quot;AB_OP_\\&quot;;\\n\\n function sendToCS(csKey, csValue) {\\n csKey = tvp + csKey;\\n\\n _uxa.push([\\&quot;trackDynamicVariable\\&quot;, {\\n key: csKey,\\n value: csValue\\n }]);\\n };\\n\\n function startOPIntegration(decisionString) {\\n sendToCS(decisionString.experiment, decisionString.holdback ? decisionString.variation + ' [Holdback]' : decisionString.variation);\\n }\\n\\n function callback() {\\n if (!disableCallback) {\\n disableCallback = true;\\n\\n var decisionString = optimizely.get('state').getDecisionObject({\\n \\&quot;campaignId\\&quot;: campaignId\\n });\\n\\n if (!!decisionString) {\\n startOPIntegration(decisionString);\\n }\\n\\n if (window.CS_CONF) {\\n CS_CONF.integrations = CS_CONF.integrations || [];\\n CS_CONF.integrations.push(\\&quot;Optimizely\\&quot;);\\n }\\n }\\n }\\n\\n var disableCallback = false;\\n window._uxa = window._uxa || [];\\n _uxa.push([\\&quot;afterPageView\\&quot;, callback]);\\n\\n})();&quot;\n }\n}\n</code></pre>\n<h3>Using the integration</h3>\n<p>Before using this integration, you'll need to enable it in the <a href=https://www.optimizely.com/"https://help.optimizely.com/Integrate_Other_Platforms/Custom_analytics_integrations_in_Optimizely_X#Enable_an_integration\">project settings</a>.</p>\n<p>Moving forward, this integration will be turned on by default for every new experiment you create in Optimizely Web.</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<p>If everything works properly, you should see in ContentSquare a Dynamic Variable called <code>AB_OP_</code> followed by the experiment name or id.\t\nExample: <code>AB_OP_(18180652355)</code> where 18180652355 is the experimentId. The value of this ContentSquare dynamic variable will be the variation Ids of this experiment.</p>\n<h3>Integration Code</h3>\n<p>If you're interested in checking out the code that powers this integration, here it is:</p>\n<pre><code class=\"language-javascript\">/*\n *Name: Optimizely CS Integration\n *Version: 2.1\n */\n(function () {\n var tvp = &quot;AB_OP_&quot;;\n\n function sendToCS(csKey, csValue) {\n csKey = tvp + csKey;\n\n _uxa.push([&quot;trackDynamicVariable&quot;, {\n key: csKey,\n value: csValue\n }]);\n };\n\n function startOPIntegration(decisionString) {\n sendToCS(decisionString.experiment, decisionString.holdback ? decisionString.variation + ' [Holdback]' : decisionString.variation);\n }\n\n function callback() {\n if (!disableCallback) {\n disableCallback = true;\n\n var decisionString = optimizely.get('state').getDecisionObject({\n &quot;campaignId&quot;: campaignId\n });\n\n if (!!decisionString) {\n startOPIntegration(decisionString);\n }\n\n if (window.CS_CONF) {\n CS_CONF.integrations = CS_CONF.integrations || [];\n CS_CONF.integrations.push(&quot;Optimizely&quot;);\n }\n }\n }\n\n var disableCallback = false;\n window._uxa = window._uxa || [];\n _uxa.push([&quot;afterPageView&quot;, callback]);\n\n})();\n</code></pre>\n","labels":"integrations, web, analytics","revisionDate":"2020-08-19","resourceFile":null,"resourceFileName":null,"author":null,"repositoryUrl":"https://raw.githubusercontent.com/optimizely/labs/master/labs/contentsquare-integration-web/README.md","labelsLabel":"Labels","publishedLabel":"Published","resourcesLabel":"Resources","repositoryLabel":"Repository","authorLabel":"Author"}" data-redux="false" data-router="false">

ContentSquare Integration for Optimizely Web

Hello! This integration allows you to send experiment and variation data from Optimizely into ContentSquare.

Pre-requisites

You need a ContentSquare and Optimizely Web account.

Installation

This integration is using Optimizely's Custom Analytics feature.

  1. Log into Optimizely at optimizely.com
  2. Navigate to the Optimizely project in which you want to use the integration
  3. Click on Settings in the left navigation bar, and then Integration
  4. You'll see a blue button titled "Create New Analytics Integration..."
  5. In the dropdown menu, select "Using JSON"
  6. Paste the following code:
{
  "plugin_type": "analytics_integration",
  "name": "ContentSquare",
  "form_schema": [],
  "description": "This integration allows you to send the experiment and variation data from Optimizely Web to ContentSquare",
  "options": {
    "track_layer_decision": "/*\n *Name: Optimizely CS Integration\n *Version: 2.1\n */\n(function () {\n    var tvp = \"AB_OP_\";\n\n    function sendToCS(csKey, csValue) {\n        csKey = tvp + csKey;\n\n        _uxa.push([\"trackDynamicVariable\", {\n            key: csKey,\n            value: csValue\n        }]);\n    };\n\n    function startOPIntegration(decisionString) {\n        sendToCS(decisionString.experiment, decisionString.holdback ? decisionString.variation + ' [Holdback]' : decisionString.variation);\n    }\n\n    function callback() {\n        if (!disableCallback) {\n            disableCallback = true;\n\n            var decisionString = optimizely.get('state').getDecisionObject({\n                \"campaignId\": campaignId\n            });\n\n            if (!!decisionString) {\n                startOPIntegration(decisionString);\n            }\n\n            if (window.CS_CONF) {\n                CS_CONF.integrations = CS_CONF.integrations || [];\n                CS_CONF.integrations.push(\"Optimizely\");\n            }\n        }\n    }\n\n    var disableCallback = false;\n    window._uxa = window._uxa || [];\n    _uxa.push([\"afterPageView\", callback]);\n\n})();"
  }
}

Using the integration

Before using this integration, you'll need to enable it in the project settings.

Moving forward, this integration will be turned on by default for every new experiment you create in Optimizely Web.

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

If everything works properly, you should see in ContentSquare a Dynamic Variable called AB_OP_ followed by the experiment name or id. Example: AB_OP_(18180652355) where 18180652355 is the experimentId. The value of this ContentSquare dynamic variable will be the variation Ids of this experiment.

Integration Code

If you're interested in checking out the code that powers this integration, here it is:

/*
 *Name: Optimizely CS Integration
 *Version: 2.1
 */
(function () {
    var tvp = "AB_OP_";

    function sendToCS(csKey, csValue) {
        csKey = tvp + csKey;

        _uxa.push(["trackDynamicVariable", {
            key: csKey,
            value: csValue
        }]);
    };

    function startOPIntegration(decisionString) {
        sendToCS(decisionString.experiment, decisionString.holdback ? decisionString.variation + ' [Holdback]' : decisionString.variation);
    }

    function callback() {
        if (!disableCallback) {
            disableCallback = true;

            var decisionString = optimizely.get('state').getDecisionObject({
                "campaignId": campaignId
            });

            if (!!decisionString) {
                startOPIntegration(decisionString);
            }

            if (window.CS_CONF) {
                CS_CONF.integrations = CS_CONF.integrations || [];
                CS_CONF.integrations.push("Optimizely");
            }
        }
    }

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

})();
Additional links