Skip to content

Commit

Permalink
Support for setting customer_event_alias for BranchEven
Browse files Browse the repository at this point in the history
  • Loading branch information
RodrigoSMarques committed Oct 7, 2023
1 parent 39a89f4 commit 3ae526b
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ BranchEvent convertToEvent(HashMap<String, Object> eventMap) {
} else {
event = new BranchEvent((String) eventMap.get("eventName"));
}

if (eventMap.containsKey("transactionID"))
event.setTransactionID((String) eventMap.get("transactionID"));
if (eventMap.containsKey("currency"))
Expand All @@ -202,6 +201,9 @@ BranchEvent convertToEvent(HashMap<String, Object> eventMap) {
event.addCustomDataProperty(customData.getKey(), customData.getValue());
}
}
if (eventMap.containsKey("alias")) {
event.setCustomerEventAlias((String) eventMap.get("alias"));
}
return event;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
public class FlutterBranchSdkInit {
private static final String DEBUG_NAME = "FlutterBranchSDK";
private static final String PLUGIN_NAME = "Flutter";
private static final String PLUGIN_VERSION = "6.8.0";
private static final String PLUGIN_VERSION = "6.9.0";

public static void init(Context context) {
ApplicationInfoHelper applicationInfoHelper = new ApplicationInfoHelper(context);
Expand Down
2 changes: 1 addition & 1 deletion example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
package="br.com.rsmarques.flutter_branch_sdk_example">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:label="flutter_branch_sdk_example"
android:label="Flutter Branch SDK Example"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
<activity
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ packages:
path: ".."
relative: true
source: path
version: "6.8.0"
version: "6.9.0"
flutter_lints:
dependency: "direct dev"
description:
Expand Down
3 changes: 3 additions & 0 deletions ios/Classes/FlutterBranchIoSdkHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ func convertToEvent(dict: [String: Any?]) -> BranchEvent? {
event.customData[customData.key] = (customData.value as! String)
}
}
if let alias = dict["alias"] as? String {
event.alias = alias
}
return event
}

Expand Down
2 changes: 1 addition & 1 deletion ios/Classes/SwiftFlutterBranchSdkPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let MESSAGE_CHANNEL = "flutter_branch_sdk/message";
let EVENT_CHANNEL = "flutter_branch_sdk/event";
let ERROR_CODE = "FLUTTER_BRANCH_SDK_ERROR";
let PLUGIN_NAME = "Flutter";
let PLUGIN_VERSION = "6.8.0"
let PLUGIN_VERSION = "6.9.0"

public class SwiftFlutterBranchSdkPlugin: NSObject, FlutterPlugin, FlutterStreamHandler {
var eventSink: FlutterEventSink?
Expand Down
14 changes: 11 additions & 3 deletions lib/src/flutter_branch_sdk_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,23 @@ class FlutterBranchSdkWeb extends FlutterBranchSdkPlatform {
void trackContent(
{required List<BranchUniversalObject> buo,
required BranchEvent branchEvent}) {
js.JsArray<Object> contentItems = js.JsArray();
List<Object> contentItems = [];

for (var element in buo) {
contentItems.add(_dartObjectToJsObject(element.toMap()));
}

try {
BranchJS.logEvent(branchEvent.eventName,
_dartObjectToJsObject(branchEvent.toMap()), contentItems);
if (branchEvent.alias.isNotEmpty) {
BranchJS.logEvent(
branchEvent.eventName,
_dartObjectToJsObject(branchEvent.toMap()),
contentItems,
branchEvent.alias);
} else {
BranchJS.logEvent(branchEvent.eventName,
_dartObjectToJsObject(branchEvent.toMap()), contentItems);
}
} catch (e) {
debugPrint('trackContent() error: ${e.toString()}');
}
Expand Down
54 changes: 28 additions & 26 deletions lib/src/objects/branch_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class BranchEvent {
String searchQuery = '';
BranchEventAdType? adType;
final Map<String, String> _customData = {};
String alias = '';

BranchEvent.standardEvent(BranchStandardEvent branchStandardEvent) {
_eventName = getBranchStandardEventString(branchStandardEvent);
Expand All @@ -82,59 +83,60 @@ class BranchEvent {
}

Map<String, dynamic> toMap() {
Map<String, dynamic> ret = <String, dynamic>{};
Map<String, dynamic> data = <String, dynamic>{};

if (!kIsWeb) {
ret["eventName"] = _eventName;
ret["isStandardEvent"] = _isStandardEvent;
data["eventName"] = _eventName;
data["isStandardEvent"] = _isStandardEvent;
if (transactionID.isNotEmpty) {
ret["transactionID"] = transactionID;
data["transactionID"] = transactionID;
}
if (currency != null) {
ret["currency"] = getCurrencyTypeString(currency!);
data["currency"] = getCurrencyTypeString(currency!);
}
if (revenue != -1) ret["revenue"] = revenue;
if (shipping != -1) ret["shipping"] = shipping;
if (tax != -1) ret["tax"] = tax;
if (coupon.isNotEmpty) ret["coupon"] = coupon;
if (affiliation.isNotEmpty) ret["affiliation"] = affiliation;
if (revenue != -1) data["revenue"] = revenue;
if (shipping != -1) data["shipping"] = shipping;
if (tax != -1) data["tax"] = tax;
if (coupon.isNotEmpty) data["coupon"] = coupon;
if (affiliation.isNotEmpty) data["affiliation"] = affiliation;
if (eventDescription.isNotEmpty) {
ret["eventDescription"] = eventDescription;
data["eventDescription"] = eventDescription;
}
if (searchQuery.isNotEmpty) {
ret["searchQuery"] = searchQuery;
data["searchQuery"] = searchQuery;
}
if (adType != null) {
ret["adType"] = getBranchEventAdTypeString(adType!);
data["adType"] = getBranchEventAdTypeString(adType!);
}
if (_customData.isNotEmpty) ret["customData"] = _customData;
if (_customData.isNotEmpty) data["customData"] = _customData;
if (alias.isNotEmpty) data["alias"] = alias;
} else {
if (_isStandardEvent) {
if (transactionID.isNotEmpty) {
ret["transactionID"] = transactionID;
data["transactionID"] = transactionID;
}
if (currency != null) {
ret["currency"] = getCurrencyTypeString(currency!);
data["currency"] = getCurrencyTypeString(currency!);
}
if (revenue != -1) ret["revenue"] = revenue;
if (shipping != -1) ret["shipping"] = shipping;
if (tax != -1) ret["tax"] = tax;
if (coupon.isNotEmpty) ret["coupon"] = coupon;
if (affiliation.isNotEmpty) ret["affiliation"] = affiliation;
if (revenue != -1) data["revenue"] = revenue;
if (shipping != -1) data["shipping"] = shipping;
if (tax != -1) data["tax"] = tax;
if (coupon.isNotEmpty) data["coupon"] = coupon;
if (affiliation.isNotEmpty) data["affiliation"] = affiliation;
if (eventDescription.isNotEmpty) {
ret["eventDescription"] = eventDescription;
data["eventDescription"] = eventDescription;
}
if (searchQuery.isNotEmpty) {
ret["searchQuery"] = searchQuery;
data["searchQuery"] = searchQuery;
}
if (adType != null) {
ret["adType"] = getBranchEventAdTypeString(adType!);
data["adType"] = getBranchEventAdTypeString(adType!);
}
}
_customData.forEach((key, value) {
ret[key] = value;
data[key] = value;
});
}
return ret;
return data;
}
}
4 changes: 1 addition & 3 deletions lib/src/web/branch_js.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
@JS()
library branchjs;

// ignore: avoid_web_libraries_in_flutter
import 'dart:js';
import 'dart:typed_data';

import 'package:js/js.dart';
Expand Down Expand Up @@ -757,7 +755,7 @@ class BranchJS {
@JS('logEvent')
external static void logEvent(String event,
[Object eventDataAndCustomData,
JsArray contentItems,
Object contentItems,
String customerEventAlias,
Function callback]);

Expand Down

0 comments on commit 3ae526b

Please sign in to comment.