11/**
2- * Improved exposure event for tracking exposures to Amplitude Experiment.
2+ * Event object for tracking exposures to Amplitude Experiment.
33 *
44 * This object contains all the required information to send an `$exposure`
5- * event through any SDK or CDP to experiment. The resulting exposure event
6- * must follow the following definition:
5+ * event through any SDK or CDP to experiment.
6+ *
7+ * The resulting exposure event must follow the following definition:
78 * ```
89 * {
910 * "event_type": "$exposure",
1011 * "event_properties": {
1112 * "flag_key": "<flagKey>",
12- * "variant": "<variant>"
13+ * "variant": "<variant>",
14+ * "experiment_key": "<expKey>"
1315 * }
1416 * }
1517 * ```
1618 *
17- * Where `<flagKey>` and `<variant >` are the {@link flag_key} and
18- * {@link variant} variant` members on this type.
19+ * Where `<flagKey>`, `<variant>`, and `<expKey >` are the {@link flag_key},
20+ * {@link variant}, and { @link experiment_key} variant members on this type:
1921 *
2022 * For example, if you're using Segment for analytics:
2123 *
2426 * ```
2527 */
2628export type Exposure = {
29+ /**
30+ * (Required) The key for the flag the user was exposed to.
31+ */
2732 flag_key : string ;
33+ /**
34+ * (Optional) The variant the user was exposed to. If null or missing, the
35+ * event will not be persisted, and will unset the user property.
36+ */
2837 variant ?: string ;
38+ /**
39+ * (Optional) The experiment key used to differentiate between multiple
40+ * experiments associated with the same flag.
41+ */
42+ experiment_key ?: string ;
2943} ;
3044
3145/**
3246 * Interface for enabling tracking {@link Exposure}s through the
3347 * {@link ExperimentClient}.
3448 *
3549 * If you're using the Amplitude Analytics SDK for tracking you do not need
36- * to implement this interface. Simply upgrade your analytics SDK version to
37- * 2.36.0+ and initialize experiment using the
50+ * to implement this interface. Simply initialize experiment using the
3851 * {@link Experiment.initializeWithAmplitudeAnalytics} function.
3952 *
4053 * If you're using a 3rd party analytics implementation then you'll need to
@@ -46,7 +59,8 @@ export type Exposure = {
4659 * "event_type": "$exposure",
4760 * "event_properties": {
4861 * "flag_key": "<flagKey>",
49- * "variant": "<variant>"
62+ * "variant": "<variant>",
63+ * "experiment_key": "<expKey>"
5064 * }
5165 * }
5266 * ```
@@ -72,7 +86,8 @@ export interface ExposureTrackingProvider {
7286 * "event_type": "$exposure",
7387 * "event_properties": {
7488 * "flag_key": "<flagKey>",
75- * "variant": "<variant>"
89+ * "variant": "<variant>",
90+ * "experiment_key": "<expKey>"
7691 * }
7792 * }
7893 * ```
0 commit comments