Skip to content

Commit 6be1491

Browse files
authored
Support EU API URL and bump Mixpanel to 7.3.3 from 7.3.0 (#7)
* Support EU api URL. * Bumb mixpanel to latest fix version 7.3.3
1 parent 600b97b commit 6be1491

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

lib/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ dependencies {
5656

5757
// Partner Dependencies
5858
dependencies {
59-
implementation("com.mixpanel.android:mixpanel-android:7.3.0")
59+
implementation("com.mixpanel.android:mixpanel-android:7.3.3")
6060
}
6161

6262
// Test Dependencies

lib/src/main/java/com/segment/analytics/kotlin/destinations/mixpanel/MixpanelDestination.kt

+16-10
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ SOFTWARE.
5151
@Serializable
5252
data class MixpanelSettings(
5353
var token: String,
54+
var enableEuropeanUnionEndpoint: Boolean = false,
5455
@SerialName("people")
5556
var isPeopleEnabled: Boolean = false,
5657
var setAllTraitsByDefault: Boolean = true,
@@ -71,7 +72,7 @@ class MixpanelDestination(
7172
private val context: Context
7273
) : DestinationPlugin(), AndroidLifecycle, VersionedPlugin {
7374

74-
internal var settings: MixpanelSettings? = null
75+
internal var mixpanelSettings: MixpanelSettings? = null
7576
internal var mixpanel: MixpanelAPI? = null
7677

7778
override val key: String = "Mixpanel"
@@ -80,13 +81,18 @@ class MixpanelDestination(
8081
super.update(settings, type)
8182
if (settings.hasIntegrationSettings(this)) {
8283
analytics.log("Mixpanel Destination is enabled")
83-
this.settings = settings.destinationSettings(key)
84+
this.mixpanelSettings = settings.destinationSettings(key)
8485
if (type == Plugin.UpdateType.Initial) {
8586
mixpanel = MixpanelAPI.getInstance(
8687
context,
87-
this.settings?.token,
88-
this.settings?.trackAutomaticEvents ?: false
88+
this.mixpanelSettings?.token,
89+
this.mixpanelSettings?.trackAutomaticEvents ?: false
8990
)
91+
92+
if (mixpanelSettings?.enableEuropeanUnionEndpoint == true) {
93+
mixpanel?.setServerURL("https://api-eu.mixpanel.com")
94+
}
95+
9096
analytics.log("Mixpanel Destination loaded")
9197
}
9298
} else {
@@ -95,7 +101,7 @@ class MixpanelDestination(
95101
}
96102

97103
override fun track(payload: TrackEvent): BaseEvent {
98-
val settings = settings ?: return payload
104+
val settings = mixpanelSettings ?: return payload
99105
// Example of transforming event property keys
100106
val eventName = payload.event
101107
val properties = payload.properties
@@ -113,7 +119,7 @@ class MixpanelDestination(
113119
}
114120

115121
override fun identify(payload: IdentifyEvent): BaseEvent {
116-
val settings = settings ?: return payload
122+
val settings = mixpanelSettings ?: return payload
117123
val userId: String = payload.userId
118124
val traits: JsonObject = payload.traits
119125

@@ -193,7 +199,7 @@ class MixpanelDestination(
193199
}
194200

195201
override fun screen(payload: ScreenEvent): BaseEvent {
196-
val settings = settings ?: return payload
202+
val settings = mixpanelSettings ?: return payload
197203
val screenName = payload.name
198204
val properties = payload.properties
199205
val screenCategory = payload.category
@@ -218,15 +224,15 @@ class MixpanelDestination(
218224
}
219225

220226
override fun onActivityCreated(activity: Activity?, savedInstanceState: Bundle?) {
221-
val settings = settings ?: return
227+
val settings = mixpanelSettings ?: return
222228
// This is needed to trigger a call to #checkIntentForInboundAppLink.
223229
// From Mixpanel's source, this won't trigger a creation of another instance. It caches
224230
// instances by the application context and token, both of which remain the same.
225231
MixpanelAPI.getInstance(
226232
activity,
227233
settings.token,
228234
false,
229-
this.settings?.trackAutomaticEvents ?: false
235+
this.mixpanelSettings?.trackAutomaticEvents ?: false
230236
)
231237
}
232238

@@ -250,7 +256,7 @@ class MixpanelDestination(
250256

251257
val revenue = properties.getDouble("revenue")
252258

253-
with(settings!!) {
259+
with(mixpanelSettings!!) {
254260
if (isPeopleEnabled && revenue != null && revenue != 0.0) {
255261
mixpanel?.people?.trackCharge(revenue, props)
256262
analytics.log("mixpanel.people.trackCharge($name, $props)")

lib/src/test/java/com/segment/analytics/kotlin/destinations/mixpanel/MixpanelDestinationTests.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ class MixpanelDestinationTests {
8080
mixpanelDestination.update(settingsBlob, Plugin.UpdateType.Initial)
8181

8282
/* assertions about config */
83-
Assertions.assertNotNull(mixpanelDestination.settings)
84-
with(mixpanelDestination.settings!!) {
83+
Assertions.assertNotNull(mixpanelDestination.mixpanelSettings)
84+
with(mixpanelDestination.mixpanelSettings!!) {
8585
Assertions.assertFalse(consolidatedPageCalls)
8686
Assertions.assertTrue(isPeopleEnabled)
8787
Assertions.assertFalse(trackAllPages)
@@ -854,7 +854,7 @@ class MixpanelDestinationTests {
854854

855855
private fun MixpanelDestination.setupTest(mixpanelSettings: MixpanelSettings) {
856856
this.mixpanel = mockMixpanel
857-
this.settings = mixpanelSettings
857+
this.mixpanelSettings = mixpanelSettings
858858
}
859859

860860
data class JsonObjectMatcher(

0 commit comments

Comments
 (0)