amplitude / experiment-js-client

Amplitude Experiment client-side SDK for JavaScript
MIT License
7 stars 7 forks source link

Exposure Events with automatic tracking and third-party analytics #113

Closed adrianostas closed 4 months ago

adrianostas commented 4 months ago

Hey!

We have implemented the experiment-js-client in a Nuxt 3 app. We are using automaticExposureTracking with exposureTrackingProvider but it seems that the event is fired only when calling variant() for the first time. All subsequent variant() calls do not fire an exposure event. I'm not sure if this is expected since the docs mention that every variant() call should fire an exposure event.

bgiori commented 4 months ago

Hey @adrianostas,

This is expected. The SDK uses an in memory cache of the last exposure sent for each flag/experiment to filter duplicate exposures for that same flag/experiment & variant.

pocketcolin commented 2 months ago

@bgiori Would you be able to explain the rationale for preventing multiple exposure events per session? I understand the desire to prevent true duplicate exposures, but if it's possible to be "exposed" to an experiment multiple times in a single session then wouldn't we want to track that?

Also, it is possible to track a user being exposed to the same experiment multiple times, it just requires that they reload the page which (I'm assuming) clears Amplitude's memory. It seems to me that we would either want to prevent all duplicate exposure tracking (i.e., you can only log 1 exposure event per user per experiment) or we would want to allow multiple exposure events per session. By only allowing duplicate exposures to be tracked when a user reloads the page, we get inconsistent and unpredictable tracking behavior.