diff --git a/snowplow-tracker/src/main/java/com/snowplowanalytics/core/tracker/TrackerControllerImpl.kt b/snowplow-tracker/src/main/java/com/snowplowanalytics/core/tracker/TrackerControllerImpl.kt index 51e4614ae..89103d3a1 100644 --- a/snowplow-tracker/src/main/java/com/snowplowanalytics/core/tracker/TrackerControllerImpl.kt +++ b/snowplow-tracker/src/main/java/com/snowplowanalytics/core/tracker/TrackerControllerImpl.kt @@ -12,6 +12,7 @@ */ package com.snowplowanalytics.core.tracker +import android.net.Uri import androidx.annotation.RestrictTo import com.snowplowanalytics.core.Controller import com.snowplowanalytics.core.ecommerce.EcommerceControllerImpl @@ -70,6 +71,34 @@ class TrackerControllerImpl // Constructors return tracker.track(event) } + override fun decorateLink(uri: Uri, parameters: List): Uri { + var spParam: String? = uri.getQueryParameter("_sp") + + val values = hashMapOf( + CrossDeviceParameters.session_id to (this.session?.sessionId ?: ""), + CrossDeviceParameters.source_id to this.appId, + CrossDeviceParameters.source_platform to this.devicePlatform.value, + CrossDeviceParameters.user_id to (this.session?.userId ?: "") + ) + + + // No `_sp` param, we need to add it in + val spVals = arrayListOf() + if (spParam.isNullOrBlank()) { + for (value in CrossDeviceParameters.values()) { + if (value in parameters) { + values[value]?.let { spVals.add(it) } + } else { + spVals.add("") + } + } + + return Uri.parse("$uri&_sp=${spVals.joinToString(".")}") + } + + return Uri.parse("garbage") + } + override val version: String get() = BuildConfig.TRACKER_LABEL override val isTracking: Boolean diff --git a/snowplow-tracker/src/main/java/com/snowplowanalytics/snowplow/controller/TrackerController.kt b/snowplow-tracker/src/main/java/com/snowplowanalytics/snowplow/controller/TrackerController.kt index f32a80b89..e3d83ead7 100644 --- a/snowplow-tracker/src/main/java/com/snowplowanalytics/snowplow/controller/TrackerController.kt +++ b/snowplow-tracker/src/main/java/com/snowplowanalytics/snowplow/controller/TrackerController.kt @@ -12,6 +12,8 @@ */ package com.snowplowanalytics.snowplow.controller +import android.net.Uri +import com.snowplowanalytics.core.tracker.CrossDeviceParameters import com.snowplowanalytics.core.tracker.TrackerConfigurationInterface import com.snowplowanalytics.snowplow.ecommerce.EcommerceController import com.snowplowanalytics.snowplow.event.Event @@ -36,9 +38,9 @@ interface TrackerController : TrackerConfigurationInterface { * It is used to identify the tracker when there are multiple trackers running in the same app. */ val namespace: String - + // Controllers - + /** * NetworkController. * Note: don't retain the reference. It may change on tracker reconfiguration. @@ -91,13 +93,13 @@ interface TrackerController : TrackerConfigurationInterface { * Note: don't retain the reference. It may change on tracker reconfiguration. */ val ecommerce: EcommerceController - + // Methods - + /** * Track the event. * The tracker will process and send the event. - * + * * @param event The event to track. * @return The event's unique ID, or null when tracking is paused */ @@ -116,4 +118,10 @@ interface TrackerController : TrackerConfigurationInterface { * The tracker will start tracking again. */ fun resume() + + /** + * Adds user and session information to a URI + * e.g. appSchema://path/to/page -> appSchema://path/to/page?_sp=userId.timestamp.sessionId.appId.platform + */ + fun decorateLink(uri: Uri, parameters: List = CrossDeviceParameters.values().toList()): Uri }