Skip to content

Commit

Permalink
Initial
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-el committed Sep 5, 2023
1 parent 9d541a5 commit a997af5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -70,6 +71,34 @@ class TrackerControllerImpl // Constructors
return tracker.track(event)
}

override fun decorateLink(uri: Uri, parameters: List<CrossDeviceParameters>): Uri {
var spParam: String? = uri.getQueryParameter("_sp")

val values = hashMapOf<CrossDeviceParameters, String>(
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<String>()
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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
*/
Expand All @@ -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> = CrossDeviceParameters.values().toList()): Uri
}

0 comments on commit a997af5

Please sign in to comment.