Skip to content

Commit 6eb6f1f

Browse files
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
1 parent 87f50a5 commit 6eb6f1f

File tree

7 files changed

+48
-23
lines changed

7 files changed

+48
-23
lines changed

packages/core/android/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ apply plugin: 'kotlin-android'
2626

2727
android {
2828
namespace 'com.segment.analytics'
29-
compileSdkVersion 31
29+
compileSdkVersion 35 //Patch for for Github issue #147
3030

3131
compileOptions {
3232
sourceCompatibility JavaVersion.VERSION_1_8
@@ -44,4 +44,4 @@ android {
4444
defaultConfig {
4545
minSdkVersion 16
4646
}
47-
}
47+
}

packages/core/android/src/main/kotlin/com/segment/analytics/AnalyticsPlugin.kt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,17 @@ class AnalyticsPlugin : FlutterPlugin, NativeContextApi, EventChannel.StreamHand
143143
NativeContext(
144144
app = NativeContextApp(
145145
build = appBuild,
146-
name = packageInfo.applicationInfo.loadLabel(
147-
packageManager
148-
).toString(),
146+
147+
/* Retrieves the application name from the package info, using the application's label
148+
(i.e., the app name displayed on the device). If the application name cannot be fetched
149+
(e.g., due to a missing label or other issues), the fallback value "Unknown" will be used
150+
to ensure the app doesn't break due to a null value.
151+
152+
Patch for for Github issue #147 - Replaced following line:
153+
name = packageInfo.applicationInfo.loadLabel(packageManager).toString(), with the line below
154+
*/
155+
name = packageInfo.applicationInfo?.loadLabel(packageManager)?.toString() ?: "Unknown",
156+
149157
namespace = packageInfo.packageName,
150158
version = packageInfo.versionName
151159
),

packages/core/lib/analytics.dart

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,26 +212,30 @@ class Analytics with ClientMethods {
212212

213213
@override
214214
Future track(String event, {Map<String, dynamic>? properties}) async {
215-
await _process(TrackEvent(event, properties: properties ?? {}));
215+
await _process(TrackEvent(event, properties: properties ?? {},
216+
integrations: _state.integrations.state)); // Patch for Github Issue #152
216217
}
217218

218219
@override
219220
Future screen(String name, {Map<String, dynamic>? properties}) async {
220-
final event = ScreenEvent(name, properties: properties ?? {});
221+
final event = ScreenEvent(name, properties: properties ?? {},
222+
integrations: _state.integrations.state); // Patch for Github Issue #152
221223

222224
await _process(event);
223225
}
224226

225227
@override
226228
Future identify({String? userId, UserTraits? userTraits}) async {
227-
final event = IdentifyEvent(userId: userId, traits: userTraits);
229+
final event = IdentifyEvent(userId: userId, traits: userTraits,
230+
integrations: _state.integrations.state); // Patch for Github Issue #152
228231

229232
await _process(event);
230233
}
231234

232235
@override
233236
Future group(String groupId, {GroupTraits? groupTraits}) async {
234-
final event = GroupEvent(groupId, traits: groupTraits);
237+
final event = GroupEvent(groupId, traits: groupTraits,
238+
integrations: _state.integrations.state); // Patch for Github Issue #152
235239

236240
await _process(event);
237241
}
@@ -240,7 +244,8 @@ class Analytics with ClientMethods {
240244
Future alias(String newUserId) async {
241245
final userInfo = await state.userInfo.state;
242246
final event =
243-
AliasEvent(userInfo.userId ?? userInfo.anonymousId, userId: newUserId);
247+
AliasEvent(userInfo.userId ?? userInfo.anonymousId, userId: newUserId,
248+
integrations: _state.integrations.state); // Patch for Github Issue #152
244249

245250
await _process(event);
246251
}

packages/core/lib/analytics_web.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class AnalyticsPlatformImpl extends AnalyticsPlatform {
1818
NativeContext(
1919
app: NativeContextApp(
2020
name: web.window.navigator.appName,
21-
version: web.window.navigator.appVersion,
21+
version: getAppVersion(), // Patch Github Issue #138
2222
namespace: web.window.navigator.appCodeName,
2323
),
2424
userAgent: web.window.navigator.userAgent,
@@ -28,6 +28,16 @@ class AnalyticsPlatformImpl extends AnalyticsPlatform {
2828
width: web.window.screen.width,
2929
),
3030
);
31+
32+
/*
33+
- Checks for <meta name="app-version" content="1.2.3"> in <root>/web/index.html
34+
and return the value inside 'content'
35+
- Returns the browser version as fallback
36+
*/
37+
String getAppVersion() {
38+
final meta = web.document.querySelector('meta[name="app-version"]');
39+
return meta?.getAttribute('content') ?? web.window.navigator.appVersion;
40+
}
3141
}
3242

3343
class AnalyticsWeb {

packages/core/lib/event.dart

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ abstract class RawEvent with JSONSerialisable {
5555
@JsonKey(name: "_metadata")
5656
DestinationMetadata? metadata;
5757

58-
RawEvent(this.type, {this.anonymousId, this.userId});
58+
RawEvent(this.type, {this.anonymousId, this.userId, this.integrations,}); // Patch for Github Issue #152
5959
}
6060

6161
@JsonSerializable(explicitToJson: true)
@@ -79,7 +79,7 @@ class TrackEvent extends RawEvent {
7979
String event;
8080
Map<String, dynamic>? properties;
8181

82-
TrackEvent(this.event, {this.properties}) : super(EventType.track);
82+
TrackEvent(this.event, {this.properties, Map<String, dynamic>? integrations,}) : super(EventType.track, integrations: integrations,); // Patch for Github Issue #152
8383

8484
factory TrackEvent.fromJson(Map<String, dynamic> json) =>
8585
_$TrackEventFromJson(json);
@@ -90,8 +90,8 @@ class TrackEvent extends RawEvent {
9090
@JsonSerializable(explicitToJson: true)
9191
class IdentifyEvent extends RawEvent {
9292
UserTraits? traits;
93-
IdentifyEvent({this.traits, String? userId})
94-
: super(EventType.identify, userId: userId);
93+
IdentifyEvent({this.traits, String? userId, Map<String, dynamic>? integrations})
94+
: super(EventType.identify, userId: userId, integrations: integrations); // Patch for Github Issue #152
9595

9696
factory IdentifyEvent.fromJson(Map<String, dynamic> json) =>
9797
_$IdentifyEventFromJson(json);
@@ -105,7 +105,7 @@ class GroupEvent extends RawEvent {
105105
String groupId;
106106
GroupTraits? traits;
107107

108-
GroupEvent(this.groupId, {this.traits}) : super(EventType.group);
108+
GroupEvent(this.groupId, {this.traits, Map<String, dynamic>? integrations}) : super(EventType.group, integrations: integrations); // Patch for Github Issue #152
109109

110110
factory GroupEvent.fromJson(Map<String, dynamic> json) =>
111111
_$GroupEventFromJson(json);
@@ -117,8 +117,8 @@ class GroupEvent extends RawEvent {
117117
class AliasEvent extends RawEvent {
118118
String previousId;
119119

120-
AliasEvent(this.previousId, {String? userId})
121-
: super(EventType.alias, userId: userId);
120+
AliasEvent(this.previousId, {String? userId, Map<String, dynamic>? integrations})
121+
: super(EventType.alias, userId: userId, integrations: integrations); // Patch for Github Issue #152
122122

123123
factory AliasEvent.fromJson(Map<String, dynamic> json) =>
124124
_$AliasEventFromJson(json);
@@ -131,7 +131,10 @@ class ScreenEvent extends RawEvent {
131131
String name;
132132
Map<String, dynamic>? properties;
133133

134-
ScreenEvent(this.name, {this.properties}) : super(EventType.screen);
134+
ScreenEvent(
135+
this.name, {
136+
this.properties,
137+
Map<String, dynamic>? integrations}) : super(EventType.screen, integrations: integrations); // Patch for Github Issue #152
135138

136139
factory ScreenEvent.fromJson(Map<String, dynamic> json) =>
137140
_$ScreenEventFromJson(json);

packages/core/lib/state.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,5 +583,6 @@ Configuration setFlushPolicies(
583583
trackApplicationLifecycleEvents: a.trackApplicationLifecycleEvents,
584584
trackDeeplinks: a.trackDeeplinks,
585585
storageJson: a.storageJson,
586-
token: a.token);
586+
token: a.token,
587+
collectDeviceId: a.collectDeviceId); //Patch for for Github issue #144
587588
}

packages/core/lib/timeline.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ class Timeline {
9999
Future<RawEvent?> applyPlugins(PluginType type, RawEvent event) async {
100100
RawEvent? result = event;
101101

102-
final plugins = _plugins[type];
103-
if (plugins != null) {
102+
final plugins = List<Plugin>.from(_plugins[type] ?? []); //Patch for Github issue #157
104103
for (var plugin in plugins) {
105104
if (result != null) {
106105
try {
@@ -122,7 +121,6 @@ class Timeline {
122121
}
123122
}
124123
}
125-
}
126124
return result;
127125
}
128126
}

0 commit comments

Comments
 (0)