mixpanel-react-native 1.4.2 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -0
- package/{LICENSE → LICENSE.md} +1 -12
- package/MixpanelReactNative.podspec +1 -1
- package/README.md +6 -3
- package/Samples/ContextAPIMixpanel/Analytics.js +2 -1
- package/Samples/MixpanelDemo/Analytics.js +2 -2
- package/Samples/MixpanelDemo/app.json +2 -1
- package/Samples/SimpleMixpanel/App.js +2 -1
- package/__tests__/index.test.js +42 -42
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/mixpanel/reactnative/MixpanelReactNativeModule.java +84 -84
- package/docs/Mixpanel.html +60 -37
- package/docs/MixpanelGroup.html +7 -7
- package/docs/People.html +12 -12
- package/docs/index.html +7 -4
- package/docs/index.js.html +13 -8
- package/index.d.ts +2 -2
- package/index.js +12 -7
- package/ios/MixpanelReactNative.m +1 -1
- package/ios/MixpanelReactNative.swift +3 -6
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -42,24 +42,28 @@ const DEFAULT_OPT_OUT = false;
|
|
|
42
42
|
*/
|
|
43
43
|
export class Mixpanel {
|
|
44
44
|
|
|
45
|
-
constructor(token) {
|
|
45
|
+
constructor(token, trackAutomaticEvents) {
|
|
46
46
|
if (!StringHelper.isValid(token)) {
|
|
47
47
|
StringHelper.raiseError(PARAMS.TOKEN);
|
|
48
48
|
}
|
|
49
|
+
if (trackAutomaticEvents == null) {
|
|
50
|
+
throw new Error(`trackAutomaticEvents is undefined`);
|
|
51
|
+
}
|
|
49
52
|
this.token = token;
|
|
53
|
+
this.trackAutomaticEvents = trackAutomaticEvents;
|
|
50
54
|
this.people = new People(this.token);
|
|
51
55
|
}
|
|
52
56
|
|
|
53
57
|
/**
|
|
54
58
|
* Initializes Mixpanel
|
|
55
59
|
*
|
|
56
|
-
* @param {boolean} Optional Whether or not Mixpanel can start tracking by default. See optOutTracking()
|
|
57
|
-
* @param {object} Optional A Map containing the key value pairs of the super properties to register
|
|
60
|
+
* @param {boolean} optOutTrackingDefault Optional Whether or not Mixpanel can start tracking by default. See optOutTracking()
|
|
61
|
+
* @param {object} superProperties Optional A Map containing the key value pairs of the super properties to register
|
|
58
62
|
*
|
|
59
63
|
*/
|
|
60
64
|
async init(optOutTrackingDefault = DEFAULT_OPT_OUT, superProperties = {}) {
|
|
61
65
|
let metadata = Helper.getMetaData();
|
|
62
|
-
await MixpanelReactNative.initialize(this.token, optOutTrackingDefault, {...metadata, ...superProperties});
|
|
66
|
+
await MixpanelReactNative.initialize(this.token, this.trackAutomaticEvents, optOutTrackingDefault, {...metadata, ...superProperties});
|
|
63
67
|
}
|
|
64
68
|
|
|
65
69
|
/**
|
|
@@ -73,13 +77,14 @@ export class Mixpanel {
|
|
|
73
77
|
* Initializes Mixpanel and return an instance of Mixpanel the given project token.
|
|
74
78
|
*
|
|
75
79
|
* @param {string} token your project token.
|
|
80
|
+
* @param {boolean} trackAutomaticEvents Whether or not to automatically track common mobile events
|
|
76
81
|
* @param {boolean} Optional Whether or not Mixpanel can start tracking by default. See optOutTracking()
|
|
77
82
|
*
|
|
78
83
|
*/
|
|
79
|
-
static async init(token, optOutTrackingDefault = DEFAULT_OPT_OUT) {
|
|
84
|
+
static async init(token, trackAutomaticEvents, optOutTrackingDefault = DEFAULT_OPT_OUT) {
|
|
80
85
|
let metadata = Helper.getMetaData();
|
|
81
|
-
await MixpanelReactNative.initialize(token, optOutTrackingDefault, metadata);
|
|
82
|
-
return new Mixpanel(token);
|
|
86
|
+
await MixpanelReactNative.initialize(token, trackAutomaticEvents, optOutTrackingDefault, metadata);
|
|
87
|
+
return new Mixpanel(token, trackAutomaticEvents);
|
|
83
88
|
}
|
|
84
89
|
|
|
85
90
|
/**
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
// MARK: - Mixpanel Instance
|
|
7
7
|
|
|
8
|
-
RCT_EXTERN_METHOD(initialize:(NSString *)token optOutTrackingByDefault:(BOOL)optOutTrackingByDefault properties:(NSDictionary *)properties resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
|
|
8
|
+
RCT_EXTERN_METHOD(initialize:(NSString *)token trackAutomaticEvents:(BOOL)trackAutomaticEvents optOutTrackingByDefault:(BOOL)optOutTrackingByDefault properties:(NSDictionary *)properties resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
|
|
9
9
|
|
|
10
10
|
// Mark: - Settings
|
|
11
11
|
RCT_EXTERN_METHOD(setServerURL:(NSString *)token serverURL:(NSString *)serverURL resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
|
|
@@ -13,12 +13,13 @@ open class MixpanelReactNative: NSObject {
|
|
|
13
13
|
|
|
14
14
|
@objc
|
|
15
15
|
func initialize(_ token: String,
|
|
16
|
+
trackAutomaticEvents: Bool,
|
|
16
17
|
optOutTrackingByDefault: Bool = false,
|
|
17
18
|
properties: [String: Any],
|
|
18
19
|
resolver resolve: RCTPromiseResolveBlock,
|
|
19
20
|
rejecter reject: RCTPromiseRejectBlock) -> Void {
|
|
20
21
|
AutomaticProperties.setAutomaticProperties(properties)
|
|
21
|
-
Mixpanel.initialize(token: token, flushInterval: Constants.DEFAULT_FLUSH_INTERVAL,
|
|
22
|
+
Mixpanel.initialize(token: token, trackAutomaticEvents: trackAutomaticEvents, flushInterval: Constants.DEFAULT_FLUSH_INTERVAL,
|
|
22
23
|
instanceName: token, optOutTrackingByDefault: optOutTrackingByDefault,
|
|
23
24
|
superProperties: MixpanelTypeHandler.processProperties(properties: properties, includeLibInfo: true))
|
|
24
25
|
resolve(true)
|
|
@@ -439,11 +440,7 @@ open class MixpanelReactNative: NSObject {
|
|
|
439
440
|
if token.isEmpty {
|
|
440
441
|
return nil
|
|
441
442
|
}
|
|
442
|
-
|
|
443
|
-
if instance == nil {
|
|
444
|
-
instance = Mixpanel.initialize(token: token, instanceName: token)
|
|
445
|
-
}
|
|
446
|
-
return instance
|
|
443
|
+
return Mixpanel.getInstance(name: token)
|
|
447
444
|
}
|
|
448
445
|
|
|
449
446
|
}
|