Skip to content

Commit fb822e3

Browse files
authored
Merge pull request #127 from mixpanel/jared-add-init-super-props
add init super props & declare multi-prop interfaces
2 parents 09d3cd2 + 62dbc40 commit fb822e3

File tree

3 files changed

+33
-23
lines changed

3 files changed

+33
-23
lines changed

__tests__/index.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ test(`it calls MixpanelReactNative initialize`, async () => {
1212
expect(NativeModules.MixpanelReactNative.initialize).toBeCalledWith("token", false, {"$lib_version": "1.3.7", "mp_lib": "react-native"});
1313
});
1414

15+
test(`it calls MixpanelReactNative initialize with optOut and superProperties`, async () => {
16+
const mixpanel = new Mixpanel("token");
17+
mixpanel.init(true, {"super": "property"})
18+
expect(NativeModules.MixpanelReactNative.initialize).toBeCalledWith("token", true, {"$lib_version": "1.3.7", "mp_lib": "react-native", "super": "property"});
19+
});
20+
1521
test(`it calls MixpanelReactNative setServerURL`, async () => {
1622
const mixpanel = await Mixpanel.init("token");
1723
mixpanel.setServerURL("https://api-eu.mixpanel.com");

index.d.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ type MixpanelProperties = { [key: string]: MixpanelType };
44
export class Mixpanel {
55
constructor(token: string);
66
static init(token: string, optOutTrackingDefault?: boolean): Promise<Mixpanel>;
7-
init(optOutTrackingDefault?: boolean): Promise<void>;
7+
init(optOutTrackingDefault?: boolean, superProperties?: MixpanelProperties): Promise<void>;
88
setServerURL(serverURL: string): void;
99
setLoggingEnabled(loggingEnabled: boolean): void;
1010
setUseIpAddressForGeolocation(useIpAddressForGeolocation: boolean): void;
@@ -36,8 +36,11 @@ export class Mixpanel {
3636
export class People {
3737
constructor(token: string);
3838
set(prop: string, to: MixpanelType): void;
39+
set(properties: MixpanelProperties): void;
3940
setOnce(prop: string, to: MixpanelType): void;
41+
setOnce(properties: MixpanelProperties): void;
4042
increment(prop: string, by: number): void;
43+
increment(properties: MixpanelProperties): void;
4144
append(name: string, value: MixpanelType): void;
4245
union(name: string, value: Array<MixpanelType>): void;
4346
remove(name: string, value: MixpanelType): void;

index.js

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,12 @@ export class Mixpanel {
5454
* Initializes Mixpanel
5555
*
5656
* @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
5758
*
5859
*/
59-
async init(optOutTrackingDefault = DEFAULT_OPT_OUT) {
60+
async init(optOutTrackingDefault = DEFAULT_OPT_OUT, superProperties = {}) {
6061
let metadata = Helper.getMetaData();
61-
await MixpanelReactNative.initialize(this.token, optOutTrackingDefault, metadata);
62+
await MixpanelReactNative.initialize(this.token, optOutTrackingDefault, {...metadata, ...superProperties});
6263
}
6364

6465
/**
@@ -68,12 +69,12 @@ export class Mixpanel {
6869
* const mixpanel = new Mixpanel('your project token');
6970
* mixpanel.init();
7071
* </code></pre>
71-
*
72+
*
7273
* Initializes Mixpanel and return an instance of Mixpanel the given project token.
7374
*
7475
* @param {string} token your project token.
7576
* @param {boolean} Optional Whether or not Mixpanel can start tracking by default. See optOutTracking()
76-
*
77+
*
7778
*/
7879
static async init(token, optOutTrackingDefault = DEFAULT_OPT_OUT) {
7980
let metadata = Helper.getMetaData();
@@ -87,7 +88,7 @@ export class Mixpanel {
8788
* To route data to Mixpanel's EU servers, set to https://api-eu.mixpanel.com
8889
*
8990
* @param {string} serverURL the base URL used for Mixpanel API requests
90-
*
91+
*
9192
*/
9293
setServerURL(serverURL) {
9394
MixpanelReactNative.setServerURL(this.token, serverURL);
@@ -96,23 +97,23 @@ export class Mixpanel {
9697
/**
9798
* This allows enabling or disabling of all Mixpanel logs at run time.
9899
* All logging is disabled by default. Usually, this is only required if
99-
* you are running into issues with the SDK that you want to debug
100-
*
100+
* you are running into issues with the SDK that you want to debug
101+
*
101102
* @param {boolean} loggingEnabled whether to enable logging
102-
*
103+
*
103104
*/
104105
setLoggingEnabled(loggingEnabled) {
105106
MixpanelReactNative.setLoggingEnabled(this.token, loggingEnabled);
106107
}
107108

108109
/**
109110
* This controls whether to automatically send the client IP Address as part of event tracking.
110-
* With an IP address, geo-location is possible down to neighborhoods within a city,
111+
* With an IP address, geo-location is possible down to neighborhoods within a city,
111112
* although the Mixpanel Dashboard will just show you city level location specificity.
112-
*
113-
* @param {boolean} useIpAddressForGeolocation whether to automatically send the client IP Address.
113+
*
114+
* @param {boolean} useIpAddressForGeolocation whether to automatically send the client IP Address.
114115
* Defaults to true.
115-
*
116+
*
116117
*/
117118
setUseIpAddressForGeolocation(useIpAddressForGeolocation) {
118119
MixpanelReactNative.setUseIpAddressForGeolocation(this.token, useIpAddressForGeolocation);
@@ -126,7 +127,7 @@ export class Mixpanel {
126127
hasOptedOutTracking() {
127128
return MixpanelReactNative.hasOptedOutTracking(this.token);
128129
}
129-
130+
130131
/**
131132
* Use this method to opt-in an already opted-out user from tracking. People updates and track
132133
* calls will be sent to Mixpanel after using this method.
@@ -176,10 +177,10 @@ export class Mixpanel {
176177
/**
177178
* The alias method creates an alias which Mixpanel will use to remap one id to another.
178179
* Multiple aliases can point to the same identifier.
179-
*
180+
*
180181
* `mixpane.alias("New ID", mixpane.distinctId)`
181182
* `mixpane.alias("Newer ID", mixpane.distinctId)`
182-
*
183+
*
183184
* <p>This call does not identify the user after. You must still call both identify() and
184185
* People.identify() if you wish the new alias to be used for Events and People.
185186
*
@@ -242,7 +243,7 @@ export class Mixpanel {
242243
* Pass null if no extra properties exist.
243244
* @param {object} groups A Map containing the group key value pairs for this event.
244245
*
245-
*/
246+
*/
246247
trackWithGroups(eventName, properties, groups) {
247248
if (!StringHelper.isValid(eventName)) {
248249
StringHelper.raiseError(PARAMS.EVENT_NAME);
@@ -434,13 +435,13 @@ export class Mixpanel {
434435
}
435436

436437
/**
437-
* Returns the current distinct id of the user.
438+
* Returns the current distinct id of the user.
438439
* This is either the id automatically generated by the library or the id that has been passed by a call to identify().
439-
*
440-
* example of usage:
440+
*
441+
* example of usage:
441442
* <pre>
442443
* <code>
443-
* const distinctId = await mixpanel.getDistinctId();
444+
* const distinctId = await mixpanel.getDistinctId();
444445
* </code>
445446
* </pre>
446447
*
@@ -730,7 +731,7 @@ export class MixpanelGroup {
730731

731732
/**
732733
* Permanently removes the property with the given name from the group's profile
733-
*
734+
*
734735
* @param {string} prop name of a property to unset
735736
*/
736737
unset(prop) {
@@ -744,7 +745,7 @@ export class MixpanelGroup {
744745
* Remove value from a list-valued property only if it is already present in the list.
745746
* If the property does not currently exist, the remove will be ignored.
746747
* If the property exists and is not list-valued, the remove will be ignored.
747-
*
748+
*
748749
* @param {string} name the Group Analytics list-valued property that should have a value removed
749750
* @param {any} value the value that will be removed from the list
750751
*/

0 commit comments

Comments
 (0)