davide-scalzo / react-native-mixpanel

A React Native wrapper for Mixpanel tracking
MIT License
455 stars 195 forks source link

Events not being fired to Mixpanel #250

Closed luisfuertes closed 4 years ago

luisfuertes commented 4 years ago

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.

Captura de pantalla 2020-08-03 a las 15 01 01

And in live preview:

Captura de pantalla 2020-08-03 a las 15 02 58

It should show my "track" events in "Live view data" in dashborad, is correct? I cant see my data

luisfuertes commented 4 years ago

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?

luisfuertes commented 4 years ago

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'
tibbus commented 4 years ago

I tried your fix for Android, but it is still not working for me.

luisfuertes commented 4 years ago

@tibbus Your mixpanel server url is in EU?

tibbus commented 4 years ago

Yes, I got from the panel: https://api-eu.mixpanel.com

luisfuertes commented 4 years ago

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" />
luisfuertes commented 4 years ago

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

luisfuertes commented 4 years ago

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";
raburski commented 4 years ago

I have raised a small quickfix. Once/if this is merged README could be updated to surface this functionality. https://github.com/davodesign84/react-native-mixpanel/pull/253

davide-scalzo commented 4 years ago

Merged!

raburski commented 4 years ago

@davodesign84 readme updated: https://github.com/davodesign84/react-native-mixpanel/pull/254 Would that close this issue?

luisfuertes commented 4 years ago

Yes thanks.

What version is this upgrade available in?

davide-scalzo commented 4 years ago

On the latest npm version 1.2.2

luisfuertes commented 4 years ago

great thx