From b693bdc88964f21418fa6adf1fd48fe48fccaada Mon Sep 17 00:00:00 2001 From: pedromassango Date: Fri, 4 Oct 2024 11:05:40 +0200 Subject: [PATCH 1/4] feat: Add wasm support --- example/.gitignore | 1 - example/pubspec.lock | 38 +++++---- lib/mixpanel_flutter_web.dart | 52 ++++++------ lib/web/mixpanel_js_bindings.dart | 135 +++++++++++++++--------------- pubspec.lock | 18 ++-- pubspec.yaml | 2 +- 6 files changed, 130 insertions(+), 116 deletions(-) diff --git a/example/.gitignore b/example/.gitignore index 9d532b1..7283898 100644 --- a/example/.gitignore +++ b/example/.gitignore @@ -32,7 +32,6 @@ /build/ # Web related -lib/generated_plugin_registrant.dart # Symbolication related app.*.symbols diff --git a/example/pubspec.lock b/example/pubspec.lock index 3e80661..2c7f2be 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -76,26 +76,34 @@ packages: dependency: transitive description: name: js - sha256: c1b2e9b5ea78c45e1a0788d29606ba27dc5f71f019f32ca5140f61ef071838cf + sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 url: "https://pub.dev" source: hosted - version: "0.7.1" + version: "0.6.7" + js_interop: + dependency: transitive + description: + name: js_interop + sha256: "7ec859c296958ccea34dc770504bd3ff4ae52fdd9e7eeb2bacc7081ad476a1f5" + url: "https://pub.dev" + source: hosted + version: "0.0.1" leak_tracker: dependency: transitive description: name: leak_tracker - sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a" + sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05" url: "https://pub.dev" source: hosted - version: "10.0.4" + version: "10.0.5" leak_tracker_flutter_testing: dependency: transitive description: name: leak_tracker_flutter_testing - sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8" + sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806" url: "https://pub.dev" source: hosted - version: "3.0.3" + version: "3.0.5" leak_tracker_testing: dependency: transitive description: @@ -116,25 +124,25 @@ packages: dependency: transitive description: name: material_color_utilities - sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" + sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec url: "https://pub.dev" source: hosted - version: "0.8.0" + version: "0.11.1" meta: dependency: transitive description: name: meta - sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136" + sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7 url: "https://pub.dev" source: hosted - version: "1.12.0" + version: "1.15.0" mixpanel_flutter: dependency: "direct main" description: path: ".." relative: true source: path - version: "2.3.1" + version: "2.3.3" path: dependency: transitive description: @@ -192,10 +200,10 @@ packages: dependency: transitive description: name: test_api - sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f" + sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb" url: "https://pub.dev" source: hosted - version: "0.7.0" + version: "0.7.2" vector_math: dependency: transitive description: @@ -208,10 +216,10 @@ packages: dependency: transitive description: name: vm_service - sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec" + sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d" url: "https://pub.dev" source: hosted - version: "14.2.1" + version: "14.2.5" sdks: dart: ">=3.3.0 <4.0.0" flutter: ">=3.18.0-18.0.pre.54" diff --git a/lib/mixpanel_flutter_web.dart b/lib/mixpanel_flutter_web.dart index bf0e0b5..337eecc 100644 --- a/lib/mixpanel_flutter_web.dart +++ b/lib/mixpanel_flutter_web.dart @@ -1,9 +1,9 @@ import 'dart:async'; +import 'dart:js_interop'; import 'package:flutter/services.dart'; import 'package:flutter_web_plugins/flutter_web_plugins.dart'; import 'package:mixpanel_flutter/web/mixpanel_js_bindings.dart'; -import 'package:js/js_util.dart' as js; /// A web implementation of the MixpanelFlutter plugin. class MixpanelFlutterPlugin { @@ -138,13 +138,13 @@ class MixpanelFlutterPlugin { Map args = call.arguments as Map; String token = args['token'] as String; dynamic config = args['config']; - init(token, js.jsify(config ?? {})); + init(token, config?.jsify() ?? {}); } void handleSetServerURL(MethodCall call) { Map args = call.arguments as Map; String serverURL = args['serverURL'] as String; - set_config(js.jsify({'api_host': serverURL})); + set_config({'api_host': serverURL}.jsify()); } void handleTrack(MethodCall call) { @@ -155,7 +155,7 @@ class MixpanelFlutterPlugin { ..._mixpanelProperties, ...(properties ?? {}) }; - track(eventName, js.jsify(props)); + track(eventName, props.jsify()); } void handleAlias(MethodCall call) { @@ -180,7 +180,7 @@ class MixpanelFlutterPlugin { ...(properties ?? {}) }; dynamic groups = args["groups"]; - track_with_groups(eventName, js.jsify(props), js.jsify(groups)); + track_with_groups(eventName, props.jsify(), groups.jsify()); } void handleSetGroup(MethodCall call) { @@ -189,7 +189,7 @@ class MixpanelFlutterPlugin { dynamic groupID = args["groupID"]; if (groupID != null) { set_group(groupKey, - (groupID is Map || groupID is List) ? js.jsify(groupID) : groupID); + (groupID is Map || groupID is List) ? groupID.jsify() : groupID); } } @@ -200,7 +200,7 @@ class MixpanelFlutterPlugin { if (groupID != null) { add_group(groupKey, - (groupID is Map || groupID is List) ? js.jsify(groupID) : groupID); + (groupID is Map || groupID is List) ? groupID.jsify() : groupID); } } @@ -210,20 +210,20 @@ class MixpanelFlutterPlugin { dynamic groupID = args["groupID"]; if (groupID != null) { remove_group(groupKey, - (groupID is Map || groupID is List) ? js.jsify(groupID) : groupID); + (groupID is Map || groupID is List) ? groupID.jsify() : groupID); } } void handleRegisterSuperProperties(MethodCall call) { Map args = call.arguments as Map; dynamic properties = args['properties']; - register(js.jsify(properties)); + register(properties.jsify()); } void handleRegisterSuperPropertiesOnce(MethodCall call) { Map args = call.arguments as Map; dynamic properties = args['properties']; - register_once(js.jsify(properties)); + register_once(properties.jsify()); } void handleUnregisterSuperProperty(MethodCall call) { @@ -250,51 +250,51 @@ class MixpanelFlutterPlugin { Map args = call.arguments as Map; dynamic properties = args['properties']; Map props = {..._mixpanelProperties, ...properties}; - people_set(js.jsify(props)); + people_set(props.jsify()); } void handleSetOnce(MethodCall call) { Map args = call.arguments as Map; dynamic properties = args['properties']; Map props = {..._mixpanelProperties, ...properties}; - people_set_once(js.jsify(props)); + people_set_once(props.jsify()); } void handlePeopleIncrement(MethodCall call) { Map args = call.arguments as Map; dynamic properties = args['properties']; - people_increment(js.jsify(properties)); + people_increment(properties.jsify()); } void handlePeopleAppend(MethodCall call) { Map args = call.arguments as Map; dynamic properties = args['properties']; - people_append(js.jsify(properties)); + people_append(properties.jsify()); } void handlePeopleUnion(MethodCall call) { Map args = call.arguments as Map; dynamic properties = args['properties']; - people_union(js.jsify(properties)); + people_union(properties.jsify()); } void handlePeopleRemove(MethodCall call) { Map args = call.arguments as Map; dynamic properties = args['properties']; - people_remove(js.jsify(properties)); + people_remove(properties.jsify()); } void handlePeopleUnset(MethodCall call) { Map args = call.arguments as Map; dynamic properties = args['properties']; - people_unset(js.jsify(properties)); + people_unset(properties.jsify()); } void handleTrackCharge(MethodCall call) { Map args = call.arguments as Map; dynamic properties = args['properties']; double amount = args['amount'] as double; - people_track_charge(amount, js.jsify(properties ?? {})); + people_track_charge(amount, properties?.jsify() ?? {}); } void handleClearCharge() { @@ -312,8 +312,8 @@ class MixpanelFlutterPlugin { dynamic properties = args['properties']; get_group(groupKey, - (groupID is Map || groupID is List) ? js.jsify(groupID) : groupID) - .set(js.jsify(properties)); + (groupID is Map || groupID is List) ? groupID.jsify() : groupID) + .set(properties.jsify()); } void handleGroupSetPropertyOnce(MethodCall call) { @@ -324,7 +324,7 @@ class MixpanelFlutterPlugin { dynamic properties = args['properties']; get_group(groupKey, - (groupID is Map || groupID is List) ? js.jsify(groupID) : groupID) + (groupID is Map || groupID is List) ? groupID.jsify() : groupID) .set_once(properties.keys.first, properties[properties.keys.first]); } @@ -335,7 +335,7 @@ class MixpanelFlutterPlugin { String propertyName = args['propertyName'] as String; get_group(groupKey, - (groupID is Map || groupID is List) ? js.jsify(groupID) : groupID) + (groupID is Map || groupID is List) ? groupID.jsify() : groupID) .unset(propertyName); } @@ -347,9 +347,9 @@ class MixpanelFlutterPlugin { String name = args['name'] as String; dynamic value = args['value']; get_group(groupKey, - (groupID is Map || groupID is List) ? js.jsify(groupID) : groupID) + (groupID is Map || groupID is List) ? groupID.jsify() : groupID) .remove( - name, (value is Map || value is List) ? js.jsify(value) : value); + name, (value is Map || value is List) ? value.jsify() : value); } void handleGroupUnion(MethodCall call) { @@ -360,8 +360,8 @@ class MixpanelFlutterPlugin { String name = args['name'] as String; dynamic value = args['value'] as dynamic; get_group(groupKey, - (groupID is Map || groupID is List) ? js.jsify(groupID) : groupID) - .union(name, js.jsify(value)); + (groupID is Map || groupID is List) ? groupID.jsify() : groupID) + .union(name, value.jsify()); } bool handleHasOptedOutTracking() { diff --git a/lib/web/mixpanel_js_bindings.dart b/lib/web/mixpanel_js_bindings.dart index a43718b..3cde6b2 100644 --- a/lib/web/mixpanel_js_bindings.dart +++ b/lib/web/mixpanel_js_bindings.dart @@ -1,110 +1,109 @@ +import 'dart:js_interop'; + @JS('mixpanel') -library mixpaneljs; +@staticInterop +class Mixpanel {} + +@JS('MixpanelGroup') +@staticInterop +class MixpanelGroup {} + +extension MixpanelGroupMethods on MixpanelGroup { + external void set(JSAny? properties); + + @JS('group.set_once') + external void set_once(String prop, JSAny? to); -import 'package:js/js.dart'; + external void unset(String prop); + + external void remove(String name, JSAny? value); + + external void union(String name, JSArray values); +} -@JS('init') -external void init(String token, Object? config); +@JS('mixpanel.init') +external void init(String token, JSAny? config); -@JS('set_config') -external void set_config(Object config); +@JS('mixpanel.set_config') +external void set_config(JSAny? config); -@JS('has_opted_out_tracking') +@JS('mixpanel.has_opted_out_tracking') external bool has_opted_out_tracking(); -@JS('opt_in_tracking') +@JS('mixpanel.opt_in_tracking') external void opt_in_tracking(); -@JS('opt_out_tracking') +@JS('mixpanel.opt_out_tracking') external void opt_out_tracking(); -@JS('identify') +@JS('mixpanel.identify') external void identify(String distinctId); -@JS('alias') +@JS('mixpanel.alias') external void alias(String alias, String distinctId); -@JS('track') -external void track(String name, Object? properties); +@JS('mixpanel.track') +external void track(String name, JSAny? properties); -@JS('track_with_groups') -external void track_with_groups( - String event_name, Object properties, Object groups); +@JS('mixpanel.track_with_groups') +external void track_with_groups(String event_name, JSAny? properties, JSAny? groups); -@JS('set_group') -external void set_group(String group_key, Object group_ids); +@JS('mixpanel.set_group') +external void set_group(String group_key, JSAny? group_ids); -@JS('add_group') -external void add_group(String group_key, Object group_id); +@JS('mixpanel.add_group') +external void add_group(String group_key, JSAny? group_id); -@JS('remove_group') -external void remove_group(String group_key, Object group_id); +@JS('mixpanel.remove_group') +external void remove_group(String group_key, JSAny? group_id); -@JS('get_group') -external MixpanelGroup get_group(String group_key, Object group_id); +@JS('mixpanel.get_group') +external MixpanelGroup get_group(String group_key, JSAny? group_id); -@JS('register') -external void register(Object properties); +@JS('mixpanel.register') +external void register(JSAny? properties); -@JS('register_once') -external void register_once(Object properties); +@JS('mixpanel.register_once') +external void register_once(JSAny? properties); -@JS('unregister') +@JS('mixpanel.unregister') external void unregister(String property); -@JS('time_event') +@JS('mixpanel.time_event') external void time_event(String event_name); -@JS('reset') +@JS('mixpanel.reset') external void reset(); -@JS('get_distinct_id') +@JS('mixpanel.get_distinct_id') external String get_distinct_id(); -@JS('people.set') -external void people_set(Object properties); +@JS('mixpanel.people.set') +external void people_set(JSAny? properties); -@JS('people.set_once') -external void people_set_once(Object properties); +@JS('mixpanel.people.set_once') +external void people_set_once(JSAny? properties); -@JS('people.increment') -external void people_increment(Object properties); +@JS('mixpanel.people.increment') +external void people_increment(JSAny? properties); -@JS('people.append') -external void people_append(Object properties); +@JS('mixpanel.people.append') +external void people_append(JSAny? properties); -@JS('people.union') -external void people_union(Object properties); +@JS('mixpanel.people.union') +external void people_union(JSAny? properties); -@JS('people.remove') -external void people_remove(Object properties); +@JS('mixpanel.people.remove') +external void people_remove(JSAny? properties); -@JS('people.unset') -external void people_unset(Object properties); +@JS('mixpanel.people.unset') +external void people_unset(JSAny? properties); -@JS('people.track_charge') -external void people_track_charge(double amount, Object? properties); +@JS('mixpanel.people.track_charge') +external void people_track_charge(double amount, JSAny? properties); -@JS('people.clear_charge') +@JS('mixpanel.people.clear_charge') external void people_clear_charge(); -@JS('people.delete_users') +@JS('mixpanel.people.delete_users') external void people_delete_users(); - -@JS() -class MixpanelGroup { - @JS('group.set') - external void set(Object properties); - - @JS('group.set_once') - external void set_once(String prop, Object to); - - @JS('group.unset') - external void unset(String prop); - - @JS('group.remove') - external void remove(String name, Object value); - - @JS('group.union') - external void union(String name, List values); -} diff --git a/pubspec.lock b/pubspec.lock index a94ced2..a759297 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -65,13 +65,21 @@ packages: source: sdk version: "0.0.0" js: - dependency: "direct main" + dependency: transitive description: name: js - sha256: c1b2e9b5ea78c45e1a0788d29606ba27dc5f71f019f32ca5140f61ef071838cf + sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 + url: "https://pub.dev" + source: hosted + version: "0.6.7" + js_interop: + dependency: "direct main" + description: + name: js_interop + sha256: "7ec859c296958ccea34dc770504bd3ff4ae52fdd9e7eeb2bacc7081ad476a1f5" url: "https://pub.dev" source: hosted - version: "0.7.1" + version: "0.0.1" leak_tracker: dependency: transitive description: @@ -193,10 +201,10 @@ packages: dependency: transitive description: name: vm_service - sha256: f652077d0bdf60abe4c1f6377448e8655008eef28f128bc023f7b5e8dfeb48fc + sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d" url: "https://pub.dev" source: hosted - version: "14.2.4" + version: "14.2.5" sdks: dart: ">=3.3.0 <4.0.0" flutter: ">=3.18.0-18.0.pre.54" diff --git a/pubspec.yaml b/pubspec.yaml index 0c1b248..9b41cb9 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -15,7 +15,7 @@ dependencies: sdk: flutter flutter_web_plugins: sdk: flutter - js: ">=0.6.0 <0.8.0" + js_interop: ^0.0.1 dev_dependencies: flutter_test: From 5cf5f48bb7bb04cfe43ea9444030cb61b8a3a7ab Mon Sep 17 00:00:00 2001 From: pedromassango Date: Fri, 4 Oct 2024 11:06:22 +0200 Subject: [PATCH 2/4] nit: run formatter --- lib/codec/mixpanel_message_codec.dart | 2 +- lib/mixpanel_flutter_web.dart | 3 +-- lib/web/mixpanel_js_bindings.dart | 3 ++- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/codec/mixpanel_message_codec.dart b/lib/codec/mixpanel_message_codec.dart index 91a37e8..82584c8 100644 --- a/lib/codec/mixpanel_message_codec.dart +++ b/lib/codec/mixpanel_message_codec.dart @@ -38,4 +38,4 @@ class MixpanelMessageCodec extends StandardMessageCodec { return super.readValueOfType(type, buffer); } } -} \ No newline at end of file +} diff --git a/lib/mixpanel_flutter_web.dart b/lib/mixpanel_flutter_web.dart index 337eecc..77951a3 100644 --- a/lib/mixpanel_flutter_web.dart +++ b/lib/mixpanel_flutter_web.dart @@ -348,8 +348,7 @@ class MixpanelFlutterPlugin { dynamic value = args['value']; get_group(groupKey, (groupID is Map || groupID is List) ? groupID.jsify() : groupID) - .remove( - name, (value is Map || value is List) ? value.jsify() : value); + .remove(name, (value is Map || value is List) ? value.jsify() : value); } void handleGroupUnion(MethodCall call) { diff --git a/lib/web/mixpanel_js_bindings.dart b/lib/web/mixpanel_js_bindings.dart index 3cde6b2..fa043b9 100644 --- a/lib/web/mixpanel_js_bindings.dart +++ b/lib/web/mixpanel_js_bindings.dart @@ -46,7 +46,8 @@ external void alias(String alias, String distinctId); external void track(String name, JSAny? properties); @JS('mixpanel.track_with_groups') -external void track_with_groups(String event_name, JSAny? properties, JSAny? groups); +external void track_with_groups( + String event_name, JSAny? properties, JSAny? groups); @JS('mixpanel.set_group') external void set_group(String group_key, JSAny? group_ids); From a742f28a52cde9b6073c250d3d22a4d7898e2211 Mon Sep 17 00:00:00 2001 From: pedromassango Date: Fri, 4 Oct 2024 11:12:15 +0200 Subject: [PATCH 3/4] nit: remove unnecessary changes --- example/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/example/.gitignore b/example/.gitignore index 7283898..9d532b1 100644 --- a/example/.gitignore +++ b/example/.gitignore @@ -32,6 +32,7 @@ /build/ # Web related +lib/generated_plugin_registrant.dart # Symbolication related app.*.symbols From 23ba8ea03997cf313e32ccdaea50c6f7f313745a Mon Sep 17 00:00:00 2001 From: pedromassango Date: Fri, 1 Nov 2024 14:59:32 +0100 Subject: [PATCH 4/4] fix: Remove js_interop --- example/pubspec.lock | 16 ---------------- pubspec.lock | 16 ---------------- pubspec.yaml | 1 - 3 files changed, 33 deletions(-) diff --git a/example/pubspec.lock b/example/pubspec.lock index 2c7f2be..01a4379 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -72,22 +72,6 @@ packages: description: flutter source: sdk version: "0.0.0" - js: - dependency: transitive - description: - name: js - sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 - url: "https://pub.dev" - source: hosted - version: "0.6.7" - js_interop: - dependency: transitive - description: - name: js_interop - sha256: "7ec859c296958ccea34dc770504bd3ff4ae52fdd9e7eeb2bacc7081ad476a1f5" - url: "https://pub.dev" - source: hosted - version: "0.0.1" leak_tracker: dependency: transitive description: diff --git a/pubspec.lock b/pubspec.lock index a759297..4549095 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -64,22 +64,6 @@ packages: description: flutter source: sdk version: "0.0.0" - js: - dependency: transitive - description: - name: js - sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 - url: "https://pub.dev" - source: hosted - version: "0.6.7" - js_interop: - dependency: "direct main" - description: - name: js_interop - sha256: "7ec859c296958ccea34dc770504bd3ff4ae52fdd9e7eeb2bacc7081ad476a1f5" - url: "https://pub.dev" - source: hosted - version: "0.0.1" leak_tracker: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 9b41cb9..384897f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -15,7 +15,6 @@ dependencies: sdk: flutter flutter_web_plugins: sdk: flutter - js_interop: ^0.0.1 dev_dependencies: flutter_test: