Experiment JS Client Documentation - v1.24.0
    Preparing search index...

    Interface ExposureTrackingProvider

    Interface for enabling tracking Exposures through the ExperimentClient.

    If you're using the Amplitude Analytics SDK for tracking you do not need to implement this interface. Simply initialize experiment using the Experiment.initializeWithAmplitudeAnalytics function.

    If you're using a 3rd party analytics implementation then you'll need to implement the sending of the analytics event yourself. The implementation should result in the following event getting sent to amplitude:

    {
    "event_type": "$exposure",
    "event_properties": {
    "flag_key": "<flagKey>",
    "variant": "<variant>",
    "experiment_key": "<expKey>"
    }
    }

    For example, if you're using Segment for analytics:

    analytics.track('$exposure', exposure)
    

    If the exposure has a variant and the user has groups, the groups are passed as the second argument to ExposureTrackingProvider.track. Send them as event-level groups, not as event properties, so group-unit experiments count the exposure. For example, with the Amplitude Analytics SDK:

    amplitude.track('$exposure', exposure, { groups })
    
    interface ExposureTrackingProvider {
        track(exposure: Exposure, groups?: Record<string, string[]>): void;
    }
    Index

    Methods

    Methods

    • Called when the ExperimentClient intends to track an exposure event; either when ExperimentClient.variant serves a variant (and ExperimentConfig.automaticExposureTracking is true) or if ExperimentClient.exposure is called.

      The implementation should result in the following event getting sent to amplitude:

      {
      "event_type": "$exposure",
      "event_properties": {
      "flag_key": "<flagKey>",
      "variant": "<variant>",
      "experiment_key": "<expKey>"
      }
      }

      For example, if you're using Segment for analytics:

      analytics.track('$exposure', exposure)
      

      Parameters

      • exposure: Exposure

        the exposure to track.

      • Optionalgroups: Record<string, string[]>

        (Optional) the groups of the user the variant was evaluated for. Omitted if the user has no groups, if the exposure has no variant, or if the user has more than 10 group values in total. Send these as event-level groups.

      Returns void