-
Notifications
You must be signed in to change notification settings - Fork 1
feat: support exposure tracking #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
47ceaf4
feat: support exposure tracking
vaibhav-jain-exp 150cc3f
feat: support exposure tracking
vaibhav-jain-exp 1faa852
fix: update logger import
vaibhav-jain-exp e714c78
Remove always-empty $unset object from userProperties in Exposure.toA…
macroscopeapp[bot] 07da4db
Check if toAmplitudeEvents() returns non-empty list before tracking E…
vaibhav-jain-exp a61586d
nit: rename trackExposure to tracksExposure
vaibhav-jain-exp 310d49c
Merge branch 'support-exposure-tracking' of https://github.com/amplit…
vaibhav-jain-exp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package com.amplitude.exposure | ||
|
|
||
| import com.amplitude.experiment.evaluation.EvaluationContext | ||
| import com.amplitude.experiment.evaluation.EvaluationVariant | ||
| import com.amplitude.util.deviceId | ||
| import com.amplitude.util.userId | ||
|
|
||
| internal const val DAY_MILLIS: Long = 24 * 60 * 60 * 1000 | ||
|
|
||
| internal data class Exposure( | ||
| val context: EvaluationContext, | ||
| val results: Map<String, EvaluationVariant>, | ||
| val timestamp: Long = System.currentTimeMillis(), | ||
| ) | ||
|
|
||
| internal fun Exposure.canonicalize(): String { | ||
| val sb = StringBuilder().append(this.context.userId()?.trim(), " ", this.context.deviceId()?.trim(), " ") | ||
| for (key in this.results.keys.sorted()) { | ||
| val variant = this.results[key] | ||
| sb.append(key.trim(), " ", variant?.key?.trim(), " ") | ||
| } | ||
| return sb.toString() | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package com.amplitude.exposure | ||
|
|
||
| import com.amplitude.util.Cache | ||
|
|
||
| internal interface ExposureFilter { | ||
| suspend fun shouldTrack(exposure: Exposure): Boolean | ||
| } | ||
|
|
||
| internal class InMemoryExposureFilter(size: Int) : ExposureFilter { | ||
| // Cache of canonical exposure to the last sent timestamp. | ||
| private val cache = Cache<String, Unit>(size, DAY_MILLIS) | ||
|
|
||
| override suspend fun shouldTrack(exposure: Exposure): Boolean { | ||
| val canonicalExposure = exposure.canonicalize() | ||
| val track = cache.get(canonicalExposure) == null | ||
| if (track) { | ||
| cache.set(canonicalExposure, Unit) | ||
| } | ||
| return track | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering if we should just canonicalize userId and deviceId while having full context being part of Exposure object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you elaborate?