Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LIBMOBILE-1276 - Bump up analytics-kotlin version to latest. #6

Merged
merged 1 commit into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ plugins {
val VERSION_NAME: String by project

android {
compileSdk = 31
buildToolsVersion = "31.0.0"
compileSdk = 33
buildToolsVersion = "33.0.1"

defaultConfig {
multiDexEnabled = true
minSdk = 16
targetSdk = 31
targetSdk = 33

testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
consumerProguardFiles("proguard-consumer-rules.pro")
Expand All @@ -40,39 +40,39 @@ android {
}

dependencies {
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:1.1.5")
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.0.2")

implementation("com.segment.analytics.kotlin:android:1.5.0")
implementation("com.segment.analytics.kotlin:android:1.10.3")
implementation("androidx.multidex:multidex:2.0.1")

implementation("androidx.core:core-ktx:1.7.0")
implementation("androidx.appcompat:appcompat:1.4.1")
implementation("androidx.core:core-ktx:1.9.0")
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("com.google.android.material:material:1.5.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.3")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")

implementation("androidx.lifecycle:lifecycle-process:2.4.1")
implementation("androidx.lifecycle:lifecycle-common-java8:2.4.1")
}

// Partner Dependencies
dependencies {
implementation("com.mixpanel.android:mixpanel-android:5.8.7")
implementation("com.mixpanel.android:mixpanel-android:7.3.0")
}

// Test Dependencies
dependencies {
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.3")
androidTestImplementation("androidx.test.espresso:espresso-core:3.4.0")
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.0")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4")

testImplementation("io.mockk:mockk:1.12.2")
testImplementation("io.mockk:mockk:1.12.4")
testImplementation(platform("org.junit:junit-bom:5.7.2"))
testImplementation("org.junit.jupiter:junit-jupiter")

// Add Roboelectric dependencies.
testImplementation("org.robolectric:robolectric:4.7.3")
testImplementation("androidx.test:core:1.4.0")
testImplementation("androidx.test:core:1.5.0")

// Add JUnit4 legacy dependencies.
testImplementation("junit:junit:4.13.2")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ data class MixpanelSettings(
@SerialName("superProperties")
var superPropertiesFilter: Set<String> = setOf(),
@SerialName("eventIncrements")
var increments: Set<String> = setOf()
var increments: Set<String> = setOf(),
var trackAutomaticEvents: Boolean = false
)

class MixpanelDestination(
Expand All @@ -81,15 +82,19 @@ class MixpanelDestination(
analytics.log("Mixpanel Destination is enabled")
this.settings = settings.destinationSettings(key)
if (type == Plugin.UpdateType.Initial) {
mixpanel = MixpanelAPI.getInstance(context, this.settings?.token)
mixpanel = MixpanelAPI.getInstance(
context,
this.settings?.token,
this.settings?.trackAutomaticEvents ?: false
)
analytics.log("Mixpanel Destination loaded")
}
} else {
analytics.log("Mixpanel destination is disabled via settings")
}
}

override fun track(payload: TrackEvent): BaseEvent? {
override fun track(payload: TrackEvent): BaseEvent {
val settings = settings ?: return payload
// Example of transforming event property keys
val eventName = payload.event
Expand All @@ -107,7 +112,7 @@ class MixpanelDestination(
return payload
}

override fun identify(payload: IdentifyEvent): BaseEvent? {
override fun identify(payload: IdentifyEvent): BaseEvent {
val settings = settings ?: return payload
val userId: String = payload.userId
val traits: JsonObject = payload.traits
Expand Down Expand Up @@ -150,7 +155,7 @@ class MixpanelDestination(
return payload
}

override fun group(payload: GroupEvent): BaseEvent? {
override fun group(payload: GroupEvent): BaseEvent {
val groupId = payload.groupId
val traits = payload.traits

Expand All @@ -172,7 +177,7 @@ class MixpanelDestination(
return payload
}

override fun alias(payload: AliasEvent): BaseEvent? {
override fun alias(payload: AliasEvent): BaseEvent {
val userId = payload.userId
val previousId = if (payload.previousId == payload.anonymousId) {
// Instead of using our own anonymousId, we use Mixpanel's own generated Id.
Expand All @@ -187,7 +192,7 @@ class MixpanelDestination(
return payload
}

override fun screen(payload: ScreenEvent): BaseEvent? {
override fun screen(payload: ScreenEvent): BaseEvent {
val settings = settings ?: return payload
val screenName = payload.name
val properties = payload.properties
Expand Down Expand Up @@ -217,7 +222,12 @@ class MixpanelDestination(
// This is needed to trigger a call to #checkIntentForInboundAppLink.
// From Mixpanel's source, this won't trigger a creation of another instance. It caches
// instances by the application context and token, both of which remain the same.
MixpanelAPI.getInstance(activity, settings.token);
MixpanelAPI.getInstance(
activity,
settings.token,
false,
this.settings?.trackAutomaticEvents ?: false
)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import android.content.Context
import com.mixpanel.android.mpmetrics.MixpanelAPI
import com.segment.analytics.kotlin.core.*
import com.segment.analytics.kotlin.core.platform.Plugin
import com.segment.analytics.kotlin.destinations.mixpanel.MixpanelDestination
import com.segment.analytics.kotlin.destinations.mixpanel.MixpanelSettings
import io.mockk.*
import io.mockk.impl.annotations.MockK
import kotlinx.serialization.decodeFromString
Expand Down Expand Up @@ -33,7 +31,7 @@ class MixpanelDestinationTests {
init {
MockKAnnotations.init(this)
mockkStatic(MixpanelAPI::class)
every { MixpanelAPI.getInstance(mockContext, any()) } returns mockMixpanel
every { MixpanelAPI.getInstance(mockContext, any(), any()) } returns mockMixpanel
every { mockMixpanel.people } returns mockMixpanelPeople
every { mockMixpanel.getGroup(any(), any()) } returns mockMixpanelGroup

Expand Down Expand Up @@ -420,7 +418,7 @@ class MixpanelDestinationTests {
}

verify {
mockMixpanelPeople.set("Last Product Clicked", any());
mockMixpanelPeople.set("Last Product Clicked", any())
}
}

Expand Down