Skip to content

Commit bc0b19f

Browse files
authored
Merge pull request #18 from mixpanel/more-config-options
Add API `setUseIpAddressForGeolocation`
2 parents 1a160e5 + 60cc14e commit bc0b19f

File tree

7 files changed

+108
-31
lines changed

7 files changed

+108
-31
lines changed

android/src/main/java/com/mixpanel/mixpanel_flutter/MixpanelFlutterPlugin.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
5656
case "initialize":
5757
handleInitialize(call, result);
5858
break;
59+
case "setServerURL":
60+
handleSetServerURL(call, result);
61+
break;
62+
case "setLoggingEnabled":
63+
handleSetLoggingEnabled(call, result);
64+
break;
65+
case "setUseIpAddressForGeolocation":
66+
handleSetUseIpAddressForGeolocation(call, result);
67+
break;
5968
case "hasOptedOutTracking":
6069
handleHasOptedOutTracking(call, result);
6170
break;
@@ -186,6 +195,24 @@ private void handleInitialize(MethodCall call, Result result) {
186195
result.success(Integer.toString(mixpanel.hashCode()));
187196
}
188197

198+
private void handleSetServerURL(MethodCall call, Result result) {
199+
String serverURL = call.argument("serverURL");
200+
mixpanel.setServerURL(serverURL);
201+
result.success(null);
202+
}
203+
204+
private void handleSetLoggingEnabled(MethodCall call, Result result) {
205+
Boolean enableLogging = call.argument("loggingEnabled");
206+
mixpanel.setEnableLogging(enableLogging);
207+
result.success(null);
208+
}
209+
210+
private void handleSetUseIpAddressForGeolocation(MethodCall call, Result result) {
211+
Boolean useIpAddressForGeolocation = call.argument("useIpAddressForGeolocation");
212+
mixpanel.setUseIpAddressForGeolocation(useIpAddressForGeolocation);
213+
result.success(null);
214+
}
215+
189216
private void handleHasOptedOutTracking(MethodCall call, Result result) {
190217
result.success(mixpanel.hasOptedOutTracking());
191218
}

example/ios/Podfile.lock

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
PODS:
22
- Flutter (1.0.0)
3-
- Mixpanel-swift (2.8.3):
4-
- Mixpanel-swift/Complete (= 2.8.3)
5-
- Mixpanel-swift/Complete (2.8.3)
6-
- mixpanel_flutter (1.0.1):
3+
- Mixpanel-swift (2.10.2):
4+
- Mixpanel-swift/Complete (= 2.10.2)
5+
- Mixpanel-swift/Complete (2.10.2)
6+
- mixpanel_flutter (1.1.0):
77
- Flutter
8-
- Mixpanel-swift (= 2.8.3)
8+
- Mixpanel-swift (= 2.10.2)
99

1010
DEPENDENCIES:
1111
- Flutter (from `Flutter`)
@@ -23,8 +23,8 @@ EXTERNAL SOURCES:
2323

2424
SPEC CHECKSUMS:
2525
Flutter: 434fef37c0980e73bb6479ef766c45957d4b510c
26-
Mixpanel-swift: 947354668bf7dcaff5aaf9c64232fb5bea6ff0c7
27-
mixpanel_flutter: 59130decd93dbb51e1a8a258d0d9af432287768e
26+
Mixpanel-swift: dc07ae05df9ff47c80542531f55e2120ec2a410a
27+
mixpanel_flutter: 1b239a014f75503531dd60e8315c82c3e86ad3ad
2828

2929
PODFILE CHECKSUM: aafe91acc616949ddb318b77800a7f51bffa2a4c
3030

example/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ packages:
8787
path: ".."
8888
relative: true
8989
source: path
90-
version: "1.0.1"
90+
version: "1.1.0"
9191
path:
9292
dependency: transitive
9393
description:

ios/Classes/SwiftMixpanelFlutterPlugin.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ public class SwiftMixpanelFlutterPlugin: NSObject, FlutterPlugin {
2525
case "setLoggingEnabled":
2626
handleSetLoggingEnabled(call, result: result)
2727
break
28+
case "setUseIpAddressForGeolocation":
29+
handleSetUseIpAddressForGeolocation(call, result: result)
30+
break
2831
case "hasOptedOutTracking":
2932
handleHasOptedOutTracking(call, result: result)
3033
break
@@ -176,6 +179,13 @@ public class SwiftMixpanelFlutterPlugin: NSObject, FlutterPlugin {
176179
instance?.loggingEnabled = loggingEnabled
177180
result(nil)
178181
}
182+
183+
private func handleSetUseIpAddressForGeolocation(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
184+
let arguments = call.arguments as? [String: Any] ?? [String: Any]()
185+
let useIpAddressForGeolocation = arguments["useIpAddressForGeolocation"] as! Bool
186+
instance?.useIPAddressForGeoLocation = useIpAddressForGeolocation
187+
result(nil)
188+
}
179189

180190
private func handleHasOptedOutTracking(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
181191
result(instance?.hasOptedOutTracking())

ios/mixpanel_flutter.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Pod::Spec.new do |s|
1212
s.source = { :path => '.' }
1313
s.source_files = 'Classes/**/*'
1414
s.dependency 'Flutter'
15-
s.dependency 'Mixpanel-swift', '2.8.3'
15+
s.dependency 'Mixpanel-swift', '2.10.2'
1616
s.platform = :ios, '9.0'
1717

1818
# Flutter.framework does not contain a i386 slice.

lib/mixpanel_flutter.dart

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -39,40 +39,47 @@ class Mixpanel {
3939
/// Set the base URL used for Mixpanel API requests.
4040
/// Useful if you need to proxy Mixpanel requests. Defaults to https://api.mixpanel.com.
4141
/// To route data to Mixpanel's EU servers, set to https://api-eu.mixpanel.com
42-
/// - Note: This method will only work for iOS. For android, please refer to:
43-
/// https://developer.mixpanel.com/docs/android
4442
///
4543
/// * [serverURL] the base URL used for Mixpanel API requests
4644
void setServerURL(String serverURL) {
47-
if (Platform.isIOS) {
48-
if (_MixpanelHelper.isValidString(serverURL)) {
49-
_channel.invokeMethod<void>(
50-
'setServerURL', <String, dynamic>{'serverURL': serverURL});
51-
} else {
52-
developer.log('`setServerURL` failed: serverURL cannot be blank',
53-
name: 'Mixpanel');
54-
}
45+
if (_MixpanelHelper.isValidString(serverURL)) {
46+
_channel.invokeMethod<void>(
47+
'setServerURL', <String, dynamic>{'serverURL': serverURL});
48+
} else {
49+
developer.log('`setServerURL` failed: serverURL cannot be blank',
50+
name: 'Mixpanel');
5551
}
5652
}
5753

5854
/// This allows enabling or disabling of all Mixpanel logs at run time.
59-
/// - Note: This method will only work for iOS. For android, please refer to:
60-
/// https://developer.mixpanel.com/docs/android
6155
/// All logging is disabled by default. Usually, this is only required if
6256
/// you are running into issues with the SDK that you want to debug
6357
///
6458
/// * [loggingEnabled] whether to enable logging
6559
void setLoggingEnabled(bool loggingEnabled) {
66-
if (Platform.isIOS) {
67-
// ignore: unnecessary_null_comparison
68-
if (loggingEnabled != null) {
69-
_channel.invokeMethod<void>('setLoggingEnabled',
70-
<String, dynamic>{'loggingEnabled': loggingEnabled});
71-
} else {
72-
developer.log(
73-
'`setLoggingEnabled` failed: loggingEnabled cannot be blank',
74-
name: 'Mixpanel');
75-
}
60+
if (loggingEnabled != null) { // ignore: unnecessary_null_comparison
61+
_channel.invokeMethod<void>('setLoggingEnabled',
62+
<String, dynamic>{'loggingEnabled': loggingEnabled});
63+
} else {
64+
developer.log(
65+
'`setLoggingEnabled` failed: loggingEnabled cannot be blank',
66+
name: 'Mixpanel');
67+
}
68+
}
69+
70+
/// This controls whether to automatically send the client IP Address as part of event tracking.
71+
/// With an IP address, geo-location is possible down to neighborhoods within a city,
72+
/// although the Mixpanel Dashboard will just show you city level location specificity.
73+
///
74+
/// * [useIpAddressForGeolocation] whether to automatically send the client IP Address. Defaults to true.
75+
void setUseIpAddressForGeolocation(bool useIpAddressForGeolocation) {
76+
if (useIpAddressForGeolocation != null) { // ignore: unnecessary_null_comparison
77+
_channel.invokeMethod<void>('setUseIpAddressForGeolocation',
78+
<String, dynamic>{'useIpAddressForGeolocation': useIpAddressForGeolocation});
79+
} else {
80+
developer.log(
81+
'`setUseIpAddressForGeolocation` failed: useIpAddressForGeolocation cannot be blank',
82+
name: 'Mixpanel');
7683
}
7784
}
7885

test/mixpanel_flutter_test.dart

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,39 @@ void main() {
6262
);
6363
});
6464

65+
test('check setServerURL', () async {
66+
_mixpanel.setServerURL("https://api-eu.mixpanel.com");
67+
expect(
68+
methodCall,
69+
isMethodCall(
70+
'setServerURL',
71+
arguments: <String, dynamic>{'serverURL': 'https://api-eu.mixpanel.com'},
72+
),
73+
);
74+
});
75+
76+
test('check setLoggingEnabled', () async {
77+
_mixpanel.setLoggingEnabled(true);
78+
expect(
79+
methodCall,
80+
isMethodCall(
81+
'setLoggingEnabled',
82+
arguments: <String, dynamic>{'loggingEnabled': true},
83+
),
84+
);
85+
});
86+
87+
test('check setUseIpAddressForGeolocation', () async {
88+
_mixpanel.setUseIpAddressForGeolocation(true);
89+
expect(
90+
methodCall,
91+
isMethodCall(
92+
'setUseIpAddressForGeolocation',
93+
arguments: <String, dynamic>{'useIpAddressForGeolocation': true},
94+
),
95+
);
96+
});
97+
6598
test('check optInTracking', () async {
6699
_mixpanel.optInTracking();
67100
expect(

0 commit comments

Comments
 (0)