-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathconfig.json
42 lines (42 loc) · 2.67 KB
/
config.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
{
"plugin_type": "analytics_integration",
"name": "Amplitude Analytics Integration",
"form_schema": [
{
"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.",
"default_value": "[Optimizely Experiment]",
"field_type": "text",
"name": "property_prefix",
"options": null
},
{
"label": "Send Event: Optionally send an event with campaign, experiment, and variation info",
"default_value": "n",
"field_type": "dropdown",
"name": "send_event",
"options": {
"choices": [
{
"value": "n",
"label": "No (not needed)"
},
{
"value": "y",
"label": "Yes"
}
]
}
},
{
"label": "Event Name (optional)",
"default_value": "User in Experiment",
"field_type": "text",
"name": "event_name",
"options": null
}
],
"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:",
"options": {
"track_layer_decision": "// VERSION 0.2.0\n// Last Updated: August 30th 2024\n\nconst MAX_ATTEMPTS = 9;\nconst RETRY_DELAY_MS = 1000;\n\nconst logEvent = ({campaign, experiment, variation, holdback}) => {\n\tconst eventProperties = {\n\t\t'[Optimizely Campaign]': campaign,\n\t\t'[Optimizely Experiment]': experiment,\n\t\t'[Optimizely Variation]': variation,\n\t\t'[Optimizely Holdback]': holdback\n\t};\n\n\twindow.amplitude.logEvent(extension.event_name, eventProperties);\n};\n\nconst identifyCall = ({experiment, variation, holdback}) => {\n\tif (!holdback) {\n\t\tconst identifyEvent = new window.amplitude.Identify();\n\t\tidentifyEvent.set(`${extension.property_prefix} ${experiment}`, variation);\n\n\t\twindow.amplitude.identify(identifyEvent);\n\t}\n};\n\nconst sendData = () => {\n\tconst campaignInfo = window.optimizely\n\t\t.get('state')\n\t\t.getDecisionObject({ campaignId });\n\n\tif (campaignInfo) {\n\t\t// Always send identify event\n\t\tidentifyCall(campaignInfo);\n\t\tif (extension.send_event === 'y') {\n\t\t\t// Only log event if so configured\n\t\t\tlogEvent(campaignInfo);\n\t\t}\n\t}\n};\n\nconst sendToAmplitude = (numberOfAttempts) => {\n\tif (window.amplitude) {\n\t\t// Send data to Amplitude\n\t\tsendData();\n\t} else {\n\t\t// Retry until Amplitude is initialized\n\t\tif (numberOfAttempts < MAX_ATTEMPTS) {\n\t\t\tsetTimeout(() => {\n\t\t\t\tsendToAmplitude(numberOfAttempts + 1);\n\t\t\t}, RETRY_DELAY_MS);\n\t\t}\n\t}\n};\n\nsendToAmplitude(0);"
}
}