Skip to content

Commit 8ae4c21

Browse files
lorenc-tomaszdavide-scalzo
authored andcommitted
Add push / registration methods; update readme and typescript defs; add tvOS support, update iOS and Android SDK; make podspec package.json driven; add fine grained in-app message control; add opt in / out tracking; add autolinking information; Expose iOS params that can be passed on Mixpanel instance initalization: trackCrashes, automaticPushTracking, launchOptions; add Changelog (davide-scalzo#180)
* Update Android SDK to 5.6.0 * Lock iOS podspec to 3.4.4 * Updater package * Update Readme * Change implementation to api within gradle build * Update iOS Mixpanel to 3.4.5 * Lock iOS podspec to 3.4.5 * Update npm version * Update gitignore - add prefs and vsc project * Update index.d.ts - add clearSuperProperties * Add support for clearing a single registration id on Android * Udpate index.d.ts * [iOS] Pass deviceToken as string to `removePushDeviceToken` as it's convinient way to de-register iOS device * Update readme * Update npm version * Update README.md * [Android] Retrieves current Firebase Cloud Messaging token * Update readme.md and index.d.ts * [Android] Add getPushRegistrationId * Add missing definition * Update README.md * Update definitions and error messages * Update Android SDK to 5.6.3 * Update iOS podspec to 3.4.7 * Update npm version * Update dependencies version * [iOS] Podspec should take velues from package.json * Added support for tvOS * Add append method; update readme.md * Update Mixpanel.h * Added fine grained in-app message control * Add Opting Out / In The later versions of Mixpanel have the ability to opt in/out of collecting data for GDPR purposes. This adds support for those as well as updating the Mixpanel library. * Update version * Update doc * Add information about Autolinking * Add missing Platform import * Update readme; add changelog * Expose iOS params that can be passed on Mixpanel instance initalization: trackCrashes, automaticPushTracking, launchOptions * Fix typo
1 parent 81b49fa commit 8ae4c21

File tree

14 files changed

+1054
-613
lines changed

14 files changed

+1054
-613
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,5 @@ local.properties
3434
#
3535
node_modules/
3636
npm-debug.log
37+
*.prefs
38+
android/.project

CHANGELOG.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# 1.1.10
2+
3+
- Fix typo
4+
5+
# 1.1.9
6+
7+
- Expose iOS params that can be passed on Mixpanel instance initalization: trackCrashes, automaticPushTracking, launchOptions
8+
- Update Typescript defs and readme
9+
10+
# 1.1.8
11+
12+
- Add support for AppleTV
13+
- Add information about Autolinking from RN >= 0.60
14+
- Update podspec to be package.json driven
15+
- Add fine grained in-app message control
16+
- Update iOS SDK to 3.5.0
17+
- Update Android SDK to 5.6.5
18+
- Add opt in / opt out tracking option
19+
- Add push / registration methods
20+
- Update README
21+
- Update Typescript defs
22+
- Fix crash on clearPushRegistrationId

README.md

Lines changed: 134 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ From version 1.1.2 module uses Mixpanel SDK >= 5.6.0 that requires FCM
2424
- 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)
2525

2626

27+
# Autolinking and RN >= 0.60
28+
29+
Autolinking should work out of the box.
30+
31+
Remember to do: pod install.
32+
2733
# Manual Installation
2834

2935
## Installation iOS ##
@@ -81,12 +87,48 @@ public class MainActivity extends ReactActivity {
8187
# Usage
8288

8389
```js
84-
//Require the module
90+
// Require the module
8591
var Mixpanel = require('react-native-mixpanel');
8692

87-
//Init Mixpanel SDK with your project token
93+
// Init Mixpanel SDK with your project token
94+
// @param apiToken - your project token
8895
Mixpanel.sharedInstanceWithToken(YOUR_PROJECT_TOKEN);
8996

97+
// You can also opt out tracking by default (GDPR)
98+
// @param apiToken - your project token
99+
// @param optOutTrackingByDefault - whether or not to be opted out from tracking by default (default value: false)
100+
Mixpanel.sharedInstanceWithToken(YOUR_PROJECT_TOKEN, false);
101+
102+
// You can also disable trackCrashes
103+
// @param apiToken - your project token
104+
// @param optOutTrackingByDefault - whether or not to be opted out from tracking by default (default value: false)
105+
// @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)
106+
Mixpanel.sharedInstanceWithToken(YOUR_PROJECT_TOKEN, false, true);
107+
108+
// You can also disable automaticPushTracking
109+
// @param apiToken - your project token
110+
// @param optOutTrackingByDefault - whether or not to be opted out from tracking by default (default value: false)
111+
// @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)
112+
// @param automaticPushTracking (iOS only!) - whether or not to automatically track pushes sent from Mixpanel (default value: true)
113+
Mixpanel.sharedInstanceWithToken(YOUR_PROJECT_TOKEN, false, true, true);
114+
115+
// You can also pass launchOptions
116+
// @param apiToken - your project token
117+
// @param optOutTrackingByDefault - whether or not to be opted out from tracking by default (default value: false)
118+
// @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)
119+
// @param automaticPushTracking (iOS only!) - whether or not to automatically track pushes sent from Mixpanel (default value: true)
120+
// @param launchOptions (iOS only!) - your application delegate's launchOptions (default value: null)
121+
Mixpanel.sharedInstanceWithToken(YOUR_PROJECT_TOKEN, false, true, true, null);
122+
123+
// Opt in tracking.
124+
// 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.
125+
Mixpanel.optInTracking();
126+
127+
// Opt out tracking.
128+
129+
// 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.
130+
Mixpanel.optOutTracking();
131+
90132
//Send and event name with no properties
91133
Mixpanel.track("Event name");
92134

@@ -126,19 +168,78 @@ Mixpanel.trackChargeWithProperties(399, {"product": "ACME Wearable tech"});
126168
// increment property
127169
Mixpanel.increment("Login Count", 1);
128170

171+
// Append array to a list property
172+
Mixpanel.append("Lines", ["Simple", "Dashed"]);
173+
174+
// Merge array to a list property, excluding duplicate values
175+
Mixpanel.union("Lines", ["Dashed", "Custom"]);
176+
177+
// Android
178+
// Retrieves current Firebase Cloud Messaging token.
179+
// Should only be called after identify(String) has been called.
180+
Mixpanel.getPushRegistrationId();
181+
129182
// send push notifications token to Mixpanel
130183
// Android
131184
Mixpanel.setPushRegistrationId("GCM/FCM push token");
132185

133-
//tell Mixpanel which user record in People Analytics should receive the messages when they are sent from the Mixpanel app,
134-
//make sure you call this right after you call `identify`
186+
// Android
187+
// tell Mixpanel which user record in People Analytics should receive the messages when they are sent from the Mixpanel app,
188+
// make sure you call this right after you call `identify`
189+
// Deprecated.
190+
// 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:
191+
192+
193+
// <service
194+
// android:name="com.mixpanel.android.mpmetrics.MixpanelFCMMessagingService"
195+
// android:enabled="true"
196+
// android:exported="false">
197+
// <intent-filter>
198+
// <action android:name="com.google.firebase.MESSAGING_EVENT"/>
199+
// </intent-filter>
200+
// </service>
201+
202+
203+
204+
// Make sure you have a valid google-services.json file in your project and firebase messaging is included as a dependency. Example:
205+
206+
207+
// buildscript {
208+
// ...
209+
// dependencies {
210+
// classpath 'com.google.gms:google-services:4.1.0'
211+
// ...
212+
// }
213+
// }
214+
215+
// dependencies {
216+
// implementation 'com.google.firebase:firebase-messaging:17.3.4'
217+
// implementation 'com.mixpanel.android:mixpanel-android:5.5.0'
218+
// }
219+
220+
// apply plugin: 'com.google.gms.google-services'
221+
222+
// We recommend you update your Server Key on mixpanel.com from your Firebase console. Legacy server keys are still supported.
135223
Mixpanel.initPushHandling(YOUR_12_DIGIT_GOOGLE_SENDER_ID);
136224

137-
//unregister a device for push notifications
138-
Mixpanel.clearPushRegistrationId();
225+
// Allows to clear super properites
226+
Mixpabel.clearSuperProperties();
227+
228+
// Android
229+
// Unregister an android device for push notifications
230+
// With token it will clear a single Firebase Cloud Messaging token from Mixpanel.
231+
// Without token it will clear all current Firebase Cloud Messaging tokens from Mixpanel.
232+
Mixpanel.clearPushRegistrationId(token?: string);
233+
234+
// iOS
235+
Mixpanel.addPushDeviceToken("APNS push token");
236+
237+
// iOS - unregister iOS device, pushDeviceToken = APNS push token
238+
Mixpanel.removePushDeviceToken(pushDeviceToken: string);
139239

140240
// iOS
141-
Mixpanel.addPushDeviceToken("APNS push token")
241+
// Unregister the given device to receive push notifications.
242+
Mixpanel.removeAllPushDeviceTokens();
142243

143244
// 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.)
144245
Mixpanel.reset();
@@ -148,5 +249,31 @@ Mixpanel.reset();
148249
Mixpanel.getDistinctId(function(id){})
149250
```
150251

252+
## Displaying in-app messages ##
253+
254+
By default, in-app messages are shown to users when the app starts and a message is available to display
255+
This behaviour can be disabled by default, and explicitally triggered at a later time (e.g. after your loading sequence)
256+
257+
For iOS, in your app delegate, add the following line:
258+
259+
```
260+
// In application:didFinishLaunchingWithOptions:
261+
Mixpanel *mixpanel = [Mixpanel sharedInstanceWithToken:YOUR_MIXPANEL_TOKEN];
262+
// Turn this off so the message doesn't pop up automatically.
263+
mixpanel.showNotificationOnActive = NO;
264+
```
265+
266+
For Android, add the following to your app mainifest in the `<application>` tag:
267+
268+
```
269+
<meta-data android:name="com.mixpanel.android.MPConfig.AutoShowMixpanelUpdates" android:value="false" />
270+
```
271+
272+
You can then call the following in your react native application:
273+
274+
```
275+
Mixpanel.showInAppMessageIfAvailable();
276+
```
277+
151278
## Notes ##
152279
For more info please have a look at the [official Mixpanel reference](https://mixpanel.com/help/reference/ios) for iOS

RNMixpanel.xcodeproj/project.pbxproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
/* Begin PBXFileReference section */
4040
5EAEEA411F0555B100C6FED8 /* libRNMixpanel-tvOS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libRNMixpanel-tvOS.a"; sourceTree = BUILT_PRODUCTS_DIR; };
41+
E78DD5BC2364BED0009197B6 /* MixpanelPeople.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MixpanelPeople.h; sourceTree = "<group>"; };
4142
FDC64AF01BF1690D0044C1B4 /* libRNMixpanel.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNMixpanel.a; sourceTree = BUILT_PRODUCTS_DIR; };
4243
FDC64AF31BF1690D0044C1B4 /* RNMixpanel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNMixpanel.h; sourceTree = "<group>"; };
4344
FDC64AF51BF1690D0044C1B4 /* RNMixpanel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNMixpanel.m; sourceTree = "<group>"; };
@@ -86,6 +87,7 @@
8687
FDC64AF21BF1690D0044C1B4 /* RNMixpanel */ = {
8788
isa = PBXGroup;
8889
children = (
90+
E78DD5BC2364BED0009197B6 /* MixpanelPeople.h */,
8991
FDDAC2A11BF2B66500E70D3C /* Mixpanel.h */,
9092
FDC64AF31BF1690D0044C1B4 /* RNMixpanel.h */,
9193
FDC64AF51BF1690D0044C1B4 /* RNMixpanel.m */,
@@ -153,6 +155,7 @@
153155
developmentRegion = English;
154156
hasScannedForEncodings = 0;
155157
knownRegions = (
158+
English,
156159
en,
157160
);
158161
mainGroup = FDC64AE71BF1690D0044C1B4;

0 commit comments

Comments
 (0)