Integrating Optimizely's experiment tools with Amplitude Analytics lets you share user data in real-time and helps non-technical product and marketing team members to do full-circle tracking, analysis, and engagement across web and mobile apps.
This integration is available to all customers who have access to Optimizely's Custom Analytics Integration feature.
Be sure you have the most recent Amplitude Browser SDK implemented. Also, you must place the Amplitude snippet before the Optimizely snippet.
To integrate Optimizely with Amplitude, follow these steps:
Log in to your Optimizely account, select a project, and navigate to Settings > Integrations. The URL should adhere to this format: https://app.optimizely.com/v2/projects/[PROJECT_ID]/settings/integrations
From the Create Analytics Integration.. dropdown, select Using JSON.
Insert the following code:
1{ 2 "plugin_type":"analytics_integration", 3 "name":"Amplitude Analytics Integration", 4 "form_schema":[ 5 { 6 "default_value":"[Optimizely Experiment]", 7 "field_type":"text", 8 "name":"property_prefix", 9 "label":"User Property Prefix: A user property for your experiment will be sent in an identify call. The user property will be prefixed with this prefix.",10 "options":null11 },12 {13 "default_value":"n",14 "field_type":"dropdown",15 "name":"send_event",16 "label":"Send Event: Optionally send an event with campaign, experiment, and variation info",17 "options":{18 "choices":[19 {20 "value":"n",21 "label":"No (not needed)"22 },23 {24 "value":"y",25 "label":"Yes"26 }27 ]28 }29 },30 {31 "default_value":"User in Experiment",32 "field_type":"text",33 "name":"event_name",34 "label":"Event Name (optional)",35 "options":null36 },37 {38 "default_value":"",39 "field_type":"text",40 "name":"instance_name",41 "label":"Instance Name (optional): The instance name you are using in your amplitude instrumentation eg: amplitude.getInstance('my instance name'). Usually this is blank.",42 "options":null43 }44 ],45 "description":"Send an identify call to amplitude identifying the experiment variation the user is seeing. Also, optionally send an event to amplitude that the user is in an experiment.\n\nSettings:",46 "options":{47 "track_layer_decision":"// VERSION 0.1.0\n// Last Updated: July 9th 2019\n\nvar dataSent = false;\nvar MAX_ATTEMPTS = 9;\nvar RETRY_DELAY_MS = 1000;\n\nfunction getCampaignInfo() {\n return window.optimizely\n .get(\"state\")\n .getDecisionObject({ campaignId: campaignId });\n}\n\nfunction logEvent() {\n var campaignInfo = getCampaignInfo();\n\n if (campaignInfo) {\n var eventProperties = {\n \"[Optimizely Campaign]\": campaignInfo.campaign,\n \"[Optimizely Experiment]\": campaignInfo.experiment,\n \"[Optimizely Variation]\": campaignInfo.variation,\n \"[Optimizely Holdback]\": campaignInfo.holdback\n };\n amplitude.getInstance(extension.instance_name).logEvent(extension.event_name, eventProperties);\n }\n}\n\nfunction identifyCall() {\n var campaignInfo = getCampaignInfo();\n\n if (campaignInfo) {\n var identify = new amplitude.Identify().set(\n extension.property_prefix + \" \" + campaignInfo.experiment,\n campaignInfo.variation\n );\n amplitude.getInstance(extension.instance_name).identify(identify);\n }\n}\n\nfunction sendData() {\n if (!dataSent) {\n identifyCall();\n if (extension.send_event === \"y\") {\n logEvent();\n }\n }\n dataSent = true;\n}\n\nfunction sendToAmplitude(call) {\n if (call >= MAX_ATTEMPTS) {\n return;\n }\n \n var instanceKey = extension.instance_name || \"$default_instance\";\n\n if (window.amplitude && window.amplitude.getInstance) {\n var instance = window.amplitude.getInstance(extension.instance_name);\n \n if (instance._isInitialized) {\n return sendData();\n } else if (instance.onInit) {\n instance.onInit(function() {\n sendData();\n });\n return;\n }\n }\n \n return setTimeout(function() {\n sendToAmplitude(call + 1);\n }, RETRY_DELAY_MS);\n}\nsendToAmplitude(0);"48 }49}
Turn the integration from Optimizely's Project Settings page. It's listed as Amplitude Analytics Integration.
Navigate to an experiment that's generating data that you want in Amplitude. In the Optimizely experiment settings panel, go to Integrations, and enable Tracked for the Amplitude Analytics Integration.
You can also take this opportunity to adjust the following settings:
Save your settings.
When the Optimizely experiment is running and collecting data, the user properties for this experiment appear in Amplitude.
Thanks for your feedback!
April 22nd, 2024
Need help? Contact Support
Visit Amplitude.com
Have a look at the Amplitude Blog
Learn more at Amplitude Academy
© 2024 Amplitude, Inc. All rights reserved. Amplitude is a registered trademark of Amplitude, Inc.