Solved

Exposure Events Tracking

  • 29 March 2023
  • 7 replies
  • 368 views

Badge

Hi Amplitude Community

I am trying to launch my first experiment and trying to track exposure event

However the docs seem to not have been updated.

What is the correct code to track exposure event.

I am using this 

amplitude.track(        "$exposure",        (Map<String, ? extends Object>) new Properties()                .put("exposure.getFlagKey()",exposure.getVariant()));}

 

but I feel this is not the right way

Could someone please help me out?

 

 

icon

Best answer by Jon Shek 3 April 2023, 22:22

View original

7 replies

Userlevel 6
Badge +9

Thanks for posting here @invictus. Is this the documentation you are referencing? 

This code uses the IdentifiedExposureEvent class provided by the Amplitude SDK. The experimentId parameter is the unique identifier for your experiment, the experimentName parameter is the name of your experiment, the variationId parameter is the unique identifier for the variation, and the variationName parameter is the name of the variation.

Here’s an example:

amplitude.logEvent(new IdentifiedExposureEvent("experiment_123", "My Experiment", "variation_a", "Variation A"));
 

Badge

Hi Jeremie, thanks for your reply

The exact documentation I am refering to is this one https://www.docs.developers.amplitude.com/experiment/sdks/android-sdk/#exposure-tracking-provider

since I am using Android Experimentation SDK and my code is in android

Here, there is no mention of  IdentifiedExposureEvent class. 

Even when I am implementing the code you gave above in my codebase, I am not getting any mention of importing that class

I am using

 dependencies { implementation 'com.amplitude:experiment-android-client:1.5.1+' }

sdk in my android code

 

Badge

Tried again...but still nowhere near to the implementation.. please help us out Jeremie/ Team Amplitude 

Userlevel 6
Badge +9

Thanks @invictus I’ll make sure our support team takes a look.

Userlevel 1
Badge +1

Hi @invictus, if you're using an Amplitude Analytics SDK with the Android Experiment SDK, you don’t need to use the exposureTrackingProvider. Whenever you call .variant(), it will automatically fire an Exposure event. See this snippet in the doc:

Using the integration initializer will automatically configure implementations of the user provider and exposure tracking provider interfaces to pull user data from the Amplitude Analytics SDK and track exposure events.

Badge

Hi @Jon Shek thank you for your reply.

I have few questions

  1. How will it know which events to be considered and tracked as exposure events in the code? How will it differentiate it from the normally used events ( “normally used events” are those which were already there in the previous version of code too and are not newly added like the new events introduced with the new features that we are adding)
  2. Suppose we want to explicitly assign some events in the code as exposure events. So how would we do that?
  3. Do we need to include ExperimentClient experiment = Experiment.initializeWithAmplitudeAnalytics( context, "<DEPLOYMENT_KEY>", new ExperimentConfig()); in every activity that we want to track exposure events?

Thanks in advance 

Invictus

Userlevel 1
Badge +1
  1. Exposure events will only be fired when you call .variant() - other events are logged through different methods such as track() or logEvent().
  2. If for some reason you opted to not use the Amplitude [Experiment] Exposure event, you can continue to send your normal events as is, then in the Plan tab of your Experiment, you can choose a custom Exposure event instead, and specify that particular event. Note that this is not recommended unless you’re familiar with Analytics, since this can be hard to keep track of once an Experiment has concluded. 
  3. No that should be initialized just once, after you’ve initialized Analytics. You would only need to fetch() and variant() in every activity where you want to track Exposure events. 

Reply