Events not being fired to Mixpanel
luisfuertes opened this issue · 14 comments
I have mixpanel configured without errors, but cant see my events or my users in Mixpanel dashboard.
To install i only write: yarn add react-native-mixpanel
and npx react-native run-android
My versions:
"react": "16.11.0",
"react-native": "0.62.2",
"react-native-mixpanel": "^1.2.0",
My App.js
import Mixpanel from 'react-native-mixpanel'
Mixpanel.sharedInstanceWithToken(MIXPANEL_TOKEN)
class App extends Component {
}
When user register:
Mixpanel.createAlias(userId)
Mixpanel.setOnce({ $email: email, Created: new Date().toISOString() })
When load auth data:
Mixpanel.identify(userId)
Mixpanel.track('event test')
Anybody return error, but in Mixpanel panel i cant see anything.
And is token, true? Not api key. To init app.
It should show my "track" events in "Live view data" in dashborad, is correct? I cant see my data
Ok in server side it solved adding api_host:
mixpanel.init("YOUR_TOKEN", { "api_host": "https://api-eu.mixpanel.com" }, "");
But how can i set api_host with react-native-mixpanel?
Ok, in android i had to add this to the manifest and it works
<meta-data android:name="com.mixpanel.android.MPConfig.EventsEndpoint"
android:value="https://api-eu.mixpanel.com/track" />
<meta-data android:name="com.mixpanel.android.MPConfig.PeopleEndpoint"
android:value="https://api-eu.mixpanel.com/engage" />
<meta-data android:name="com.mixpanel.android.MPConfig.GroupsEndpoint"
android:value="https://api-eu.mixpanel.com/groups" />
And on iOS y try to send url with launchOptions but it doesnt work.
Mixpanel.sharedInstanceWithToken(MIXPANEL_TOKEN, false, false, false, { serverURL: 'https://api-eu.mixpanel.com' })
Any idea how can i fix it on iOS? Docs in Objective-c says this:
self.mixpanel = [Mixpanel sharedInstanceWithToken:@"MIXPANEL_TOKEN" launchOptions:launchOptions];
self.mixpanel.serverURL = @"https://api-eu.mixpanel.com";
But i dont know how can i add that.
PD: This isnt work
Mixpanel.serverURL = 'https://api-eu.mixpanel.com'
I tried your fix for Android, but it is still not working for me.
@tibbus Your mixpanel server url is in EU?
Yes, I got from the panel: https://api-eu.mixpanel.com
meta-data are inside "application" in mannifest?
<application
android:name=".MainApplication"
...
android:theme="@style/AppTheme">
<meta-data android:name="com.mixpanel.android.MPConfig.EventsEndpoint"
android:value="https://api-eu.mixpanel.com/track" />
<meta-data android:name="com.mixpanel.android.MPConfig.PeopleEndpoint"
android:value="https://api-eu.mixpanel.com/engage" />
<meta-data android:name="com.mixpanel.android.MPConfig.GroupsEndpoint"
android:value="https://api-eu.mixpanel.com/groups" />
For iOS add instance.serverURL = @"https://api-eu.mixpanel.com";
in node_modules/react-native-mixpanel/RNMixpanel/RNMixpanel.m
and it works
// sharedInstanceWithToken
RCT_EXPORT_METHOD(sharedInstanceWithToken:(NSString *)apiToken
optOutTrackingByDefault:(BOOL)optOutTrackingByDefault
trackCrashes:(BOOL)trackCrashes
automaticPushTracking:(BOOL)automaticPushTracking
launchOptions:(nullable NSDictionary *)launchOptions
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject) {
@synchronized(self) {
if (instances != nil && [instances objectForKey:apiToken] != nil) {
resolve(nil);
return;
}
Mixpanel *instance = [Mixpanel sharedInstanceWithToken:apiToken
launchOptions:launchOptions
trackCrashes:trackCrashes
automaticPushTracking:automaticPushTracking
optOutTrackingByDefault:optOutTrackingByDefault];
instance.serverURL = @"https://api-eu.mixpanel.com";
// copy instances and add the new instance. then reassign instances
NSMutableDictionary *newInstances = [NSMutableDictionary dictionaryWithDictionary:instances];
[newInstances setObject:instance forKey:apiToken];
instances = [NSDictionary dictionaryWithDictionary:newInstances];
[instance applicationDidBecomeActive:nil];
resolve(nil);
}
}
I will try to submit a PR with serverURL as param, but I think there are no active collaborators
Another solution (more permanent, since you don't have to add every time you do an npm install) is to create an instance in our AppDelegate.m.
First add the import (before #if DEBUG
): #import "Mixpanel / Mixpanel.h"
and in didFinishLaunchingWithOptions:
Mixpanel *mixpanel = [Mixpanel sharedInstanceWithToken:@"MIXPANEL_TOKEN"];
mixpanel.serverURL = @"https://api-eu.mixpanel.com";
I have raised a small quickfix.
Once/if this is merged README could be updated to surface this functionality.
#253
Merged!
Yes thanks.
What version is this upgrade available in?
On the latest npm version 1.2.2
great thx