Skip to content

Commit 8a51d98

Browse files
authored
Merge pull request #160 from mixpanel/jared-serverURL
add serverURL to init params
2 parents b65cffe + 89fbce9 commit 8a51d98

File tree

7 files changed

+96
-92
lines changed

7 files changed

+96
-92
lines changed

MixpanelReactNative.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ Pod::Spec.new do |s|
1919
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }
2020

2121
s.dependency "React-Core"
22-
s.dependency "Mixpanel-swift", '4.0.1'
22+
s.dependency "Mixpanel-swift", '4.0.2'
2323
end

__tests__/index.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ test(`it calls MixpanelReactNative initialize`, async () => {
1515
test(`it calls MixpanelReactNative initialize with optOut and superProperties`, async () => {
1616
const mixpanel = new Mixpanel("token", true);
1717
mixpanel.init(true, {"super": "property"})
18-
expect(NativeModules.MixpanelReactNative.initialize).toBeCalledWith("token", true, true, {"$lib_version": "2.0.1", "mp_lib": "react-native", "super": "property"});
18+
expect(NativeModules.MixpanelReactNative.initialize).toBeCalledWith("token", true, true, {"$lib_version": "2.0.1", "mp_lib": "react-native", "super": "property"}, "https://api.mixpanel.com");
1919
});
2020

2121
test(`it calls MixpanelReactNative setServerURL`, async () => {

android/src/main/java/com/mixpanel/reactnative/MixpanelReactNativeModule.java

Lines changed: 85 additions & 84 deletions
Large diffs are not rendered by default.

index.d.ts

Lines changed: 1 addition & 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, trackAutomaticEvents: boolean);
66
static init(token: string, trackAutomaticEvents: boolean, optOutTrackingDefault?: boolean): Promise<Mixpanel>;
7-
init(optOutTrackingDefault?: boolean, superProperties?: MixpanelProperties): Promise<void>;
7+
init(optOutTrackingDefault?: boolean, superProperties?: MixpanelProperties, serverURL?: String): Promise<void>;
88
setServerURL(serverURL: string): void;
99
setLoggingEnabled(loggingEnabled: boolean): void;
1010
setFlushOnBackground(flushOnBackground: boolean): void;

index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,17 @@ export class Mixpanel {
6161
* @param {object} superProperties Optional A Map containing the key value pairs of the super properties to register
6262
*
6363
*/
64-
async init(optOutTrackingDefault = DEFAULT_OPT_OUT, superProperties = {}) {
64+
async init(optOutTrackingDefault = DEFAULT_OPT_OUT, superProperties = {}, serverURL = "https://api.mixpanel.com") {
6565
let metadata = Helper.getMetaData();
66-
await MixpanelReactNative.initialize(this.token, this.trackAutomaticEvents, optOutTrackingDefault, {...metadata, ...superProperties});
66+
await MixpanelReactNative.initialize(this.token, this.trackAutomaticEvents, optOutTrackingDefault, {...metadata, ...superProperties}, serverURL);
6767
}
6868

6969
/**
7070
* @deprecated since version 1.3.0. To initialize Mixpanel, please use the instance method `init` instead. See the example below:
7171
*
7272
* <pre><code>
73-
* const mixpanel = new Mixpanel('your project token');
73+
* const trackAutomaticEvents = true;
74+
* const mixpanel = new Mixpanel('your project token', trackAutomaticEvents);
7475
* mixpanel.init();
7576
* </code></pre>
7677
*

ios/MixpanelReactNative.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ @interface RCT_EXTERN_MODULE(MixpanelReactNative, NSObject)
55

66
// MARK: - Mixpanel Instance
77

8-
RCT_EXTERN_METHOD(initialize:(NSString *)token trackAutomaticEvents:(BOOL)trackAutomaticEvents 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 serverURL:(NSString *)serverURL resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
99

1010
// Mark: - Settings
1111
RCT_EXTERN_METHOD(setServerURL:(NSString *)token serverURL:(NSString *)serverURL resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)

ios/MixpanelReactNative.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ open class MixpanelReactNative: NSObject {
1616
trackAutomaticEvents: Bool,
1717
optOutTrackingByDefault: Bool = false,
1818
properties: [String: Any],
19+
serverURL: String,
1920
resolver resolve: RCTPromiseResolveBlock,
2021
rejecter reject: RCTPromiseRejectBlock) -> Void {
2122
AutomaticProperties.setAutomaticProperties(properties)
2223
Mixpanel.initialize(token: token, trackAutomaticEvents: trackAutomaticEvents, flushInterval: Constants.DEFAULT_FLUSH_INTERVAL,
2324
instanceName: token, optOutTrackingByDefault: optOutTrackingByDefault,
24-
superProperties: MixpanelTypeHandler.processProperties(properties: properties, includeLibInfo: true))
25+
superProperties: MixpanelTypeHandler.processProperties(properties: properties, includeLibInfo: true),
26+
serverURL: serverURL)
2527
resolve(true)
2628
}
2729

0 commit comments

Comments
 (0)