From 6666bcf0ca8636f98d6192f7449275af5bc1dd18 Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 18 Mar 2022 12:13:30 +0100 Subject: [PATCH] Support for setting clientId --- lib/src/usage_impl.dart | 5 +++++ lib/usage.dart | 6 ++++++ test/src/common.dart | 10 ++++++++++ 3 files changed, 21 insertions(+) diff --git a/lib/src/usage_impl.dart b/lib/src/usage_impl.dart index 870d123..0d51ef1 100644 --- a/lib/src/usage_impl.dart +++ b/lib/src/usage_impl.dart @@ -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`, ...). /// diff --git a/lib/usage.dart b/lib/usage.dart index cd548fe..9ba68eb 100644 --- a/lib/usage.dart +++ b/lib/usage.dart @@ -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 @@ -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? parameters}) { parameters ??= {}; diff --git a/test/src/common.dart b/test/src/common.dart index b08d89b..958e704 100644 --- a/test/src/common.dart +++ b/test/src/common.dart @@ -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? props}) : super(trackingId, MockProperties(props), StallingPostHandler(), applicationName: 'Test App', applicationVersion: '0.1'); + + @override + set clientId(String value) { + properties['clientId'] = value; + } } class StallingPostHandler extends PostHandler {