Skip to content

Commit

Permalink
Bugfix/sdk 494 - Update user matching logic to support crossplatform …
Browse files Browse the repository at this point in the history
…plugins (#29)

* SDK-494: Updated SDK to support user matching on crossplatform plugins

* SDK-494: Updated sample app to use last modified SDK
  • Loading branch information
semsudin-tafilovic authored Jul 15, 2024
1 parent 2e7d687 commit f4a8248
Show file tree
Hide file tree
Showing 16 changed files with 117 additions and 70 deletions.
9 changes: 5 additions & 4 deletions android-sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,12 @@ android {
}

testOptions {
unitTests.returnDefaultValues = true
unitTests.all {
useJUnitPlatform()
}
// unitTests.returnDefaultValues = true
// unitTests.all {
// useJUnitPlatform()
// }
}

lint {
abortOnError false
textReport true
Expand Down
2 changes: 1 addition & 1 deletion android-sdk/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#
# LIBRARY_VERSION=5.1.4.3 (hotfixes are included on this variable)
#
LIBRARY_VERSION=5.1.9
LIBRARY_VERSION=5.1.9.1
BINTRAY_REPO=webtrekk-android-sdk
BINRTAY_NAME=webtrekk-android-sdk
PUBLISHED_GROUP_ID=com.mapp.sdk
Expand Down
9 changes: 5 additions & 4 deletions android-sdk/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@
~
-->

<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<manifest xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
<application>
<receiver
android:name=".integration.EngageIntegrationReceiver"
android:name="webtrekk.android.sdk.integration.EngageIntegrationReceiver"
android:enabled="true"
android:exported="false">
android:exported="true"
tools:ignore="ExportedReceiver">
<intent-filter>
<action android:name="webtrekk.android.sdk.integration.MappIntelligenceListener" />
</intent-filter>
Expand Down
30 changes: 15 additions & 15 deletions android-sdk/src/main/java/webtrekk/android/sdk/core/WebtrekkImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import androidx.annotation.RestrictTo
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.launch
import okhttp3.internal.userAgent
import webtrekk.android.sdk.ActiveConfig
import webtrekk.android.sdk.Config
import webtrekk.android.sdk.ExceptionType
Expand Down Expand Up @@ -633,35 +634,34 @@ constructor() : Webtrekk(),
}

override fun getDmcUserId(): String? {
return AppModule.webtrekkSharedPrefs.dmcUserId
return if (config.userMatchingEnabled) sessions.getDmcUserId() else null
}

override fun getCurrentConfiguration(): ActiveConfig {
return ActiveConfig(
trackDomains = config.trackDomain,
trackIds = config.trackIds,
everId = sessions.getEverId(),
trackDomains = getTrackDomain(),
trackIds = getTrackIds(),
everId = getEverId(),
everIdMode = sessions.getEverIdMode(),
userAgent = sessions.getUserAgent(),
userMatchingId = sessions.getDmcUserId(),
userAgent = getUserAgent(),
userMatchingId = getDmcUserId(),
anonymousParams = sessions.isAnonymousParam(),
isAnonymous = sessions.isAnonymous(),
isAnonymous = isAnonymousTracking(),
logLevel = config.logLevel,
exceptionLogLevel = config.exceptionLogLevel,
exceptionLogLevel = getExceptionLogLevel(),
requestInterval = config.requestsInterval,
requestsPerBatch = config.requestPerBatch,
requestsPerBatch = getRequestsPerBatch(),
isActivityAutoTracking = config.activityAutoTracking,
isFragmentAutoTracking = config.fragmentsAutoTracking,
isAutoTracking = config.autoTracking,
isBatchSupport = config.batchSupport,
isOptOut = sessions.isOptOut(),
isUserMatching = config.userMatchingEnabled,
isBatchSupport = isBatchEnabled(),
isOptOut = hasOptOut(),
isUserMatching = isUserMatchingEnabled(),
shouldMigrate = config.shouldMigrate,
sendVersionInEachRequest = config.versionInEachRequest,
sendVersionInEachRequest = getVersionInEachRequest(),
appFirstOpen = sessions.getAppFirstOpen(false) == "1",
temporarySessionId = sessions.getTemporarySessionId(),

)
)
}

override fun setTemporarySessionId(sessionId: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,19 @@ import webtrekk.android.sdk.data.model.GenerationMode
*/
internal class WebtrekkSharedPrefs(val context: Context) {

var dmcUserId: String?
inline get() = sharedPreferences.getString(DMC_USER_ID, null)
set(value) = sharedPreferences.edit().putString(DMC_USER_ID, value).apply()

val sharedPreferences: SharedPreferences =
context.getSharedPreferences(SHARED_PREFS_NAME, Context.MODE_PRIVATE)

val previousSharedPreferences: SharedPreferences =
context.getSharedPreferences(PREVIOUS_SHARED_PREFS_NAME, Context.MODE_PRIVATE)

var everId:String?
var dmcUserId: String?
inline get() {
return sharedPreferences.getString(DMC_USER_ID, null)
}
set(value) = sharedPreferences.edit().putString(DMC_USER_ID, value).apply()

var everId: String?
inline get() {
return sharedPreferences.getString(EVER_ID_KEY, null)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import webtrekk.android.sdk.util.currentDeviceModel
import webtrekk.android.sdk.util.currentLanguage
import webtrekk.android.sdk.util.currentOsVersion
import webtrekk.android.sdk.util.currentWebtrekkVersion
import webtrekk.android.sdk.util.userId

/**
* This file contains extension & helper functions used to form the request url from [TrackRequest] and [DataTrack].
Expand Down Expand Up @@ -233,8 +232,8 @@ internal fun DataTrack.buildBody(
}

// set global EmailReceiverId only if custom EmailReceiverId not set
if (emailReceiverID == null && !activeConfig.isAnonymous && activeConfig.isUserMatching && !userId.isNullOrEmpty()) {
stringBuffer += "&${UrlParams.USER_ID}=$userId"
if (emailReceiverID == null && !activeConfig.isAnonymous && activeConfig.isUserMatching && !activeConfig.userMatchingId.isNullOrEmpty()) {
stringBuffer += "&${UrlParams.USER_ID}=${activeConfig.userMatchingId}"
}

val customParamsString = customParams.buildCustomParams(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ import webtrekk.android.sdk.module.LibraryModule
class EngageIntegrationReceiver : BroadcastReceiver() {
private val ACTION = "webtrekk.android.sdk.integration.MappIntelligenceListener"

private val sessions: Sessions by lazy { InteractorModule.sessions }

private val config:Config by lazy { LibraryModule.configuration }

override fun onReceive(context: Context?, intent: Intent?) {
intent?.let {
context?.let { ctx ->
Expand All @@ -25,7 +21,7 @@ class EngageIntegrationReceiver : BroadcastReceiver() {
if (ACTION == action) {
it.extras?.getString("dmcUserId")?.let { dmcUserId ->
if (dmcUserId.isNotEmpty()) {
sessions.setDmcUserId(dmcUserId)
InteractorModule.sessions.setDmcUserId(dmcUserId)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ internal val trackIds: List<String>
internal val webtrekkLogger: Logger
inline get() = WebtrekkImpl.getInstance().logger

internal var userId: String?
inline get() = WebtrekkImpl.getInstance().sessions.getDmcUserId()
set(value) = WebtrekkImpl.getInstance().sessions.setDmcUserId(value)

internal var appVersionInRequest: Boolean
inline get() = WebtrekkImpl.getInstance().config.versionInEachRequest
set(value) {
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@ buildscript {
classpath "com.github.dcendents:android-maven-gradle-plugin:${versions.mavenPluginVersion}"
classpath "com.google.gms:google-services:${versions.googleServices}"
classpath "com.google.firebase:firebase-appdistribution-gradle:${versions.firebaseAppDistribution}"
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.9'
classpath 'com.google.firebase:firebase-crashlytics-gradle:3.0.2'
classpath 'io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.30.0'
}
}

allprojects {
repositories {
//mavenLocal()
mavenLocal()
mavenCentral()
google()
gradlePluginPortal()
Expand Down
8 changes: 4 additions & 4 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ android {

dependencies {
implementation 'androidx.recyclerview:recyclerview:1.3.2'
implementation('com.google.android.material:material:1.11.0')
implementation('com.google.android.material:material:1.12.0')
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$versions.kotlinVersion"
implementation "androidx.appcompat:appcompat:$versions.appCompatVersion"
Expand All @@ -137,14 +137,14 @@ dependencies {
implementation 'androidx.media3:media3-exoplayer-dash:1.3.1'
implementation 'androidx.media3:media3-exoplayer-hls:1.3.1'

implementation platform('com.google.firebase:firebase-bom:32.8.1')
implementation platform('com.google.firebase:firebase-bom:33.1.1')
implementation('com.google.firebase:firebase-messaging')
implementation("com.google.firebase:firebase-crashlytics")

implementation('com.mapp.sdk:mapp-android:6.0.22')
implementation('com.mapp.sdk:mapp-android:6.0.23.1')

implementation(project(':android-sdk'))
//implementation ("com.mapp.sdk:intelligence-android:5.1.8")
//implementation ("com.mapp.sdk:intelligence-android:5.1.9")

//debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.9.1'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ class CrashActivity : AppCompatActivity() {
}

binding.trackUncaught.setOnClickListener {
Integer.parseInt("@!#")
//Integer.parseInt("@!#")
throw RuntimeException("Test runtime native exception uncaught!!!")
}

binding.trackCaught.setOnClickListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import com.appoxee.AppoxeeOptions

object EngageSdk {


private val appoxeeOptions = AppoxeeOptions().apply {
appID = "264157"
tenantID = "33"
server = AppoxeeOptions.Server.TEST
sdkKey = "6017dd65b8d820.37698249"
appID = "206974"
tenantID = "5963"
server = AppoxeeOptions.Server.L3
sdkKey = "183408d0cd3632.83592719"
}

private val listener = Appoxee.OnInitCompletedListener { successful, failReason ->
Expand All @@ -22,4 +23,6 @@ object EngageSdk {
Appoxee.engage(application, appoxeeOptions)
Appoxee.instance().addInitListener(listener)
}
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class ManualMediaTracking : AppCompatActivity() {
binding.swIncrementTime.text = String.format(
Locale.US,
getString(R.string.increment_current_time_by_s_seconds_on_each_action),
secondsCountToIncrease
secondsCountToIncrease.toString()
)

binding.swIncrementTime.isChecked = false
Expand Down
Loading

0 comments on commit f4a8248

Please sign in to comment.