Skip to content

Commit

Permalink
Support EU API URL and bump Mixpanel to 7.3.3 from 7.3.0 (#7)
Browse files Browse the repository at this point in the history
* Support EU api URL.

* Bumb mixpanel to latest fix version 7.3.3
  • Loading branch information
didiergarcia authored Feb 27, 2024
1 parent 600b97b commit 6be1491
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ dependencies {

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

// Test Dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ SOFTWARE.
@Serializable
data class MixpanelSettings(
var token: String,
var enableEuropeanUnionEndpoint: Boolean = false,
@SerialName("people")
var isPeopleEnabled: Boolean = false,
var setAllTraitsByDefault: Boolean = true,
Expand All @@ -71,7 +72,7 @@ class MixpanelDestination(
private val context: Context
) : DestinationPlugin(), AndroidLifecycle, VersionedPlugin {

internal var settings: MixpanelSettings? = null
internal var mixpanelSettings: MixpanelSettings? = null
internal var mixpanel: MixpanelAPI? = null

override val key: String = "Mixpanel"
Expand All @@ -80,13 +81,18 @@ class MixpanelDestination(
super.update(settings, type)
if (settings.hasIntegrationSettings(this)) {
analytics.log("Mixpanel Destination is enabled")
this.settings = settings.destinationSettings(key)
this.mixpanelSettings = settings.destinationSettings(key)
if (type == Plugin.UpdateType.Initial) {
mixpanel = MixpanelAPI.getInstance(
context,
this.settings?.token,
this.settings?.trackAutomaticEvents ?: false
this.mixpanelSettings?.token,
this.mixpanelSettings?.trackAutomaticEvents ?: false
)

if (mixpanelSettings?.enableEuropeanUnionEndpoint == true) {
mixpanel?.setServerURL("https://api-eu.mixpanel.com")
}

analytics.log("Mixpanel Destination loaded")
}
} else {
Expand All @@ -95,7 +101,7 @@ class MixpanelDestination(
}

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

override fun identify(payload: IdentifyEvent): BaseEvent {
val settings = settings ?: return payload
val settings = mixpanelSettings ?: return payload
val userId: String = payload.userId
val traits: JsonObject = payload.traits

Expand Down Expand Up @@ -193,7 +199,7 @@ class MixpanelDestination(
}

override fun screen(payload: ScreenEvent): BaseEvent {
val settings = settings ?: return payload
val settings = mixpanelSettings ?: return payload
val screenName = payload.name
val properties = payload.properties
val screenCategory = payload.category
Expand All @@ -218,15 +224,15 @@ class MixpanelDestination(
}

override fun onActivityCreated(activity: Activity?, savedInstanceState: Bundle?) {
val settings = settings ?: return
val settings = mixpanelSettings ?: return
// 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,
false,
this.settings?.trackAutomaticEvents ?: false
this.mixpanelSettings?.trackAutomaticEvents ?: false
)
}

Expand All @@ -250,7 +256,7 @@ class MixpanelDestination(

val revenue = properties.getDouble("revenue")

with(settings!!) {
with(mixpanelSettings!!) {
if (isPeopleEnabled && revenue != null && revenue != 0.0) {
mixpanel?.people?.trackCharge(revenue, props)
analytics.log("mixpanel.people.trackCharge($name, $props)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ class MixpanelDestinationTests {
mixpanelDestination.update(settingsBlob, Plugin.UpdateType.Initial)

/* assertions about config */
Assertions.assertNotNull(mixpanelDestination.settings)
with(mixpanelDestination.settings!!) {
Assertions.assertNotNull(mixpanelDestination.mixpanelSettings)
with(mixpanelDestination.mixpanelSettings!!) {
Assertions.assertFalse(consolidatedPageCalls)
Assertions.assertTrue(isPeopleEnabled)
Assertions.assertFalse(trackAllPages)
Expand Down Expand Up @@ -854,7 +854,7 @@ class MixpanelDestinationTests {

private fun MixpanelDestination.setupTest(mixpanelSettings: MixpanelSettings) {
this.mixpanel = mockMixpanel
this.settings = mixpanelSettings
this.mixpanelSettings = mixpanelSettings
}

data class JsonObjectMatcher(
Expand Down

0 comments on commit 6be1491

Please sign in to comment.