Skip to content
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

chore: change sessionid to opaqueuserid #22

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions TopsortAnalytics/src/main/java/com/topsort/analytics/Analytics.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,24 @@ object Analytics : TopsortAnalytics {
/**
* Setup initial properties required for the analytics library,
* Call this from the Application class, before submitting any event,
* Or when a new sessionId or bearer token has to be used.
* Or when a new opaqueUserId or bearer token has to be used.
*
* @param application The Application instance of the app.
* @param sessionId The SessionId allows correlating user activity during a session whether or not they are actually logged in.
* @param opaqueUserId The SessionId allows correlating user activity during a session whether or not they are actually logged in.
* @param token The bearer token
*/
@SuppressLint("KotlinNullnessAnnotation")
fun setup(
@NonNull application: Application,
@NonNull sessionId: String,
@NonNull opaqueUserId: String,
@NonNull token: String
) {
applicationContext = application.applicationContext
workManager = WorkManager.getInstance(applicationContext!!)
Cache.setup(application, sessionId, token)
Cache.setup(application, opaqueUserId, token)

session = Session(
sessionId = sessionId
opaqueUserId = opaqueUserId
)
}

Expand All @@ -72,7 +72,7 @@ object Analytics : TopsortAnalytics {
Impression.Factory.buildPromoted(
resolvedBidId = resolvedBidId,
placement = placement,
opaqueUserId = opaqueUserId ?: session!!.sessionId,
opaqueUserId = opaqueUserId ?: session!!.opaqueUserId,
id = id?: randomId(),
occurredAt = occurredAt ?: eventTime(),
)
Expand All @@ -92,7 +92,7 @@ object Analytics : TopsortAnalytics {
Impression.Factory.buildOrganic(
entity = entity,
placement = placement,
opaqueUserId = opaqueUserId ?: session!!.sessionId,
opaqueUserId = opaqueUserId ?: session!!.opaqueUserId,
id = id?: randomId(),
occurredAt = occurredAt ?: eventTime(),
)
Expand All @@ -112,7 +112,7 @@ object Analytics : TopsortAnalytics {
Click.Factory.buildPromoted(
resolvedBidId = resolvedBidId,
placement = placement,
opaqueUserId = opaqueUserId ?: session!!.sessionId,
opaqueUserId = opaqueUserId ?: session!!.opaqueUserId,
id = id?: randomId(),
occurredAt = occurredAt ?: eventTime()
)
Expand All @@ -132,7 +132,7 @@ object Analytics : TopsortAnalytics {
Click.Factory.buildOrganic(
entity = entity,
placement = placement,
opaqueUserId = opaqueUserId ?: session!!.sessionId,
opaqueUserId = opaqueUserId ?: session!!.opaqueUserId,
id = id?: randomId(),
occurredAt = occurredAt ?: eventTime()
)
Expand All @@ -158,7 +158,7 @@ object Analytics : TopsortAnalytics {
id = id,
items = items,
occurredAt = occurredAt ?: eventTime(),
opaqueUserId = opaqueUserId ?: session!!.sessionId,
opaqueUserId = opaqueUserId ?: session!!.opaqueUserId,
),
),
)
Expand Down
10 changes: 5 additions & 5 deletions TopsortAnalytics/src/main/java/com/topsort/analytics/Cache.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import android.text.TextUtils
import com.topsort.analytics.model.ClickEvent
import com.topsort.analytics.model.ImpressionEvent
import com.topsort.analytics.model.PurchaseEvent
import java.util.*
import java.util.Locale

private const val PREFERENCES_NAME = "TOPSORT_EVENTS_CACHE"

Expand All @@ -31,7 +31,7 @@ internal object Cache {
.apply()
}

var sessionId: String = ""
private var opaqueUserId: String = ""
set(value) {
field = value
preferences
Expand All @@ -45,18 +45,18 @@ internal object Cache {
preferences = applicationContext.getSharedPreferences(PREFERENCES_NAME, Context.MODE_PRIVATE)

token = preferences.getString(KEY_TOKEN, "")!!
sessionId = preferences.getString(KEY_SESSION_ID, "")!!
opaqueUserId = preferences.getString(KEY_SESSION_ID, "")!!
}

fun setup(
context: Context,
sessionId: String,
opaqueUserId: String,
token: String
) {
initialize(context)

recentRecordId = preferences.getLong(KEY_RECENT_RECORD_ID, 0)
this.sessionId = sessionId
this.opaqueUserId = opaqueUserId
this.token = token
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.topsort.analytics.model

data class Session(
val sessionId: String
val opaqueUserId: String
)
2 changes: 1 addition & 1 deletion app/src/main/java/com/topsort/analytics/TestApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class TestApplication : Application() {

Analytics.setup(
application = this,
sessionId = sessionId,
opaqueUserId = sessionId,
token = BuildConfig.TOKEN
)
}
Expand Down