diff --git a/README.md b/README.md
index c76689d..1fc8d94 100644
--- a/README.md
+++ b/README.md
@@ -23,7 +23,7 @@ implementation("com.segment.analytics.kotlin.destinations:mixpanel:1.4.4")
Open the file where you setup and configure the Analytics-Kotlin library. Add this plugin to the list of imports.
```
-import com.segment.analytics.kotlin.destinations.plugins.MixpanelDestination
+import com.segment.analytics.kotlin.destinations.mixpanel.MixpanelDestination
```
Just under your Analytics-Kotlin library setup, call `analytics.add(plugin = ...)` to add an instance of the plugin to the Analytics timeline.
diff --git a/lib/build.gradle.kts b/lib/build.gradle.kts
index a363387..b0a1bef 100644
--- a/lib/build.gradle.kts
+++ b/lib/build.gradle.kts
@@ -6,6 +6,8 @@ plugins {
id("mvn-publish")
}
+val VERSION_NAME: String by project
+
android {
compileSdk = 31
buildToolsVersion = "31.0.0"
@@ -17,6 +19,8 @@ android {
testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
consumerProguardFiles("proguard-consumer-rules.pro")
+
+ buildConfigField("String", "VERSION_NAME", "\"$VERSION_NAME\"")
}
buildTypes {
@@ -38,7 +42,7 @@ android {
dependencies {
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:1.1.5")
- implementation("com.segment.analytics.kotlin:android:1.4.3")
+ implementation("com.segment.analytics.kotlin:android:1.5.0")
implementation("androidx.multidex:multidex:2.0.1")
implementation("androidx.core:core-ktx:1.7.0")
diff --git a/lib/src/androidTest/java/com/segment/analytics/kotlin/destinations/plugins/ExampleInstrumentedTest.kt b/lib/src/androidTest/java/com/segment/analytics/kotlin/destinations/mixpanel/ExampleInstrumentedTest.kt
similarity index 70%
rename from lib/src/androidTest/java/com/segment/analytics/kotlin/destinations/plugins/ExampleInstrumentedTest.kt
rename to lib/src/androidTest/java/com/segment/analytics/kotlin/destinations/mixpanel/ExampleInstrumentedTest.kt
index 3686f35..8dfae1a 100644
--- a/lib/src/androidTest/java/com/segment/analytics/kotlin/destinations/plugins/ExampleInstrumentedTest.kt
+++ b/lib/src/androidTest/java/com/segment/analytics/kotlin/destinations/mixpanel/ExampleInstrumentedTest.kt
@@ -1,13 +1,11 @@
-package com.segment.analytics.kotlin.destinations.plugins
+package com.segment.analytics.kotlin.destinations.mixpanel
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
-
+import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith
-import org.junit.Assert.*
-
/**
* Instrumented test, which will execute on an Android device.
*
@@ -19,6 +17,9 @@ class ExampleInstrumentedTest {
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
- assertEquals("com.segment.analytics.kotlin.destinations.plugins.test", appContext.packageName)
+ Assert.assertEquals(
+ "com.segment.analytics.kotlin.destinations.mixpanel.test",
+ appContext.packageName
+ )
}
}
\ No newline at end of file
diff --git a/lib/src/main/AndroidManifest.xml b/lib/src/main/AndroidManifest.xml
index e5f5b96..e4fcdad 100644
--- a/lib/src/main/AndroidManifest.xml
+++ b/lib/src/main/AndroidManifest.xml
@@ -1,5 +1,5 @@
+ package="com.segment.analytics.kotlin.destinations.mixpanel">
\ No newline at end of file
diff --git a/lib/src/main/java/com/segment/analytics/kotlin/destinations/plugins/MixpanelDestination.kt b/lib/src/main/java/com/segment/analytics/kotlin/destinations/mixpanel/MixpanelDestination.kt
similarity index 97%
rename from lib/src/main/java/com/segment/analytics/kotlin/destinations/plugins/MixpanelDestination.kt
rename to lib/src/main/java/com/segment/analytics/kotlin/destinations/mixpanel/MixpanelDestination.kt
index 4ea754a..2d232fd 100644
--- a/lib/src/main/java/com/segment/analytics/kotlin/destinations/plugins/MixpanelDestination.kt
+++ b/lib/src/main/java/com/segment/analytics/kotlin/destinations/mixpanel/MixpanelDestination.kt
@@ -1,4 +1,4 @@
-package com.segment.analytics.kotlin.destinations.plugins
+package com.segment.analytics.kotlin.destinations.mixpanel
import android.app.Activity
import android.content.Context
@@ -9,6 +9,7 @@ import com.segment.analytics.kotlin.android.utilities.toJSONObject
import com.segment.analytics.kotlin.core.*
import com.segment.analytics.kotlin.core.platform.DestinationPlugin
import com.segment.analytics.kotlin.core.platform.Plugin
+import com.segment.analytics.kotlin.core.platform.VersionedPlugin
import com.segment.analytics.kotlin.core.platform.plugins.logger.*
import com.segment.analytics.kotlin.core.utilities.*
import kotlinx.serialization.*
@@ -67,7 +68,7 @@ data class MixpanelSettings(
class MixpanelDestination(
private val context: Context
-) : DestinationPlugin(), AndroidLifecycle {
+) : DestinationPlugin(), AndroidLifecycle, VersionedPlugin {
internal var settings: MixpanelSettings? = null
internal var mixpanel: MixpanelAPI? = null
@@ -251,4 +252,8 @@ class MixpanelDestination(
keyMapper: Map,
): Map = JsonObject(this).mapTransform(keyMapper, null)
+ override fun version(): String {
+ return BuildConfig.VERSION_NAME
+ }
+
}
\ No newline at end of file
diff --git a/lib/src/test/java/com/segment/analytics/kotlin/destinations/plugins/MixpanelDestinationTests.kt b/lib/src/test/java/com/segment/analytics/kotlin/destinations/mixpanel/MixpanelDestinationTests.kt
similarity index 93%
rename from lib/src/test/java/com/segment/analytics/kotlin/destinations/plugins/MixpanelDestinationTests.kt
rename to lib/src/test/java/com/segment/analytics/kotlin/destinations/mixpanel/MixpanelDestinationTests.kt
index a271c0e..dc196e8 100644
--- a/lib/src/test/java/com/segment/analytics/kotlin/destinations/plugins/MixpanelDestinationTests.kt
+++ b/lib/src/test/java/com/segment/analytics/kotlin/destinations/mixpanel/MixpanelDestinationTests.kt
@@ -1,9 +1,11 @@
-package com.segment.analytics.kotlin.destinations.plugins
+package com.segment.analytics.kotlin.destinations.mixpanel
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
@@ -12,12 +14,11 @@ import kotlinx.serialization.json.buildJsonObject
import kotlinx.serialization.json.put
import org.json.JSONException
import org.json.JSONObject
-import org.junit.jupiter.api.Assertions.*
+import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.skyscreamer.jsonassert.JSONAssert
import org.skyscreamer.jsonassert.JSONCompareMode
-
class MixpanelDestinationTests {
private val mockContext = mockk(relaxed = true)
@@ -81,20 +82,23 @@ class MixpanelDestinationTests {
mixpanelDestination.update(settingsBlob, Plugin.UpdateType.Initial)
/* assertions about config */
- assertNotNull(mixpanelDestination.settings)
+ Assertions.assertNotNull(mixpanelDestination.settings)
with(mixpanelDestination.settings!!) {
- assertFalse(consolidatedPageCalls)
- assertTrue(isPeopleEnabled)
- assertFalse(trackAllPages)
- assertTrue(trackCategorizedPages)
- assertFalse(trackNamedPages)
- assertFalse(setAllTraitsByDefault)
+ Assertions.assertFalse(consolidatedPageCalls)
+ Assertions.assertTrue(isPeopleEnabled)
+ Assertions.assertFalse(trackAllPages)
+ Assertions.assertTrue(trackCategorizedPages)
+ Assertions.assertFalse(trackNamedPages)
+ Assertions.assertFalse(setAllTraitsByDefault)
- assertEquals("token1234", token)
+ Assertions.assertEquals("token1234", token)
- assertEquals(emptySet(), superPropertiesFilter)
- assertEquals(setOf("email", "username", "phone_number"), peoplePropertiesFilter)
- assertEquals(setOf("Product Clicked", "Product Viewed"), increments)
+ Assertions.assertEquals(emptySet(), superPropertiesFilter)
+ Assertions.assertEquals(
+ setOf("email", "username", "phone_number"),
+ peoplePropertiesFilter
+ )
+ Assertions.assertEquals(setOf("Product Clicked", "Product Viewed"), increments)
}
}
@@ -125,7 +129,7 @@ class MixpanelDestinationTests {
)
val screenEvent = mixpanelDestination.screen(sampleEvent)
- assertNotNull(screenEvent)
+ Assertions.assertNotNull(screenEvent)
verify { mockMixpanel wasNot Called }
}
@@ -154,7 +158,7 @@ class MixpanelDestinationTests {
)
val screenEvent = mixpanelDestination.screen(sampleEvent)
- assertNotNull(screenEvent)
+ Assertions.assertNotNull(screenEvent)
verify {
mockMixpanel.track(
"Viewed LoginFragment Screen",
@@ -192,7 +196,7 @@ class MixpanelDestinationTests {
)
val screenEvent = mixpanelDestination.screen(sampleEvent)
- assertNotNull(screenEvent)
+ Assertions.assertNotNull(screenEvent)
verify {
mockMixpanel.track(
"Loaded a Screen",
@@ -232,7 +236,7 @@ class MixpanelDestinationTests {
)
val screenEvent = mixpanelDestination.screen(sampleEvent)
- assertNotNull(screenEvent)
+ Assertions.assertNotNull(screenEvent)
verify {
mockMixpanel.track(
"Viewed LoginFragment Screen",
@@ -271,7 +275,7 @@ class MixpanelDestinationTests {
)
val screenEvent = mixpanelDestination.screen(sampleEvent)
- assertNotNull(screenEvent)
+ Assertions.assertNotNull(screenEvent)
verify { mockMixpanel wasNot Called }
}
@@ -301,7 +305,7 @@ class MixpanelDestinationTests {
)
val screenEvent = mixpanelDestination.screen(sampleEvent)
- assertNotNull(screenEvent)
+ Assertions.assertNotNull(screenEvent)
verify {
mockMixpanel.track(
"Viewed signup_flow Screen",
@@ -340,7 +344,7 @@ class MixpanelDestinationTests {
)
val screenEvent = mixpanelDestination.screen(sampleEvent)
- assertNotNull(screenEvent)
+ Assertions.assertNotNull(screenEvent)
verify { mockMixpanel wasNot Called }
}
@@ -364,7 +368,7 @@ class MixpanelDestinationTests {
val trackEvent = mixpanelDestination.track(sampleEvent)
- assertNotNull(trackEvent)
+ Assertions.assertNotNull(trackEvent)
verify {
mockMixpanel.track(
@@ -399,7 +403,7 @@ class MixpanelDestinationTests {
val trackEvent = mixpanelDestination.track(sampleEvent)
- assertNotNull(trackEvent)
+ Assertions.assertNotNull(trackEvent)
verify {
mockMixpanel.track(
@@ -442,7 +446,7 @@ class MixpanelDestinationTests {
val trackEvent = mixpanelDestination.track(sampleEvent)
- assertNotNull(trackEvent)
+ Assertions.assertNotNull(trackEvent)
verify {
mockMixpanel.track(
@@ -479,7 +483,7 @@ class MixpanelDestinationTests {
val trackEvent = mixpanelDestination.alias(sampleEvent)
- assertNotNull(trackEvent)
+ Assertions.assertNotNull(trackEvent)
verify {
mockMixpanel.alias(
@@ -511,7 +515,7 @@ class MixpanelDestinationTests {
val trackEvent = mixpanelDestination.alias(sampleEvent)
- assertNotNull(trackEvent)
+ Assertions.assertNotNull(trackEvent)
verify {
mockMixpanel.alias(
@@ -540,7 +544,7 @@ class MixpanelDestinationTests {
)
val identifyEvent = mixpanelDestination.identify(sampleEvent)
- assertNotNull(identifyEvent)
+ Assertions.assertNotNull(identifyEvent)
verify { mockMixpanel.identify("abc-123") }
verify {
@@ -571,7 +575,7 @@ class MixpanelDestinationTests {
)
val identifyEvent = mixpanelDestination.identify(sampleEvent)
- assertNotNull(identifyEvent)
+ Assertions.assertNotNull(identifyEvent)
verify(exactly = 0) { mockMixpanel.identify("abc-123") }
verify {
@@ -603,7 +607,7 @@ class MixpanelDestinationTests {
)
val identifyEvent = mixpanelDestination.identify(sampleEvent)
- assertNotNull(identifyEvent)
+ Assertions.assertNotNull(identifyEvent)
verify { mockMixpanel.identify("abc-123") }
verify {
@@ -650,7 +654,7 @@ class MixpanelDestinationTests {
)
val identifyEvent = mixpanelDestination.identify(sampleEvent)
- assertNotNull(identifyEvent)
+ Assertions.assertNotNull(identifyEvent)
val expectedTraits = JSONObject()
.put("\$email", "123@abc.com")
@@ -701,7 +705,7 @@ class MixpanelDestinationTests {
)
val identifyEvent = mixpanelDestination.identify(sampleEvent)
- assertNotNull(identifyEvent)
+ Assertions.assertNotNull(identifyEvent)
val expectedTraits = JSONObject()
.put("\$phone", "987-654-3210")
@@ -747,7 +751,7 @@ class MixpanelDestinationTests {
)
val identifyEvent = mixpanelDestination.identify(sampleEvent)
- assertNotNull(identifyEvent)
+ Assertions.assertNotNull(identifyEvent)
val expectedTraits = JSONObject()
.put("\$phone", "987-654-3210")
@@ -787,7 +791,7 @@ class MixpanelDestinationTests {
)
val groupEvent = mixpanelDestination.group(sampleEvent)
- assertNotNull(groupEvent)
+ Assertions.assertNotNull(groupEvent)
// check mixpanel getGroup called with groupKey default "[Segment] Group" and groupID "grp-123"
verify { mockMixpanel.getGroup("[Segment] Group", "grp-123") }
@@ -828,7 +832,7 @@ class MixpanelDestinationTests {
)
val groupEvent = mixpanelDestination.group(sampleEvent)
- assertNotNull(groupEvent)
+ Assertions.assertNotNull(groupEvent)
// check mixpanel getGroup called with groupKey default "ABC network" and groupID "grp-123"
verify { mockMixpanel.getGroup("ABC network", "grp-123") }