Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Support for setting clientId #166

Closed
wants to merge 2 commits into from
Closed
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
5 changes: 5 additions & 0 deletions lib/src/usage_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,11 @@ class AnalyticsImpl implements Analytics {
@override
String get clientId => properties['clientId'] ??= Uuid().generateV4();

@override
set clientId(String value) {
properties['clientId'] = value;
}

/// Send raw data to analytics. Callers should generally use one of the typed
/// methods (`sendScreenView`, `sendEvent`, ...).
///
Expand Down
6 changes: 6 additions & 0 deletions lib/usage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ abstract class Analytics {
/// computer sending analytics data.
String get clientId;

// Set a custom client id.
set clientId(String value);

/// Sends a screen view hit to Google Analytics.
///
/// [parameters] can be any analytics key/value pair. Useful
Expand Down Expand Up @@ -219,6 +222,9 @@ class AnalyticsMock implements Analytics {
@override
String get clientId => '00000000-0000-4000-0000-000000000000';

@override
set clientId(String value) {}

@override
Future sendScreenView(String viewName, {Map<String, String>? parameters}) {
parameters ??= <String, String>{};
Expand Down
10 changes: 10 additions & 0 deletions test/src/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,22 @@ class AnalyticsImplMock extends AnalyticsImpl {
applicationName: 'Test App', applicationVersion: '0.1');

String get last => mockPostHandler.last;

@override
set clientId(String value) {
properties['clientId'] = value;
}
}

class StallingAnalyticsImplMock extends AnalyticsImpl {
StallingAnalyticsImplMock(String trackingId, {Map<String, dynamic>? props})
: super(trackingId, MockProperties(props), StallingPostHandler(),
applicationName: 'Test App', applicationVersion: '0.1');

@override
set clientId(String value) {
properties['clientId'] = value;
}
}

class StallingPostHandler extends PostHandler {
Expand Down