Skip to content

Patches for Github Issues #159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: release/1.1.7
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/core/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -44,4 +44,4 @@ android {
defaultConfig {
minSdkVersion 16
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
),
Expand Down
10 changes: 5 additions & 5 deletions packages/core/lib/analytics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -212,26 +212,26 @@ class Analytics with ClientMethods {

@override
Future track(String event, {Map<String, dynamic>? properties}) async {
await _process(TrackEvent(event, properties: properties ?? {}));
await _process(TrackEvent(event, properties: properties ?? {}, integrations: _state.integrations.state));
}

@override
Future screen(String name, {Map<String, dynamic>? properties}) async {
final event = ScreenEvent(name, properties: properties ?? {});
final event = ScreenEvent(name, properties: properties ?? {}, integrations: _state.integrations.state);

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);

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);

await _process(event);
}
Expand All @@ -240,7 +240,7 @@ 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);

await _process(event);
}
Expand Down
12 changes: 11 additions & 1 deletion packages/core/lib/analytics_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -28,6 +28,16 @@ class AnalyticsPlatformImpl extends AnalyticsPlatform {
width: web.window.screen.width,
),
);

/*
- Checks for <meta name="app-version" content="1.2.3"> in <root>/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 {
Expand Down
19 changes: 11 additions & 8 deletions packages/core/lib/event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,});
}

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

TrackEvent(this.event, {this.properties}) : super(EventType.track);
TrackEvent(this.event, {this.properties, Map<String, dynamic>? integrations,}) : super(EventType.track, integrations: integrations,);

factory TrackEvent.fromJson(Map<String, dynamic> json) =>
_$TrackEventFromJson(json);
Expand All @@ -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<String, dynamic>? integrations})
: super(EventType.identify, userId: userId, integrations: integrations);

factory IdentifyEvent.fromJson(Map<String, dynamic> json) =>
_$IdentifyEventFromJson(json);
Expand All @@ -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<String, dynamic>? integrations}) : super(EventType.group, integrations: integrations);

factory GroupEvent.fromJson(Map<String, dynamic> json) =>
_$GroupEventFromJson(json);
Expand All @@ -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<String, dynamic>? integrations})
: super(EventType.alias, userId: userId, integrations: integrations);

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

ScreenEvent(this.name, {this.properties}) : super(EventType.screen);
ScreenEvent(
this.name, {
this.properties,
Map<String, dynamic>? integrations}) : super(EventType.screen, integrations: integrations);

factory ScreenEvent.fromJson(Map<String, dynamic> json) =>
_$ScreenEventFromJson(json);
Expand Down
3 changes: 2 additions & 1 deletion packages/core/lib/state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
}