From 6eb6f1f9f530f388e3416d000d0c2ed9948284e1 Mon Sep 17 00:00:00 2001 From: Neelkanth Kaushik Date: Tue, 20 May 2025 23:40:41 +0530 Subject: [PATCH 1/3] Patches for Github Issues (#159) * Patch for Github Issue #144 * Patch for Github issue #147 * Patch for Github issue #147 * Patch for Github issue #144 * Patch for Github issue #147 * Patch for Github issue #147 * Patch for Github issue #138 * Patch for Github issue #138 * Patch for Github Issue #152 * Patch for Github Issue #152 * Testing patch for Github Issue #157 * Patch for Github Issue #157 --- packages/core/android/build.gradle | 4 ++-- .../com/segment/analytics/AnalyticsPlugin.kt | 14 +++++++++++--- packages/core/lib/analytics.dart | 15 ++++++++++----- packages/core/lib/analytics_web.dart | 12 +++++++++++- packages/core/lib/event.dart | 19 +++++++++++-------- packages/core/lib/state.dart | 3 ++- packages/core/lib/timeline.dart | 4 +--- 7 files changed, 48 insertions(+), 23 deletions(-) diff --git a/packages/core/android/build.gradle b/packages/core/android/build.gradle index 5085736..83a26de 100644 --- a/packages/core/android/build.gradle +++ b/packages/core/android/build.gradle @@ -26,7 +26,7 @@ apply plugin: 'kotlin-android' android { namespace 'com.segment.analytics' - compileSdkVersion 31 + compileSdkVersion 35 //Patch for for Github issue #147 compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 @@ -44,4 +44,4 @@ android { defaultConfig { minSdkVersion 16 } -} +} \ No newline at end of file diff --git a/packages/core/android/src/main/kotlin/com/segment/analytics/AnalyticsPlugin.kt b/packages/core/android/src/main/kotlin/com/segment/analytics/AnalyticsPlugin.kt index ef8d597..0388fc2 100644 --- a/packages/core/android/src/main/kotlin/com/segment/analytics/AnalyticsPlugin.kt +++ b/packages/core/android/src/main/kotlin/com/segment/analytics/AnalyticsPlugin.kt @@ -143,9 +143,17 @@ class AnalyticsPlugin : FlutterPlugin, NativeContextApi, EventChannel.StreamHand NativeContext( app = NativeContextApp( build = appBuild, - name = packageInfo.applicationInfo.loadLabel( - packageManager - ).toString(), + + /* Retrieves the application name from the package info, using the application's label + (i.e., the app name displayed on the device). If the application name cannot be fetched + (e.g., due to a missing label or other issues), the fallback value "Unknown" will be used + to ensure the app doesn't break due to a null value. + + Patch for for Github issue #147 - Replaced following line: + name = packageInfo.applicationInfo.loadLabel(packageManager).toString(), with the line below + */ + name = packageInfo.applicationInfo?.loadLabel(packageManager)?.toString() ?: "Unknown", + namespace = packageInfo.packageName, version = packageInfo.versionName ), diff --git a/packages/core/lib/analytics.dart b/packages/core/lib/analytics.dart index cff34c9..ed4ca2d 100644 --- a/packages/core/lib/analytics.dart +++ b/packages/core/lib/analytics.dart @@ -212,26 +212,30 @@ class Analytics with ClientMethods { @override Future track(String event, {Map? properties}) async { - await _process(TrackEvent(event, properties: properties ?? {})); + await _process(TrackEvent(event, properties: properties ?? {}, + integrations: _state.integrations.state)); // Patch for Github Issue #152 } @override Future screen(String name, {Map? properties}) async { - final event = ScreenEvent(name, properties: properties ?? {}); + final event = ScreenEvent(name, properties: properties ?? {}, + integrations: _state.integrations.state); // Patch for Github Issue #152 await _process(event); } @override Future identify({String? userId, UserTraits? userTraits}) async { - final event = IdentifyEvent(userId: userId, traits: userTraits); + final event = IdentifyEvent(userId: userId, traits: userTraits, + integrations: _state.integrations.state); // Patch for Github Issue #152 await _process(event); } @override Future group(String groupId, {GroupTraits? groupTraits}) async { - final event = GroupEvent(groupId, traits: groupTraits); + final event = GroupEvent(groupId, traits: groupTraits, + integrations: _state.integrations.state); // Patch for Github Issue #152 await _process(event); } @@ -240,7 +244,8 @@ class Analytics with ClientMethods { Future alias(String newUserId) async { final userInfo = await state.userInfo.state; final event = - AliasEvent(userInfo.userId ?? userInfo.anonymousId, userId: newUserId); + AliasEvent(userInfo.userId ?? userInfo.anonymousId, userId: newUserId, + integrations: _state.integrations.state); // Patch for Github Issue #152 await _process(event); } diff --git a/packages/core/lib/analytics_web.dart b/packages/core/lib/analytics_web.dart index 303661a..d1d9ada 100644 --- a/packages/core/lib/analytics_web.dart +++ b/packages/core/lib/analytics_web.dart @@ -18,7 +18,7 @@ class AnalyticsPlatformImpl extends AnalyticsPlatform { NativeContext( app: NativeContextApp( name: web.window.navigator.appName, - version: web.window.navigator.appVersion, + version: getAppVersion(), // Patch Github Issue #138 namespace: web.window.navigator.appCodeName, ), userAgent: web.window.navigator.userAgent, @@ -28,6 +28,16 @@ class AnalyticsPlatformImpl extends AnalyticsPlatform { width: web.window.screen.width, ), ); + + /* + - Checks for in /web/index.html + and return the value inside 'content' + - Returns the browser version as fallback + */ + String getAppVersion() { + final meta = web.document.querySelector('meta[name="app-version"]'); + return meta?.getAttribute('content') ?? web.window.navigator.appVersion; + } } class AnalyticsWeb { diff --git a/packages/core/lib/event.dart b/packages/core/lib/event.dart index b8454ee..9507f63 100644 --- a/packages/core/lib/event.dart +++ b/packages/core/lib/event.dart @@ -55,7 +55,7 @@ abstract class RawEvent with JSONSerialisable { @JsonKey(name: "_metadata") DestinationMetadata? metadata; - RawEvent(this.type, {this.anonymousId, this.userId}); + RawEvent(this.type, {this.anonymousId, this.userId, this.integrations,}); // Patch for Github Issue #152 } @JsonSerializable(explicitToJson: true) @@ -79,7 +79,7 @@ class TrackEvent extends RawEvent { String event; Map? properties; - TrackEvent(this.event, {this.properties}) : super(EventType.track); + TrackEvent(this.event, {this.properties, Map? integrations,}) : super(EventType.track, integrations: integrations,); // Patch for Github Issue #152 factory TrackEvent.fromJson(Map json) => _$TrackEventFromJson(json); @@ -90,8 +90,8 @@ class TrackEvent extends RawEvent { @JsonSerializable(explicitToJson: true) class IdentifyEvent extends RawEvent { UserTraits? traits; - IdentifyEvent({this.traits, String? userId}) - : super(EventType.identify, userId: userId); + IdentifyEvent({this.traits, String? userId, Map? integrations}) + : super(EventType.identify, userId: userId, integrations: integrations); // Patch for Github Issue #152 factory IdentifyEvent.fromJson(Map json) => _$IdentifyEventFromJson(json); @@ -105,7 +105,7 @@ class GroupEvent extends RawEvent { String groupId; GroupTraits? traits; - GroupEvent(this.groupId, {this.traits}) : super(EventType.group); + GroupEvent(this.groupId, {this.traits, Map? integrations}) : super(EventType.group, integrations: integrations); // Patch for Github Issue #152 factory GroupEvent.fromJson(Map json) => _$GroupEventFromJson(json); @@ -117,8 +117,8 @@ class GroupEvent extends RawEvent { class AliasEvent extends RawEvent { String previousId; - AliasEvent(this.previousId, {String? userId}) - : super(EventType.alias, userId: userId); + AliasEvent(this.previousId, {String? userId, Map? integrations}) + : super(EventType.alias, userId: userId, integrations: integrations); // Patch for Github Issue #152 factory AliasEvent.fromJson(Map json) => _$AliasEventFromJson(json); @@ -131,7 +131,10 @@ class ScreenEvent extends RawEvent { String name; Map? properties; - ScreenEvent(this.name, {this.properties}) : super(EventType.screen); + ScreenEvent( + this.name, { + this.properties, + Map? integrations}) : super(EventType.screen, integrations: integrations); // Patch for Github Issue #152 factory ScreenEvent.fromJson(Map json) => _$ScreenEventFromJson(json); diff --git a/packages/core/lib/state.dart b/packages/core/lib/state.dart index eaec773..e8f8cb2 100644 --- a/packages/core/lib/state.dart +++ b/packages/core/lib/state.dart @@ -583,5 +583,6 @@ Configuration setFlushPolicies( trackApplicationLifecycleEvents: a.trackApplicationLifecycleEvents, trackDeeplinks: a.trackDeeplinks, storageJson: a.storageJson, - token: a.token); + token: a.token, + collectDeviceId: a.collectDeviceId); //Patch for for Github issue #144 } diff --git a/packages/core/lib/timeline.dart b/packages/core/lib/timeline.dart index d8efaaf..97a712d 100644 --- a/packages/core/lib/timeline.dart +++ b/packages/core/lib/timeline.dart @@ -99,8 +99,7 @@ class Timeline { Future applyPlugins(PluginType type, RawEvent event) async { RawEvent? result = event; - final plugins = _plugins[type]; - if (plugins != null) { + final plugins = List.from(_plugins[type] ?? []); //Patch for Github issue #157 for (var plugin in plugins) { if (result != null) { try { @@ -122,7 +121,6 @@ class Timeline { } } } - } return result; } } From 3d494a31e26f9e235127dff991b2b8158f81b7a4 Mon Sep 17 00:00:00 2001 From: Michael Grosse Huelsewiesche Date: Tue, 20 May 2025 17:28:31 -0400 Subject: [PATCH 2/3] Updating for 1.1.7 release --- packages/core/CHANGELOG.md | 9 +++++++++ packages/core/lib/version.dart | 2 +- packages/core/pubspec.yaml | 6 +++--- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/core/CHANGELOG.md b/packages/core/CHANGELOG.md index 0ef336d..dff3413 100644 --- a/packages/core/CHANGELOG.md +++ b/packages/core/CHANGELOG.md @@ -1,3 +1,12 @@ +## 1.1.7 + +- Fix for setFlushPolicies method is overwriting Configuration properties #144 +- Fix for Android build error on nullable receiver in sdk 35 #147 +- Fix for Context app version wrong on Flutter web #138 +- Fix for Integrations field is empty in segment analytics #152 +- Fix for AppsFlyer Destination not initializing properly #98 +- fix for Crash in Timeline.applyPlugins #157 + ## 1.1.6 - Fix error loading storage files diff --git a/packages/core/lib/version.dart b/packages/core/lib/version.dart index 2afdc25..170b94a 100644 --- a/packages/core/lib/version.dart +++ b/packages/core/lib/version.dart @@ -1 +1 @@ -const segmentVersion = "1.1.6"; +const segmentVersion = "1.1.7"; diff --git a/packages/core/pubspec.yaml b/packages/core/pubspec.yaml index c58942b..7939246 100644 --- a/packages/core/pubspec.yaml +++ b/packages/core/pubspec.yaml @@ -1,6 +1,6 @@ name: segment_analytics description: The hassle-free way to add Segment analytics to your Flutter app. -version: 1.1.6 +version: 1.1.7 homepage: https://github.com/segmentio/analytics_flutter#readme repository: https://github.com/segmentio/analytics_flutter/tree/main/packages/core#readme issue_tracker: https://github.com/segmentio/analytics_flutter/issues @@ -30,9 +30,9 @@ dev_dependencies: flutter_test: sdk: flutter fake_async: ^1.0.0 - flutter_lints: ^4.0.0 + flutter_lints: ^5.0.0 json_serializable: ^6.8.0 - pigeon: ^22.7.2 + pigeon: ^25.3.1 mockito: ^5.3.2 flutter: From af4cd1a00df3e05c5e52a50e81d3872336b2d622 Mon Sep 17 00:00:00 2001 From: Michael Grosse Huelsewiesche Date: Tue, 20 May 2025 17:34:27 -0400 Subject: [PATCH 3/3] Removing unnecessary library name --- packages/core/lib/analytics.dart | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/core/lib/analytics.dart b/packages/core/lib/analytics.dart index ed4ca2d..f3f5c22 100644 --- a/packages/core/lib/analytics.dart +++ b/packages/core/lib/analytics.dart @@ -1,5 +1,3 @@ -library analytics; - import 'dart:async'; import 'package:segment_analytics/client.dart';