diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c9f639..b53a066 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # +## [v2.4.0](https://github.com/mixpanel/mixpanel-flutter/tree/v2.4.0) (2025-01-25) + +- Add WASM support + ## [v2.3.4](https://github.com/mixpanel/mixpanel-flutter/tree/v2.3.4) (2025-02-20) ### Fixes diff --git a/assets/mixpanel.js b/assets/mixpanel.js index d52b28d..a4f45b1 100644 --- a/assets/mixpanel.js +++ b/assets/mixpanel.js @@ -1,3 +1,3 @@ - (function(f,b){if(!b.__SV){var e,g,i,h;window.mixpanel=b;b._i=[];b.init=function(e,f,c){function g(a,d){var b=d.split(".");2==b.length&&(a=a[b[0]],d=b[1]);a[d]=function(){a.push([d].concat(Array.prototype.slice.call(arguments,0)))}}var a=b;"undefined"!==typeof c?a=b[c]=[]:c="mixpanel";a.people=a.people||[];a.toString=function(a){var d="mixpanel";"mixpanel"!==c&&(d+="."+c);a||(d+=" (stub)");return d};a.people.toString=function(){return a.toString(1)+".people (stub)"};i="disable time_event track track_pageview track_links track_forms track_with_groups add_group set_group remove_group register register_once alias unregister identify name_tag set_config reset opt_in_tracking opt_out_tracking has_opted_in_tracking has_opted_out_tracking clear_opt_in_out_tracking start_batch_senders people.set people.set_once people.unset people.increment people.append people.union people.track_charge people.clear_charges people.delete_user people.remove".split(" "); - for(h=0;h=3.3.0 <4.0.0" flutter: ">=3.18.0-18.0.pre.54" 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 bf0e0b5..77951a3 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,8 @@ 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) - .remove( - name, (value is Map || value is List) ? js.jsify(value) : value); + (groupID is Map || groupID is List) ? groupID.jsify() : groupID) + .remove(name, (value is Map || value is List) ? value.jsify() : value); } void handleGroupUnion(MethodCall call) { @@ -360,8 +359,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..fa043b9 100644 --- a/lib/web/mixpanel_js_bindings.dart +++ b/lib/web/mixpanel_js_bindings.dart @@ -1,110 +1,110 @@ +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') +@JS('mixpanel.track_with_groups') external void track_with_groups( - String event_name, Object properties, Object 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..4549095 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -64,14 +64,6 @@ packages: description: flutter source: sdk version: "0.0.0" - js: - dependency: "direct main" - description: - name: js - sha256: c1b2e9b5ea78c45e1a0788d29606ba27dc5f71f019f32ca5140f61ef071838cf - url: "https://pub.dev" - source: hosted - version: "0.7.1" leak_tracker: dependency: transitive description: @@ -193,10 +185,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 788aaab..c37906a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: mixpanel_flutter description: Official Flutter Tracking SDK for Mixpanel Analytics developed and maintained by Mixpanel, Inc. -version: 2.3.4 +version: 2.4.0 homepage: https://mixpanel.com repository: https://github.com/mixpanel/mixpanel-flutter issue_tracker: https://github.com/mixpanel/mixpanel-flutter/issues @@ -15,7 +15,6 @@ dependencies: sdk: flutter flutter_web_plugins: sdk: flutter - js: ">=0.6.0 <0.8.0" dev_dependencies: flutter_test: