Skip to content

Commit

Permalink
fix: the issue when initialize SDK without global attribute (#11)
Browse files Browse the repository at this point in the history
Co-authored-by: zhu-xiaowei <xiaoweii@amazom.com>
  • Loading branch information
zhu-xiaowei and zhu-xiaowei authored Apr 25, 2024
1 parent 2bd5583 commit 45b28cc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
20 changes: 20 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ class _MyAppState extends State<MyApp> {
log("init SDK result is:$result");
}

Future<void> initClickstreamWithoutGlobalAttribute() async {
bool result = await analytics.init(
appId: "shopping",
endpoint: testEndpoint,
isLogEvents: true,
isTrackScreenViewEvents: true,
isCompressEvents: false,
sessionTimeoutDuration: 30000,
);
log("init SDK result is:$result");
}

@override
Widget build(BuildContext context) {
return MaterialApp(
Expand All @@ -75,6 +87,14 @@ class _MyAppState extends State<MyApp> {
},
minLeadingWidth: 0,
),
ListTile(
leading: const Icon(Icons.not_started_sharp),
title: const Text('initSDKWithoutGlobalAttribute'),
onTap: () async {
initClickstreamWithoutGlobalAttribute();
},
minLeadingWidth: 0,
),
ListTile(
leading: const Icon(Icons.circle),
title: const Text('recordEventWithName'),
Expand Down
3 changes: 1 addition & 2 deletions ios/Classes/ClickstreamFlutterPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ public class ClickstreamFlutterPlugin: NSObject, FlutterPlugin {
.withSessionTimeoutDuration(arguments["sessionTimeoutDuration"] as! Int64)
.withCompressEvents(arguments["isCompressEvents"] as! Bool)
.withAuthCookie(arguments["authCookie"] as! String)
if arguments["globalAttributes"] != nil {
let attributes = arguments["globalAttributes"] as! [String: Any]
if let attributes = arguments["globalAttributes"] as? [String: Any] {
if attributes.count > 0 {
let globalAttributes = getClickstreamAttributes(attributes)
_ = configuration.withInitialGlobalAttributes(globalAttributes)
Expand Down

0 comments on commit 45b28cc

Please sign in to comment.