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

Support EU API URL and bump Mixpanel to 7.3.3 from 7.3.0 #7

Merged
merged 2 commits into from
Feb 27, 2024
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
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
Loading