-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: include persistent visitor id in context
- Loading branch information
Showing
4 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
22 changes: 22 additions & 0 deletions
22
Provider/src/main/java/com/spotify/confidence/VisitorUtil.kt
This file contains 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,22 @@ | ||
package com.spotify.confidence | ||
|
||
import android.content.Context | ||
import java.util.UUID | ||
|
||
internal const val SHARED_PREFS_NAME = "confidence-visitor" | ||
internal const val VISITOR_ID_SHARED_PREFS_KEY = "visitorId" | ||
internal const val DEFAULT_VALUE = "unable-to-read" | ||
|
||
internal object VisitorUtil { | ||
fun getId(context: Context): String { | ||
return with(context.getSharedPreferences(SHARED_PREFS_NAME, Context.MODE_PRIVATE)) { | ||
if (contains(VISITOR_ID_SHARED_PREFS_KEY)) { | ||
getString(VISITOR_ID_SHARED_PREFS_KEY, DEFAULT_VALUE) ?: DEFAULT_VALUE | ||
} else { | ||
val visitorId = UUID.randomUUID().toString() | ||
edit().putString(VISITOR_ID_SHARED_PREFS_KEY, visitorId).apply() | ||
visitorId | ||
} | ||
} | ||
} | ||
} |
This file contains 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 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