https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
j

jean

12/10/2020, 3:05 PM
I’m trying to integrate mixpanel to a js target but I’m not sure how to do it. That’s what I have for ios :
Copy code
import cocoapods.Mixpanel.Mixpanel

actual class MixpanelFactory {
    actual fun createTracker(): Tracker {
        val actualMixpanel = Mixpanel("", mapOf<Any?, Any>(), 0)
        return object : Tracker {
            override fun sendEvent(event: Event) {
                actualMixpanel.track(event.name, event.asMap() as Map<Any?, Any>)
            }
        }
    }
}
I did add the npm dependency for the js target and tried something like this, to not avail :
Copy code
@JsModule("mixpanel-browser")
external val mixpanel: Mixpanel

actual class MixpanelFactory {
    actual fun createTracker(): Tracker {
        val actualMixpanel = Mixpanel("")
        return object : Tracker {
            override fun sendEvent(event: Event) {
                actualMixpanel.track(event.name, event.asMap())
            }
        }
    }
}

// js code to use
var mixpanel = require('mixpanel-browser');
mixpanel.init("YOUR_TOKEN");
mixpanel.track("Sign up");
for anyone that might be running into this problem too, it’s actually quite simple. All you need is love
Copy code
val actualMixpanel = js("mixpanel")
5 Views