Skip to content

Commit

Permalink
Merge pull request amplitude#30 from jjpbogers/update-amplitude-nativ…
Browse files Browse the repository at this point in the history
…e-sdk-versions-and-expose-dynamics-config

Update amplitude native sdk versions and expose dynamics config
  • Loading branch information
haoliu-amp authored Dec 2, 2020
2 parents 4037bbb + e027dc7 commit 998386f
Showing 11 changed files with 54 additions and 31 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.2.3
* Bump iOS (7.2.0) and Android (2.29.2) Amplitude SDK versions
* Add `setUseDynamicConfig` API to dynamically adjust server URL

## 2.2.2
* Fix - Fixing crash on iOS. Thanks @nishiths23!
* Misc - Migrated plugin to android v2 embedding. Thanks @sergey-triputsco!
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
@@ -40,6 +40,6 @@ android {
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "com.amplitude:android-sdk:2.27.0"
implementation "com.amplitude:android-sdk:2.29.2"
implementation "com.squareup.okhttp3:okhttp:4.2.2"
}
Original file line number Diff line number Diff line change
@@ -87,6 +87,12 @@ class AmplitudeFlutterPlugin : FlutterPlugin, MethodCallHandler {

result.success("trackingSessionEvents called..")
}
"setUseDynamicConfig" -> {
val client = Amplitude.getInstance(instanceName)
client.trackSessionEvents(json.getBoolean("useDynamicConfig"))

result.success("setUseDynamicConfig called..")
}
"setUserId" -> {
val client = Amplitude.getInstance(instanceName)
client.setUserId(json.optString("userId", null))
10 changes: 5 additions & 5 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PODS:
- Amplitude (5.2.1)
- Amplitude (7.2.0)
- amplitude_flutter (0.0.1):
- Amplitude (= 5.2.1)
- Amplitude (= 7.2.0)
- Flutter
- Flutter (1.0.0)

@@ -20,10 +20,10 @@ EXTERNAL SOURCES:
:path: Flutter

SPEC CHECKSUMS:
Amplitude: 9774e93d48d9f41f271a4479e06369a30ab31db1
amplitude_flutter: 5b9cab3f48db637a37d67b93e5dc49fa9b206686
Amplitude: c948c6f99c7f798c196523b2a5584367401d910f
amplitude_flutter: 5c934cf8331619b62bbd5a69f3cfea9090b3ca94
Flutter: 0e3d915762c693b495b44d77113d4970485de6ec

PODFILE CHECKSUM: 7c0562dd817e722f66e06d0beb6e4108968d2c23
PODFILE CHECKSUM: aafe91acc616949ddb318b77800a7f51bffa2a4c

COCOAPODS: 1.9.1
1 change: 1 addition & 0 deletions example/lib/my_app.dart
Original file line number Diff line number Diff line change
@@ -28,6 +28,7 @@ class _MyAppState extends State<MyApp> {
super.initState();

analytics = Amplitude.getInstance(instanceName: "project");
analytics.setUseDynamicConfig(true);
analytics.setServerUrl("https://api2.amplitude.com");
analytics.init(widget.apiKey);
analytics.enableCoppaControl();
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ packages:
path: ".."
relative: true
source: path
version: "2.2.2"
version: "2.2.3"
async:
dependency: transitive
description:
46 changes: 25 additions & 21 deletions ios/Classes/SwiftAmplitudeFlutterPlugin.swift
Original file line number Diff line number Diff line change
@@ -35,31 +35,35 @@ import Amplitude
}

let userId = args["userId"] as! String?
Amplitude.instance(withName: instanceName)?.initializeApiKey(apiKey, userId: userId)
Amplitude.instance(withName: instanceName).initializeApiKey(apiKey, userId: userId)
result(true)

// Setters
case "enableCoppaControl":
Amplitude.instance(withName: instanceName)?.enableCoppaControl();
Amplitude.instance(withName: instanceName).enableCoppaControl();
result(true)
case "disableCoppaControl":
Amplitude.instance(withName: instanceName)?.disableCoppaControl();
Amplitude.instance(withName: instanceName).disableCoppaControl();
result(true)
case "setOptOut":
let optOut = args["optOut"] as! Bool
Amplitude.instance(withName: instanceName)?.optOut = optOut
Amplitude.instance(withName: instanceName).optOut = optOut
result(true)
case "setLibraryName":
let libraryName = args["libraryName"] as! String
Amplitude.instance(withName: instanceName)?.libraryName = libraryName
Amplitude.instance(withName: instanceName).libraryName = libraryName
result(true)
case "setLibraryVersion":
let libraryVersion = args["libraryVersion"] as! String
Amplitude.instance(withName: instanceName)?.libraryVersion = libraryVersion
Amplitude.instance(withName: instanceName).libraryVersion = libraryVersion
result(true)
case "trackingSessionEvents":
let trackingSessionEvents = args["trackingSessionEvents"] as! Bool
Amplitude.instance(withName: instanceName)?.trackingSessionEvents = trackingSessionEvents
Amplitude.instance(withName: instanceName).trackingSessionEvents = trackingSessionEvents
result(true)
case "setUseDynamicConfig":
let useDynamicConfig = args["useDynamicConfig"] as! Bool
Amplitude.instance(withName: instanceName).useDynamicConfig = useDynamicConfig
result(true)
case "setUserId":
var userId: String? = nil
@@ -68,15 +72,15 @@ import Amplitude
}
let startNewSession = args["startNewSession"] == nil ? false : (args["startNewSession"] as! Bool)

Amplitude.instance(withName: instanceName)?.setUserId(userId, startNewSession: startNewSession)
Amplitude.instance(withName: instanceName).setUserId(userId, startNewSession: startNewSession)
result(true)
case "setServerUrl":
var serverUrl: String? = nil
if !(args["serverUrl"] is NSNull) {
serverUrl = args["serverUrl"] as! String?
if let serverUrl = args["serverUrl"] as! String? {
Amplitude.instance(withName: instanceName).setServerUrl(serverUrl)
}
}

Amplitude.instance(withName: instanceName)?.setServerUrl(serverUrl)
result(true)

// Event logging
@@ -85,7 +89,7 @@ import Amplitude
let eventProperties = args["eventProperties"] as! [String: Any]?
let outOfSession = args["outOfSession"] == nil ? false : (args["outOfSession"] as! Bool)

Amplitude.instance(withName: instanceName)?.logEvent(eventType,
Amplitude.instance(withName: instanceName).logEvent(eventType,
withEventProperties: eventProperties,
outOfSession: outOfSession)
result(true)
@@ -94,27 +98,27 @@ import Amplitude
let quantity = args["quantity"] as! Int
let price = args["price"] as! Double

Amplitude.instance(withName: instanceName)?.logRevenue(productIdentifier,
Amplitude.instance(withName: instanceName).logRevenue(productIdentifier,
quantity: quantity,
price: NSNumber(value: price))
result(true)

case "logRevenueAmount":
let amount = args["amount"] as! Double
Amplitude.instance(withName: instanceName)?.logRevenue(NSNumber(value: amount))
Amplitude.instance(withName: instanceName).logRevenue(NSNumber(value: amount))

result(true)

case "identify":
let userProperties = args["userProperties"] as! [String: [String : NSObject]]
let identify: AMPIdentify = createIdentify(userProperties)
Amplitude.instance(withName: instanceName)?.identify(identify)
Amplitude.instance(withName: instanceName).identify(identify)
result(true)

case "setGroup":
let groupType = args["groupType"] as! String
let groupName = args["groupName"] as! NSObject
Amplitude.instance(withName: instanceName)?.setGroup(groupType, groupName: groupName)
Amplitude.instance(withName: instanceName).setGroup(groupType, groupName: groupName)

result(true)
case "groupIdentify":
@@ -123,23 +127,23 @@ import Amplitude
let userProperties = args["userProperties"] as! [String: [String : NSObject]]
let outOfSession = args["outOfSession"] == nil ? false : (args["outOfSession"] as! Bool)
let identify: AMPIdentify = createIdentify(userProperties)
Amplitude.instance(withName: instanceName)?.groupIdentify(withGroupType: groupType,
Amplitude.instance(withName: instanceName).groupIdentify(withGroupType: groupType,
groupName: groupName,
groupIdentify: identify,
outOfSession: outOfSession)
result(true)

// User properties
case "setUserProperties":
let userProperties = args["userProperties"] as! [String: Any]?
Amplitude.instance(withName: instanceName)?.setUserProperties(userProperties)
let userProperties = args["userProperties"] as! [String: Any]? ?? [:]
Amplitude.instance(withName: instanceName).setUserProperties(userProperties)
result(true)
case "clearUserProperties":
Amplitude.instance(withName: instanceName)?.clearUserProperties()
Amplitude.instance(withName: instanceName).clearUserProperties()
result(true)

case "uploadEvents":
Amplitude.instance(withName: instanceName)?.uploadEvents()
Amplitude.instance(withName: instanceName).uploadEvents()
result(true)

default:
2 changes: 1 addition & 1 deletion ios/amplitude_flutter.podspec
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ Pod::Spec.new do |s|
s.source_files = 'Classes/**/*'
s.public_header_files = 'Classes/**/*.h'
s.dependency 'Flutter'
s.dependency 'Amplitude', '5.2.1'
s.dependency 'Amplitude', '7.2.0'

s.ios.deployment_target = '10.0'
end
8 changes: 8 additions & 0 deletions lib/amplitude.dart
Original file line number Diff line number Diff line change
@@ -96,6 +96,14 @@ class Amplitude extends _Amplitude {
return await _channel.invokeMethod('setServerUrl', jsonEncode(properties));
}

/// Dynamically adjust server URL
Future<void> setUseDynamicConfig(bool useDynamicConfig) async {
Map<String, dynamic> properties = _baseProperties();
properties['useDynamicConfig'] = useDynamicConfig;

return await _channel.invokeMethod('setUseDynamicConfig', jsonEncode(properties));
}

/// Tracks an event. Events are saved locally.
///
/// Uploads are batched to occur every 30 events or every 30 seconds
2 changes: 1 addition & 1 deletion lib/constants.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Constants {
static const packageName = 'amplitude-flutter';
static const packageVersion = '2.2.1';
static const packageVersion = '2.2.2';
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: amplitude_flutter
description: Amplitude Flutter plugin
version: 2.2.2
version: 2.2.3
homepage: https://www.amplitude.com

environment:

0 comments on commit 998386f

Please sign in to comment.