Skip to content

Commit 45b28cc

Browse files
zhu-xiaoweizhu-xiaowei
andauthored
fix: the issue when initialize SDK without global attribute (#11)
Co-authored-by: zhu-xiaowei <xiaoweii@amazom.com>
1 parent 2bd5583 commit 45b28cc

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

example/lib/main.dart

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ class _MyAppState extends State<MyApp> {
5858
log("init SDK result is:$result");
5959
}
6060

61+
Future<void> initClickstreamWithoutGlobalAttribute() async {
62+
bool result = await analytics.init(
63+
appId: "shopping",
64+
endpoint: testEndpoint,
65+
isLogEvents: true,
66+
isTrackScreenViewEvents: true,
67+
isCompressEvents: false,
68+
sessionTimeoutDuration: 30000,
69+
);
70+
log("init SDK result is:$result");
71+
}
72+
6173
@override
6274
Widget build(BuildContext context) {
6375
return MaterialApp(
@@ -75,6 +87,14 @@ class _MyAppState extends State<MyApp> {
7587
},
7688
minLeadingWidth: 0,
7789
),
90+
ListTile(
91+
leading: const Icon(Icons.not_started_sharp),
92+
title: const Text('initSDKWithoutGlobalAttribute'),
93+
onTap: () async {
94+
initClickstreamWithoutGlobalAttribute();
95+
},
96+
minLeadingWidth: 0,
97+
),
7898
ListTile(
7999
leading: const Icon(Icons.circle),
80100
title: const Text('recordEventWithName'),

ios/Classes/ClickstreamFlutterPlugin.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ public class ClickstreamFlutterPlugin: NSObject, FlutterPlugin {
5656
.withSessionTimeoutDuration(arguments["sessionTimeoutDuration"] as! Int64)
5757
.withCompressEvents(arguments["isCompressEvents"] as! Bool)
5858
.withAuthCookie(arguments["authCookie"] as! String)
59-
if arguments["globalAttributes"] != nil {
60-
let attributes = arguments["globalAttributes"] as! [String: Any]
59+
if let attributes = arguments["globalAttributes"] as? [String: Any] {
6160
if attributes.count > 0 {
6261
let globalAttributes = getClickstreamAttributes(attributes)
6362
_ = configuration.withInitialGlobalAttributes(globalAttributes)

0 commit comments

Comments
 (0)