Skip to content

Commit

Permalink
PR fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
maciejburda committed Jan 24, 2025
1 parent 6ac27c2 commit f95e57a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ object Rum {
sdkCore.registerFeature(rumFeature)

sdkCore.getFeature(rumFeature.name)?.dataStore?.let {
val anonymousIdentifierManager = AnonymousIdentifierManager(
AnonymousIdentifierManager.manageAnonymousId(
rumConfiguration.featureConfiguration.trackAnonymousUser,
it,
sdkCore
)
anonymousIdentifierManager.manageAnonymousId(rumConfiguration.featureConfiguration.trackAnonymousUser)
}

val rumMonitor = createMonitor(sdkCore, rumFeature)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,35 @@ import com.datadog.android.core.persistence.Serializer
import com.datadog.android.core.persistence.datastore.DataStoreContent
import java.util.UUID

internal interface AnonymousIdentifierManaging {
fun manageAnonymousId(shouldTrack: Boolean)
}

internal class AnonymousIdentifierManager(
private val dataStore: DataStoreHandler,
private val core: FeatureSdkCore
) : AnonymousIdentifierManaging {

override fun manageAnonymousId(shouldTrack: Boolean) {
val anonymousIdKey = "anonymous"
if (shouldTrack) {
dataStore.value(
anonymousIdKey,
null,
AnonymousIdentifierReadCallback { anonymousId ->
if (anonymousId == null) {
val newAnonymousId = UUID.randomUUID()
dataStore.setValue(
anonymousIdKey,
newAnonymousId,
0,
null,
AnonymousIdentifierSerializer()
)
core.setAnonymousId(newAnonymousId)
} else {
core.setAnonymousId(anonymousId)
}
},
AnonymousIdentifierDeserializer()
)
} else {
dataStore.removeValue(anonymousIdKey)
core.setAnonymousId(null)
internal class AnonymousIdentifierManager {
companion object {
fun manageAnonymousId(shouldTrack: Boolean, dataStore: DataStoreHandler, core: FeatureSdkCore) {
val anonymousIdKey = "anonymous"
if (shouldTrack) {
dataStore.value(
anonymousIdKey,
null,
AnonymousIdentifierReadCallback { anonymousId ->
if (anonymousId == null) {
val newAnonymousId = UUID.randomUUID()
dataStore.setValue(
anonymousIdKey,
newAnonymousId,
0,
null,
AnonymousIdentifierSerializer()
)
core.setAnonymousId(newAnonymousId)
} else {
core.setAnonymousId(anonymousId)
}
},
AnonymousIdentifierDeserializer()
)
} else {
dataStore.removeValue(anonymousIdKey)
core.setAnonymousId(null)
}
}
}
}
Expand Down

0 comments on commit f95e57a

Please sign in to comment.