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

Update for RN 61 #1

Open
wants to merge 29 commits into
base: update
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b729d57
Added support for tvOS
gustavogenovese Oct 10, 2019
81b49fa
Merge pull request #199 from gcesarmza/master
aakashsigdel Oct 25, 2019
8ae4c21
Add push / registration methods; update readme and typescript defs; a…
lorenc-tomasz Oct 30, 2019
a522f0b
Method createAlias should accept two parameters; Update Android SDK t…
lorenc-tomasz Dec 20, 2019
332984f
Add support for clearing a single registration id on Android (#155)
jeanregisser Dec 20, 2019
e379c4c
Add methods add, set for Group Analytics. Only single values supporte…
danactive Jan 22, 2020
025371f
Update due the version of Mixpanel on cocoapods (#224)
douglasdc Mar 2, 2020
ee1e4bb
updated version
davide-scalzo Mar 2, 2020
9b0cd43
feat: allow serverURL customisation through info plist (#253)
raburski Aug 18, 2020
c9bacf0
updated package.json
davide-scalzo Aug 18, 2020
5fe17ed
chore: mixpanel urls readme (#254)
raburski Aug 21, 2020
39becf9
bumped package.json version
davide-scalzo Aug 21, 2020
ed14029
Fix `showInAppMessageIfAvailable` (#257)
DipanshKhandelwal Sep 24, 2020
9d37a13
1.2.3 (#259)
Sep 24, 2020
ce4de9c
Upgrade Mixpanel Android SDK to 5.8.5
kyleclegg Nov 17, 2020
7db8685
Merge pull request #264 from davodesign84/mixpanel-android-upgrade-5.8.5
kyleclegg Nov 18, 2020
6cd8046
Added access to the setAppSessionPropertiesIOS which was not exposed …
ddolheguy Nov 27, 2020
6456ef8
Attempting to fix null reference issue
mr-ryan-james Nov 30, 2020
7de97cc
Fixing null reference issue
mr-ryan-james Nov 30, 2020
4def74e
fixing issue with null reference
mr-ryan-james Nov 30, 2020
f462988
adding changelot and increasing version
mr-ryan-james Nov 30, 2020
d77ee17
Update CHANGELOG.md
mr-ryan-james Nov 30, 2020
c8160fd
to be super careful, also checking if people are null
mr-ryan-james Nov 30, 2020
7463dc9
Merge branch 'master' of github.com:mr-ryan-james/react-native-mixpanel
mr-ryan-james Nov 30, 2020
f3f9a41
fixing wrong message in changelog
mr-ryan-james Nov 30, 2020
a36c2c3
Update CHANGELOG.md
mr-ryan-james Nov 30, 2020
2b08de4
Merge pull request #267 from mr-ryan-james/master
kyleclegg Dec 1, 2020
f06c960
Update release notes for 1.2.5 (#268)
kyleclegg Dec 1, 2020
4ebdf3f
Update README.md
davide-scalzo Aug 6, 2021
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: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ local.properties
#
node_modules/
npm-debug.log
*.prefs
android/.project
48 changes: 48 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# 1.2.5

- [Android] Fix an uncommon issue with this.getCurrentActivity returning null inside of showInAppMessageIfAvailable
- [iOS] Add access to setAppSessionPropertiesIOS

# 1.2.4

- [Android] Update Mixpanel Android SDK to 5.8.5

# 1.1.14

- [Android] Add check against potential NPE
- Update Readme

# 1.1.13

- [Android] Update mixpanel-android SDK to 5.6.8

# 1.1.12

- Method createAlias should accept two parameters (https://developer.mixpanel.com/docs/javascript-full-api-reference#section-mixpanel-alias). Second parameter is optional to keep backward compatabiluty. Will fallback to distinctID generated by mixpanel instance.

# 1.1.11

- [iOS] Add missing file

# 1.1.10

- Fix typo

# 1.1.9

- Expose iOS params that can be passed on Mixpanel instance initalization: trackCrashes, automaticPushTracking, launchOptions
- Update Typescript defs and readme

# 1.1.8

- Add support for AppleTV
- Add information about Autolinking from RN >= 0.60
- Update podspec to be package.json driven
- Add fine grained in-app message control
- Update iOS SDK to 3.5.0
- Update Android SDK to 5.6.5
- Add opt in / opt out tracking option
- Add push / registration methods
- Update README
- Update Typescript defs
- Fix crash on clearPushRegistrationId
213 changes: 200 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@

# DEPRECATED
Please check out the official bindings at https://github.com/mixpanel/mixpanel-react-native


![npm](https://img.shields.io/npm/dt/react-native-mixpanel.svg?style=for-the-badge)

![npm](https://img.shields.io/npm/dm/react-native-mixpanel.svg?style=for-the-badge)
Expand All @@ -24,6 +29,12 @@ From version 1.1.2 module uses Mixpanel SDK >= 5.6.0 that requires FCM
- Allow sub-classes to override push notifications payload and Support when more than one push provider is used [more info here](https://github.com/mixpanel/mixpanel-android/releases/tag/v5.5.1)


# Autolinking and RN >= 0.60

Autolinking should work out of the box.

Remember to do: pod install.

# Manual Installation

## Installation iOS ##
Expand Down Expand Up @@ -81,30 +92,90 @@ public class MainActivity extends ReactActivity {
# Usage

```js
//Require the module
// Require the module
var Mixpanel = require('react-native-mixpanel');

//Init Mixpanel SDK with your project token
// Init Mixpanel SDK with your project token
// @param apiToken - your project token
Mixpanel.sharedInstanceWithToken(YOUR_PROJECT_TOKEN);

//Send and event name with no properties
// You can also opt out tracking by default (GDPR)
// @param apiToken - your project token
// @param optOutTrackingByDefault - whether or not to be opted out from tracking by default (default value: false)
Mixpanel.sharedInstanceWithToken(YOUR_PROJECT_TOKEN, false);

// You can also disable trackCrashes
// @param apiToken - your project token
// @param optOutTrackingByDefault - whether or not to be opted out from tracking by default (default value: false)
// @param trackCrashes (iOS only!) - whether or not to track crashes in Mixpanel. may want to disable if you're seeing issues with your crash reporting for either signals or exceptions (default value: true)
Mixpanel.sharedInstanceWithToken(YOUR_PROJECT_TOKEN, false, true);

// You can also disable automaticPushTracking
// @param apiToken - your project token
// @param optOutTrackingByDefault - whether or not to be opted out from tracking by default (default value: false)
// @param trackCrashes (iOS only!) - whether or not to track crashes in Mixpanel. may want to disable if you're seeing issues with your crash reporting for either signals or exceptions (default value: true)
// @param automaticPushTracking (iOS only!) - whether or not to automatically track pushes sent from Mixpanel (default value: true)
Mixpanel.sharedInstanceWithToken(YOUR_PROJECT_TOKEN, false, true, true);

// You can also pass launchOptions
// @param apiToken - your project token
// @param optOutTrackingByDefault - whether or not to be opted out from tracking by default (default value: false)
// @param trackCrashes (iOS only!) - whether or not to track crashes in Mixpanel. may want to disable if you're seeing issues with your crash reporting for either signals or exceptions (default value: true)
// @param automaticPushTracking (iOS only!) - whether or not to automatically track pushes sent from Mixpanel (default value: true)
// @param launchOptions (iOS only!) - your application delegate's launchOptions (default value: null)
Mixpanel.sharedInstanceWithToken(YOUR_PROJECT_TOKEN, false, true, true, null);

// Opt in tracking.
// Use this method to opt in an already opted out user from tracking. People updates and track calls will be sent to Mixpanel after using this method.
Mixpanel.optInTracking();

// Opt out tracking.

// This method is used to opt out tracking. This causes all events and people request no longer to be sent back to the Mixpanel server.
Mixpanel.optOutTracking();

// Send and event name with no properties
Mixpanel.track("Event name");

//Track event with properties
// Track event with properties
Mixpanel.trackWithProperties('Click Button', {button_type: 'yellow button', button_text: 'magic button'});

//Create Alias from unique id, i.e. create a new mixpanel profile: to call when a user signs up, with a unique id that is not used by another mixpanel profile as param
// Create Alias from unique id, i.e. create a new mixpanel profile: to call when a user signs up, with a unique id that is not used by another mixpanel profile as param
Mixpanel.createAlias(UNIQUE_ID)

//Identify, i.e. associate to an existing mixpanel profile: to call when a user logs in and is already registered in Mixpanel with this unique id
// OR:

// Create an alias, which Mixpanel will use to link two distinct_ids going forward (not retroactively). Multiple aliases can map to the same original ID, but not vice-versa.
// Aliases can also be chained - the following is a valid scenario:
Mixpanel.createAlias('new_id', 'existing_id');
...
Mixpanel.createAlias('newer_id', 'new_id');
// If the original ID is not passed in, we will use the current distinct_id - probably the auto-generated GUID.
// Notes:
// The best practice is to call createAlias() when a unique ID is first created for a user (e.g., when a user first registers for
// an account and provides an email address). createAlias() should never be called more than once for a given user, except to chain
// a newer ID to a previously new ID, as described above.
// More info about createAlias: https://developer.mixpanel.com/docs/javascript-full-api-reference#section-mixpanel-alias

// Identify, i.e. associate to an existing mixpanel profile: to call when a user logs in and is already registered in Mixpanel with this unique id
Mixpanel.identify(UNIQUE_ID)

//Set People properties (warning: if no mixpanel profile has been assigned to the current user when this method is called, it will automatically create a new mixpanel profile and the user will no longer be anonymous in Mixpanel)
// Set People properties (warning: if no mixpanel profile has been assigned to the current user when this method is called, it will automatically create a new mixpanel profile and the user will no longer be anonymous in Mixpanel)
Mixpanel.set({"$email": "[email protected]"});

//Set People Properties Once (warning: if no mixpanel profile has been assigned to the current user when this method is called, it will automatically create a new mixpanel profile and the user will no longer be anonymous in Mixpanel)
// Set People Properties Once (warning: if no mixpanel profile has been assigned to the current user when this method is called, it will automatically create a new mixpanel profile and the user will no longer be anonymous in Mixpanel)
Mixpanel.setOnce({"$email": "[email protected]", "Created": new Date().toISOString()});

// Add a new Group for this user.
// @param Group key
// @param A valid Mixpanel property type
Mixpanel.setGroup('company', 'mixpanel');

// Register the current user into one Group. The Group must be added before setting
// @param Group key
// @param a singular group ID
Mixpanel.setGroup('company', 'mixpanel');

// Timing Events
// Sets the start time for an action, for example uploading an image
Mixpanel.timeEvent("Image Upload");
Expand All @@ -126,19 +197,85 @@ Mixpanel.trackChargeWithProperties(399, {"product": "ACME Wearable tech"});
// increment property
Mixpanel.increment("Login Count", 1);

// Append array to a list property
Mixpanel.append("Lines", ["Simple", "Dashed"]);

// Merge array to a list property, excluding duplicate values
Mixpanel.union("Lines", ["Dashed", "Custom"]);

// Android
// Retrieves current Firebase Cloud Messaging token.
// Should only be called after identify(String) has been called.
Mixpanel.getPushRegistrationId();

// send push notifications token to Mixpanel
// Android
Mixpanel.setPushRegistrationId("GCM/FCM push token");

//tell Mixpanel which user record in People Analytics should receive the messages when they are sent from the Mixpanel app,
//make sure you call this right after you call `identify`
// Android
// tell Mixpanel which user record in People Analytics should receive the messages when they are sent from the Mixpanel app,
// make sure you call this right after you call `identify`
// Deprecated.
// in 5.5.0. Google Cloud Messaging (GCM) is now deprecated by Google. To enable end-to-end Firebase Cloud Messaging (FCM) from Mixpanel you only need to add the following to your application manifest XML file:


// <service
// android:name="com.mixpanel.android.mpmetrics.MixpanelFCMMessagingService"
// android:enabled="true"
// android:exported="false">
// <intent-filter>
// <action android:name="com.google.firebase.MESSAGING_EVENT"/>
// </intent-filter>
// </service>



// Make sure you have a valid google-services.json file in your project and firebase messaging is included as a dependency. Example:


// buildscript {
// ...
// dependencies {
// classpath 'com.google.gms:google-services:4.1.0'
// ...
// }
// }

// dependencies {
// implementation 'com.google.firebase:firebase-messaging:17.3.4'
// implementation 'com.mixpanel.android:mixpanel-android:5.5.0'
// }

// apply plugin: 'com.google.gms.google-services'

// We recommend you update your Server Key on mixpanel.com from your Firebase console. Legacy server keys are still supported.
Mixpanel.initPushHandling(YOUR_12_DIGIT_GOOGLE_SENDER_ID);

//unregister a device for push notifications
Mixpanel.clearPushRegistrationId();
// Allows to clear super properites
Mixpabel.clearSuperProperties();

// Android
// Unregister an android device for push notifications
// With token it will clear a single Firebase Cloud Messaging token from Mixpanel.
// Without token it will clear all current Firebase Cloud Messaging tokens from Mixpanel.
Mixpanel.clearPushRegistrationId(token?: string);

// iOS
Mixpanel.addPushDeviceToken("APNS push token")
Mixpanel.addPushDeviceToken("APNS push token");

// iOS - unregister iOS device, pushDeviceToken = APNS push token
Mixpanel.removePushDeviceToken(pushDeviceToken: string);

// iOS
// Unregister the given device to receive push notifications.
Mixpanel.removeAllPushDeviceTokens();

// iOS
// Allows control of the min/max sessions
Mixpanel.setAppSessionPropertiesIOS({
minimumSessionDuration: 60,
maximumSessionDuration: 10,
});

// Mixpanel reset method (warning: it will also generate a new unique id and call the identify method with it. Thus, the user will not be anonymous in Mixpanel.)
Mixpanel.reset();
Expand All @@ -148,5 +285,55 @@ Mixpanel.reset();
Mixpanel.getDistinctId(function(id){})
```

## Displaying in-app messages ##

By default, in-app messages are shown to users when the app starts and a message is available to display
This behaviour can be disabled by default, and explicitally triggered at a later time (e.g. after your loading sequence)

For iOS, in your app delegate, add the following line:

```
// In application:didFinishLaunchingWithOptions:
Mixpanel *mixpanel = [Mixpanel sharedInstanceWithToken:YOUR_MIXPANEL_TOKEN];
// Turn this off so the message doesn't pop up automatically.
mixpanel.showNotificationOnActive = NO;
```

For Android, add the following to your app mainifest in the `<application>` tag:

```
<meta-data android:name="com.mixpanel.android.MPConfig.AutoShowMixpanelUpdates" android:value="false" />
```

You can then call the following in your react native application:

```
Mixpanel.showInAppMessageIfAvailable();
```

More info: https://developer.mixpanel.com/docs/android-inapp-messages

## Configure mixpanel urls

Add server url in `.plist` files in iOS project.

```
<key>com.mixpanel.config.serverURL</key>
<string>https://api-eu.mixpanel.com</string>
```

Add endpoints to `manifest` in your Android project.

```
<application ...>
<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" />
</application>
```

## Notes ##
For more info please have a look at the [official Mixpanel reference](https://mixpanel.com/help/reference/ios) for iOS
5 changes: 5 additions & 0 deletions RNMixpanel.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@

/* Begin PBXFileReference section */
5EAEEA411F0555B100C6FED8 /* libRNMixpanel-tvOS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libRNMixpanel-tvOS.a"; sourceTree = BUILT_PRODUCTS_DIR; };
E7588479238556670081D7FF /* MixpanelType.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MixpanelType.h; sourceTree = "<group>"; };
E78DD5BC2364BED0009197B6 /* MixpanelPeople.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MixpanelPeople.h; sourceTree = "<group>"; };
FDC64AF01BF1690D0044C1B4 /* libRNMixpanel.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNMixpanel.a; sourceTree = BUILT_PRODUCTS_DIR; };
FDC64AF31BF1690D0044C1B4 /* RNMixpanel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNMixpanel.h; sourceTree = "<group>"; };
FDC64AF51BF1690D0044C1B4 /* RNMixpanel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNMixpanel.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -86,6 +88,8 @@
FDC64AF21BF1690D0044C1B4 /* RNMixpanel */ = {
isa = PBXGroup;
children = (
E78DD5BC2364BED0009197B6 /* MixpanelPeople.h */,
E7588479238556670081D7FF /* MixpanelType.h */,
FDDAC2A11BF2B66500E70D3C /* Mixpanel.h */,
FDC64AF31BF1690D0044C1B4 /* RNMixpanel.h */,
FDC64AF51BF1690D0044C1B4 /* RNMixpanel.m */,
Expand Down Expand Up @@ -153,6 +157,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
);
mainGroup = FDC64AE71BF1690D0044C1B4;
Expand Down
Loading