Skip to content

Commit 5be6df8

Browse files
authored
fixes for web2web (#99)
1 parent 1bd198e commit 5be6df8

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ android.useAndroidX=true
1919
android.enableJetifier=true
2020
# Kotlin code style for this project: "official" or "obsolete":
2121
kotlin.code.style=official
22-
sdkVersion=2.8.2
22+
sdkVersion=2.8.3

sdk/src/main/java/com/apphud/sdk/ApphudInternal+Attribution.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ internal fun ApphudInternal.tryWebAttribution(data: Map<String, Any>, callback:
202202

203203
ApphudLog.logI("Found a match from web click, updating User ID to $userId")
204204

205-
updateUserId(userId) {
205+
updateUserId(userId, web2Web = true) {
206206
if (it?.userId == userId) {
207207
callback.invoke(true, it)
208208
} else {

sdk/src/main/java/com/apphud/sdk/ApphudInternal.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ internal object ApphudInternal {
816816
forceFlushUserProperties(false) { _ -> }
817817
}
818818

819-
internal fun updateUserId(userId: UserId, callback: ((ApphudUser?) -> Unit)?) {
819+
internal fun updateUserId(userId: UserId, web2Web: Boolean? = false, callback: ((ApphudUser?) -> Unit)?) {
820820
if (userId.isBlank()) {
821821
ApphudLog.log("Invalid UserId=$userId")
822822
callback?.invoke(currentUser)
@@ -834,8 +834,12 @@ internal object ApphudInternal {
834834
RequestManager.setParams(this.context, this.apiKey)
835835

836836
coroutineScope.launch(errorHandler) {
837+
if (web2Web == true) {
838+
ApphudInternal.userId = userId
839+
ApphudInternal.fromWeb2Web = true
840+
}
837841
val needPlacementsPaywalls = !didRegisterCustomerAtThisLaunch && !deferPlacements && !observerMode
838-
val customer = RequestManager.registrationSync(needPlacementsPaywalls, is_new, true)
842+
val customer = RequestManager.registrationSync(needPlacementsPaywalls, is_new, true, userId = userId)
839843
customer?.let {
840844
mainScope.launch {
841845
notifyLoadingCompleted(it)

sdk/src/main/java/com/apphud/sdk/managers/RequestManager.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ object RequestManager {
341341
needPaywalls: Boolean,
342342
isNew: Boolean,
343343
forceRegistration: Boolean = false,
344+
userId: UserId? = null,
344345
): ApphudUser? =
345346
suspendCancellableCoroutine { continuation ->
346347
if (!canPerformRequest()) {
@@ -351,7 +352,7 @@ object RequestManager {
351352
}
352353

353354
if (currentUser == null || forceRegistration) {
354-
registration(needPaywalls, isNew, forceRegistration) { customer, error ->
355+
registration(needPaywalls, isNew, forceRegistration, userId) { customer, error ->
355356
if (continuation.isActive) {
356357
continuation.resume(customer)
357358
}
@@ -368,6 +369,7 @@ object RequestManager {
368369
needPaywalls: Boolean,
369370
isNew: Boolean,
370371
forceRegistration: Boolean = false,
372+
userId: UserId? = null,
371373
completionHandler: (ApphudUser?, ApphudError?) -> Unit,
372374
) {
373375
if (!canPerformRequest()) {
@@ -383,7 +385,7 @@ object RequestManager {
383385
.path("customers")
384386
.build()
385387

386-
val request = buildPostRequest(URL(apphudUrl.url), mkRegistrationBody(needPaywalls, isNew))
388+
val request = buildPostRequest(URL(apphudUrl.url), mkRegistrationBody(needPaywalls, isNew, userId))
387389
val httpClient = getOkHttpClient(request, !fallbackMode)
388390
try {
389391
val serverResponse = performRequestSync(httpClient, request)
@@ -968,6 +970,7 @@ object RequestManager {
968970
private fun mkRegistrationBody(
969971
needPaywalls: Boolean,
970972
isNew: Boolean,
973+
userId: UserId? = null,
971974
): RegistrationBody {
972975
val deviceIds = storage.deviceIdentifiers
973976
val idfa = deviceIds[0]
@@ -992,7 +995,7 @@ object RequestManager {
992995
idfv = if (ApphudUtils.optOutOfTracking || appSetId.isEmpty()) null else appSetId,
993996
idfa = if (ApphudUtils.optOutOfTracking || idfa.isEmpty()) null else idfa,
994997
android_id = if (ApphudUtils.optOutOfTracking || androidId.isEmpty()) null else androidId,
995-
user_id = ApphudInternal.userId,
998+
user_id = userId ?: ApphudInternal.userId,
996999
device_id = ApphudInternal.deviceId,
9971000
time_zone = TimeZone.getDefault().id,
9981001
is_sandbox = this.applicationContext.isDebuggable(),

0 commit comments

Comments
 (0)