Skip to content
This repository has been archived by the owner on Nov 25, 2022. It is now read-only.

Commit

Permalink
Added options to all tracking functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Reedyuk committed Mar 2, 2022
1 parent b832ee0 commit 8ac554c
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 29 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ plugins {
}

group = "com.myunidays"
version = "0.0.2"
version = "0.0.3"

val frameworkName = "segmenkt"
val ktor_version = "1.6.6"
Expand Down
2 changes: 1 addition & 1 deletion segmenkt.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = 'segmenkt'
spec.version = '0.0.2'
spec.version = '0.0.3'
spec.homepage = 'Link to a Kotlin/Native module homepage'
spec.source = { :git => "Not Published", :tag => "Cocoapods/#{spec.name}/#{spec.version}" }
spec.authors = ''
Expand Down
52 changes: 40 additions & 12 deletions src/androidMain/kotlin/com/myunidays/segmenkt/Analytics.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.myunidays.segmenkt

import android.content.Context
import com.segment.analytics.Options
import com.segment.analytics.Properties
import com.segment.analytics.Traits
import java.util.concurrent.TimeUnit
Expand Down Expand Up @@ -29,52 +30,79 @@ actual class Analytics internal constructor(val android: com.segment.analytics.A
Log()
}

actual fun alias(userId: String) = android.alias(userId)
actual fun alias(userId: String, options: Map<Any?, *>?) =
android.alias(
userId,
Options().apply {
options?.forEach { property ->
(property.key as? String)?.let { putContext(it, property.value) }
}
}
).also { Log.d("Segment: Alias $userId $options") }

actual fun track(name: String, properties: Map<Any?, *>?) =
actual fun track(name: String, properties: Map<Any?, *>?, options: Map<Any?, *>?) =
android.track(
name,
Properties().apply {
properties?.forEach { property ->
(property.key as? String)?.let { putValue(it, property.value) }
}
},
Options().apply {
options?.forEach { property ->
(property.key as? String)?.let { putContext(it, property.value) }
}
}
).also { Log.d("Segment: Track $name: $properties") }
).also { Log.d("Segment: Track $name: $properties $options") }

actual fun identify(userId: String, traits: Map<Any?, *>?) =
actual fun identify(userId: String, traits: Map<Any?, *>?, options: Map<Any?, *>?) =
android.identify(
userId,
Traits().apply {
traits?.forEach { trait ->
(trait.key as? String)?.let { putValue(it, trait.value) }
}
},
null
)
.also { Log.d("Segment: Identify $userId: $traits") }
Options().apply {
options?.forEach { property ->
(property.key as? String)?.let { putContext(it, property.value) }
}
}
).also { Log.d("Segment: Identify $userId: $traits $options") }

actual fun screen(
screenTitle: String,
properties: Map<Any?, *>?
properties: Map<Any?, *>?,
options: Map<Any?, *>?
) = android.screen(
null,
screenTitle,
Properties().apply {
properties?.forEach { property ->
(property.key as? String)?.let { putValue(it, property.value) }
}
},
Options().apply {
options?.forEach { property ->
(property.key as? String)?.let { putContext(it, property.value) }
}
}
).also { Log.d("Segment: Screen $screenTitle: $properties") }
).also { Log.d("Segment: Screen $screenTitle: $properties $options") }

actual fun group(groupId: String, traits: Map<Any?, *>?) =
actual fun group(groupId: String, traits: Map<Any?, *>?, options: Map<Any?, *>?) =
android.group(
groupId,
Traits().apply {
traits?.forEach { trait ->
(trait.key as? String)?.let { putValue(it, trait.value) }
}
},
Options().apply {
options?.forEach { property ->
(property.key as? String)?.let { putContext(it, property.value) }
}
}
)
.also { Log.d("Segment: Group $groupId: $traits") }
).also { Log.d("Segment: Group $groupId: $traits") }

actual fun reset() {
android.reset()
Expand Down
10 changes: 5 additions & 5 deletions src/commonMain/kotlin/com.myunidays.segmenkt/Analytics.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ expect class Analytics {
fun shared(context: Any? = null): Analytics
}

fun track(name: String, properties: Map<Any?, *>? = null)
fun identify(userId: String, traits: Map<Any?, *>? = null)
fun alias(userId: String)
fun screen(screenTitle: String, properties: Map<Any?, *>? = null)
fun group(groupId: String, traits: Map<Any?, *>? = null)
fun track(name: String, properties: Map<Any?, *>? = null, options: Map<Any?, *>? = null)
fun identify(userId: String, traits: Map<Any?, *>? = null, options: Map<Any?, *>? = null)
fun alias(userId: String, options: Map<Any?, *>? = null)
fun screen(screenTitle: String, properties: Map<Any?, *>? = null, options: Map<Any?, *>? = null)
fun group(groupId: String, traits: Map<Any?, *>? = null, options: Map<Any?, *>? = null)

fun reset()
}
22 changes: 12 additions & 10 deletions src/iosMain/kotlin/com.myunidays.segmenkt/Analytics.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,24 @@ actual class Analytics internal constructor(val ios: cocoapods.Analytics.SEGAnal
Log()
}

actual fun alias(userId: String) = ios.alias(userId)
actual fun alias(userId: String, options: Map<Any?, *>?) = ios.alias(userId, options?.let { mapOf("context" to it) })
.also { Log.d("Segment: Alias $userId: $options") }

actual fun track(name: String, properties: Map<Any?, *>?) = ios.track(name, properties)
.also { Log.d("Segment: Track $name: $properties") }
actual fun track(name: String, properties: Map<Any?, *>?, options: Map<Any?, *>?) = ios.track(name, properties, options?.let { mapOf("context" to it) })
.also { Log.d("Segment: Track $name: $properties $options") }

actual fun identify(userId: String, traits: Map<Any?, *>?) = ios.identify(userId, traits)
.also { Log.d("Segment: Identify $userId: $traits") }
actual fun identify(userId: String, traits: Map<Any?, *>?, options: Map<Any?, *>?) = ios.identify(userId, traits, options?.let { mapOf("context" to it) })
.also { Log.d("Segment: Identify $userId: $traits $options") }

actual fun screen(
screenTitle: String,
properties: Map<Any?, *>?
) = ios.screen(screenTitle, properties)
.also { Log.d("Segment: Screen $screenTitle: $properties") }
properties: Map<Any?, *>?,
options: Map<Any?, *>?
) = ios.screen(screenTitle, properties, options?.let { mapOf("context" to it) })
.also { Log.d("Segment: Screen $screenTitle: $properties $options") }

actual fun group(groupId: String, traits: Map<Any?, *>?) = ios.group(groupId, traits)
.also { Log.d("Segment: Group $groupId: $traits") }
actual fun group(groupId: String, traits: Map<Any?, *>?, options: Map<Any?, *>?) = ios.group(groupId, traits, options?.let { mapOf("context" to it) })
.also { Log.d("Segment: Group $groupId: $traits $options") }

actual fun reset() {
ios.reset().also { Log.d("Segment: Reset") }
Expand Down

0 comments on commit 8ac554c

Please sign in to comment.