Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Nils-van-Kleef/8625d772e104ef0f4825588c21a598c3 to your computer and use it in GitHub Desktop.
Save Nils-van-Kleef/8625d772e104ef0f4825588c21a598c3 to your computer and use it in GitHub Desktop.
Integration of ContentSquare with Optimizely. Use in Custom Analytics Integrations
{
"plugin_type": "analytics_integration",
"name": "ContentSquare",
"form_schema": [
{
"default_value": "1",
"field_type": "dropdown",
"name": "customVar",
"label": "customVar",
"options": {
"choices": [
{
"value": "1",
"label": "Custom Var1"
},
{
"value": "2",
"label": "Custom Var2"
},
{
"value": "3",
"label": "Custom Var3"
},
{
"value": "4",
"label": "Custom Var4"
},
{
"value": "5",
"label": "Custom Var5"
},
{
"value": "6",
"label": "Custom Var6"
},
{
"value": "7",
"label": "Custom Var7"
},
{
"value": "8",
"label": "Custom Var8"
},
{
"value": "9",
"label": "Custom Var9"
},
{
"value": "10",
"label": "Custom Var10"
},
{
"value": "11",
"label": "Custom Var11"
},
{
"value": "12",
"label": "Custom Var12"
},
{
"value": "13",
"label": "Custom Var13"
},
{
"value": "14",
"label": "Custom Var14"
},
{
"value": "15",
"label": "Custom Var15"
},
{
"value": "16",
"label": "Custom Var16"
},
{
"value": "17",
"label": "Custom Var17"
},
{
"value": "18",
"label": "Custom Var18"
},
{
"value": "19",
"label": "Custom Var19"
},
{
"value": "20",
"label": "Custom Var20"
}
]
}
}
],
"description": "Send experiment and variant IDs to ContentSquare",
"options": {
"track_layer_decision": "function sendTestToCS(customVar, key, experience) {\n window.CSexperienceVar = window.CSexperienceVar || [];\n window._uxa = window._uxa || [];\n \n // force concatenated experiences to string\n if (typeof window.CSexperienceVar[customVar] !== 'string') {\n window.CSexperienceVar[customVar] = '';\n }\n \n // get array of experiences;\n var experiences = window.CSexperienceVar[customVar] ? window.CSexperienceVar[customVar].split(',') : [];\n \n // add this experience if not already in the array\n if (experiences.indexOf(experience) === -1) {\n experiences.push(experience);\n }\n \n // join experiences comma separated\n window.CSexperienceVar[customVar] = experiences.join(',');\n \n // handles if array is present but content square hasn't initialised\n // If pushing into the same custom variable, delete existing info for this custom variable\n for (var i = 0; i < window._uxa.length; i++) {\n if (window._uxa[i] && window._uxa[i][2] === key && window._uxa[i][1] === customVar) {\n window._uxa.splice(i, 1);\n }\n }\n \n // push custom variables\n window._uxa.push(['setCustomVariable', customVar, key, window.CSexperienceVar[customVar], 3]);\n \n // If content square has already run, send a pageview\n if (typeof window.CS_CONF === 'object') {\n window._uxa.push(['trackPageview', window.location.pathname + '?cs-asyncVariantsFnFired' + window.location.hash.replace('#', '?__')]);\n window.CSexperienceVar = [];\n }\n}\n\n// Trigger it\nvar experienceGenerated = experimentId + '|' + variationId;\nsendTestToCS(extension.customVar, 'testVariants', experienceGenerated);\n"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment