From 5e85d1890ceeeacc42f2c26d0fc171bf256ed38a Mon Sep 17 00:00:00 2001 From: Guillaume Roux Date: Thu, 17 Aug 2023 13:29:52 +0200 Subject: [PATCH 1/8] feat: added setUrl method --- lib/src/matomo.dart | 17 +++++++++++++++-- lib/src/matomo_dispatcher.dart | 16 ++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/lib/src/matomo.dart b/lib/src/matomo.dart index 6cb4b20..f52aa2f 100644 --- a/lib/src/matomo.dart +++ b/lib/src/matomo.dart @@ -61,7 +61,20 @@ class MatomoTracker { /// Should not be confused with the `url` tracking parameter /// which is constructed by combining [contentBase] with a `path` /// (e.g. in [trackPageViewWithName]). - late final String url; + String get url { + if (_url case final url?) { + return url; + } + throw const UninitializedMatomoInstanceException(); + } + + String? _url; + + void setUrl(String newUrl) { + _url = newUrl; + _dispatcher = _dispatcher.copyWith(baseUrl: newUrl); + } + late final Session session; Visitor get visitor => _visitor; @@ -223,7 +236,7 @@ class MatomoTracker { log.setLogging(level: verbosityLevel); this.siteId = siteId; - this.url = url; + _url = url; this.customHeaders = customHeaders; _pingInterval = pingInterval; _lock = sync.Lock(); diff --git a/lib/src/matomo_dispatcher.dart b/lib/src/matomo_dispatcher.dart index 5795cdd..0ed7af6 100644 --- a/lib/src/matomo_dispatcher.dart +++ b/lib/src/matomo_dispatcher.dart @@ -78,4 +78,20 @@ class MatomoDispatcher { return baseUri.replace(queryParameters: queryParameters); } + + MatomoDispatcher copyWith({ + String? baseUrl, + String? tokenAuth, + String? userAgent, + Logger? log, + http.Client? httpClient, + }) { + return MatomoDispatcher( + baseUrl: baseUrl ?? baseUri.toString(), + tokenAuth: tokenAuth ?? this.tokenAuth, + userAgent: userAgent ?? this.userAgent, + log: log ?? this.log, + httpClient: httpClient ?? this.httpClient, + ); + } } From 54694266497de1099666844cdb39401356a06a7c Mon Sep 17 00:00:00 2001 From: Guillaume Roux Date: Thu, 17 Aug 2023 13:41:34 +0200 Subject: [PATCH 2/8] test: added test for url and MatomoDispatcher.copyWith --- lib/src/matomo.dart | 2 ++ test/src/matomo_dispatcher_test.dart | 40 ++++++++++++++++++++++++++++ test/src/matomo_test.dart | 23 ++++++++++++++++ 3 files changed, 65 insertions(+) diff --git a/lib/src/matomo.dart b/lib/src/matomo.dart index f52aa2f..b1e3db6 100644 --- a/lib/src/matomo.dart +++ b/lib/src/matomo.dart @@ -71,6 +71,8 @@ class MatomoTracker { String? _url; void setUrl(String newUrl) { + _initializationCheck(); + _url = newUrl; _dispatcher = _dispatcher.copyWith(baseUrl: newUrl); } diff --git a/test/src/matomo_dispatcher_test.dart b/test/src/matomo_dispatcher_test.dart index 8573993..9f8b156 100644 --- a/test/src/matomo_dispatcher_test.dart +++ b/test/src/matomo_dispatcher_test.dart @@ -207,4 +207,44 @@ void main() { ), ); }); + + group('copyWith', () { + test('should copy with new url', () { + const newUrl = 'https://test.com'; + + final initialDispatcher = MatomoDispatcher( + baseUrl: matomoDispatcherBaseUrl, + userAgent: matomoTrackerUserAgent, + tokenAuth: matomoDispatcherToken, + httpClient: mockHttpClient, + log: mockLogger, + ); + + final newDispatcher = initialDispatcher.copyWith(baseUrl: newUrl); + + expect(newDispatcher.baseUri.toString(), newUrl); + expect(newDispatcher.userAgent, matomoTrackerUserAgent); + expect(newDispatcher.tokenAuth, matomoDispatcherToken); + expect(newDispatcher.httpClient, mockHttpClient); + expect(newDispatcher.log, mockLogger); + }); + + test('should do nothing', () { + final initialDispatcher = MatomoDispatcher( + baseUrl: matomoDispatcherBaseUrl, + userAgent: matomoTrackerUserAgent, + tokenAuth: matomoDispatcherToken, + httpClient: mockHttpClient, + log: mockLogger, + ); + + final newDispatcher = initialDispatcher.copyWith(); + + expect(newDispatcher.baseUri.toString(), matomoDispatcherBaseUrl); + expect(newDispatcher.userAgent, matomoTrackerUserAgent); + expect(newDispatcher.tokenAuth, matomoDispatcherToken); + expect(newDispatcher.httpClient, mockHttpClient); + expect(newDispatcher.log, mockLogger); + }); + }); } diff --git a/test/src/matomo_test.dart b/test/src/matomo_test.dart index 7f68c7d..15946c0 100644 --- a/test/src/matomo_test.dart +++ b/test/src/matomo_test.dart @@ -1,6 +1,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:matomo_tracker/src/content.dart'; import 'package:matomo_tracker/src/event_info.dart'; +import 'package:matomo_tracker/src/exceptions.dart'; import 'package:matomo_tracker/src/matomo.dart'; import 'package:mocktail/mocktail.dart'; @@ -474,4 +475,26 @@ void main() { }, ); }); + + group('url getter', () { + test('should throw if not initialized', () { + final tracker = MatomoTracker(); + + expect( + () => tracker.url, + throwsA(isA()), + ); + }); + }); + + group('setUrl', () { + test('should throw if not initialized', () { + final tracker = MatomoTracker(); + + expect( + () => tracker.setUrl(''), + throwsA(isA()), + ); + }); + }); } From e9ce78ae2f4a2267651ac9d7597064cde671901a Mon Sep 17 00:00:00 2001 From: Guillaume Roux Date: Thu, 17 Aug 2023 13:51:06 +0200 Subject: [PATCH 3/8] chore: added tests and documentation --- lib/src/matomo.dart | 9 +++++++++ test/src/matomo_test.dart | 18 ++++++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/lib/src/matomo.dart b/lib/src/matomo.dart index b1e3db6..f9bb212 100644 --- a/lib/src/matomo.dart +++ b/lib/src/matomo.dart @@ -45,6 +45,9 @@ class MatomoTracker { late final PlatformInfo _platformInfo; + @visibleForTesting + MatomoDispatcher get dispatcher => _dispatcher; + late MatomoDispatcher _dispatcher; static final instance = MatomoTracker._internal(); @@ -61,6 +64,8 @@ class MatomoTracker { /// Should not be confused with the `url` tracking parameter /// which is constructed by combining [contentBase] with a `path` /// (e.g. in [trackPageViewWithName]). + /// + /// You can use [setUrl] to change this value after initialization. String get url { if (_url case final url?) { return url; @@ -70,6 +75,10 @@ class MatomoTracker { String? _url; + /// Sets the url of the Matomo endpoint and updates the dispatcher. + /// + /// Note that this will change the url used by the request that are still + /// in the queue. void setUrl(String newUrl) { _initializationCheck(); diff --git a/test/src/matomo_test.dart b/test/src/matomo_test.dart index 15946c0..395ecb5 100644 --- a/test/src/matomo_test.dart +++ b/test/src/matomo_test.dart @@ -478,10 +478,8 @@ void main() { group('url getter', () { test('should throw if not initialized', () { - final tracker = MatomoTracker(); - expect( - () => tracker.url, + () => MatomoTracker().url, throwsA(isA()), ); }); @@ -489,12 +487,20 @@ void main() { group('setUrl', () { test('should throw if not initialized', () { - final tracker = MatomoTracker(); - expect( - () => tracker.setUrl(''), + () => MatomoTracker().setUrl(''), throwsA(isA()), ); }); + + test('should set the new url and dispatcher', () async { + const newUrl = 'https://test.com'; + final tracker = await getInitializedMatomoTracker(); + + tracker.setUrl(newUrl); + + expect(tracker.url, newUrl); + expect(tracker.dispatcher.baseUri.toString(), newUrl); + }); }); } From aab15af27216935134cd56b5407041c96b775051 Mon Sep 17 00:00:00 2001 From: Guillaume Roux Date: Mon, 11 Sep 2023 13:38:55 +0200 Subject: [PATCH 4/8] chore: prepare release v4.1.0 --- CHANGELOG.md | 10 ++++++++++ pubspec.yaml | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e14e3b9..d2aeb79 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog +## [4.1.0] + +* Bump custom_lint from 0.4.0 to 0.5.0 by @dependabot in https://github.com/Floating-Dartists/matomo-tracker/pull/114 +* Bump mocktail from 0.3.0 to 1.0.0 by @dependabot in https://github.com/Floating-Dartists/matomo-tracker/pull/116 +* feat: fixed README and bumped dependencies by @TesteurManiak in https://github.com/Floating-Dartists/matomo-tracker/pull/118 +* Feat: Change url on the fly by @TesteurManiak in https://github.com/Floating-Dartists/matomo-tracker/pull/120 + + +**Full Changelog**: https://github.com/Floating-Dartists/matomo-tracker/compare/4.0.0...4.1.0 + ## [4.0.0] **Check the [Migration Guide](https://github.com/Floating-Dartists/matomo-tracker#v400) to learn about breaking changes in this version** diff --git a/pubspec.yaml b/pubspec.yaml index 293ee53..8b74856 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: matomo_tracker description: A fully cross-platform wrap of the Matomo tracking client for Flutter, using the Matomo API. -version: 4.0.0 +version: 4.1.0 homepage: https://github.com/Floating-Dartists/matomo-tracker repository: https://github.com/Floating-Dartists/matomo-tracker issue_tracker: https://github.com/Floating-Dartists/matomo-tracker/issues @@ -21,7 +21,7 @@ dependencies: sdk: flutter http: ^1.1.0 package_info_plus: ^4.1.0 - shared_preferences: ^2.2.0 + shared_preferences: ^2.2.1 uuid: ^3.0.7 dev_dependencies: From 6b8810a8ecae7f6180de33310b1d45273473384a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 9 Oct 2023 09:34:48 +0000 Subject: [PATCH 5/8] Bump package_info_plus from 4.1.0 to 5.0.0 Bumps [package_info_plus](https://github.com/fluttercommunity/plus_plugins/tree/main/packages/package_info_plus) from 4.1.0 to 5.0.0. - [Release notes](https://github.com/fluttercommunity/plus_plugins/releases) - [Commits](https://github.com/fluttercommunity/plus_plugins/commits/package_info_plus-v5.0.0/packages/package_info_plus) --- updated-dependencies: - dependency-name: package_info_plus dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 8b74856..147fabe 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -20,7 +20,7 @@ dependencies: flutter: sdk: flutter http: ^1.1.0 - package_info_plus: ^4.1.0 + package_info_plus: ">=4.1.0 <6.0.0" shared_preferences: ^2.2.1 uuid: ^3.0.7 From 201997be6da2c075e61db3b4e7881651812d3c05 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 9 Oct 2023 09:35:12 +0000 Subject: [PATCH 6/8] Bump device_info_plus from 9.0.3 to 10.0.0 Bumps [device_info_plus](https://github.com/fluttercommunity/plus_plugins/tree/main/packages/device_info_plus) from 9.0.3 to 10.0.0. - [Release notes](https://github.com/fluttercommunity/plus_plugins/releases) - [Commits](https://github.com/fluttercommunity/plus_plugins/commits/device_info_plus-v10.0.0/packages/device_info_plus) --- updated-dependencies: - dependency-name: device_info_plus dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 8b74856..bcce18e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ environment: dependencies: clock: ^1.1.1 collection: ^1.17.1 - device_info_plus: ^9.0.3 + device_info_plus: ">=9.0.3 <11.0.0" flutter: sdk: flutter http: ^1.1.0 From 981f454040c712671ffbc5c1e1ad8e481c488ba7 Mon Sep 17 00:00:00 2001 From: Guillaume Roux Date: Thu, 12 Oct 2023 08:18:48 +0200 Subject: [PATCH 7/8] chore: bump dependencies, fix formatting --- lib/src/campaign.dart | 2 +- pubspec.yaml | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/src/campaign.dart b/lib/src/campaign.dart index 2bac9d1..e31f36b 100644 --- a/lib/src/campaign.dart +++ b/lib/src/campaign.dart @@ -3,7 +3,7 @@ import 'package:matomo_tracker/src/assert.dart'; /// Describes a campaign. /// /// Multiple `track...` methods in [MatomoTracker] can take a campaign as argument. -/// +/// /// When using campaigns, it should be noted that each visit can only have at most /// one campaign associated with it. It does not matter if the first `track...` /// call or a subsequent `track...` call has the campaign attached, it will be treated diff --git a/pubspec.yaml b/pubspec.yaml index 37a200b..b156a1e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: matomo_tracker description: A fully cross-platform wrap of the Matomo tracking client for Flutter, using the Matomo API. -version: 4.1.0 +version: 4.1.1 homepage: https://github.com/Floating-Dartists/matomo-tracker repository: https://github.com/Floating-Dartists/matomo-tracker issue_tracker: https://github.com/Floating-Dartists/matomo-tracker/issues @@ -15,21 +15,21 @@ environment: dependencies: clock: ^1.1.1 - collection: ^1.17.1 + collection: ^1.17.2 device_info_plus: ">=9.0.3 <11.0.0" flutter: sdk: flutter http: ^1.1.0 package_info_plus: ">=4.1.0 <6.0.0" - shared_preferences: ^2.2.1 + shared_preferences: ^2.2.2 uuid: ^3.0.7 dev_dependencies: - custom_lint: ">=0.4.0 <0.6.0" - fd_lints: ^2.1.0 + custom_lint: ^0.5.3 + fd_lints: ^2.2.0 flutter_test: sdk: flutter meta: ^1.9.1 - mocktail: ^1.0.0 + mocktail: ^1.0.1 flutter: null From a97903fc8c30b7114415d472e29c239dcbaac72b Mon Sep 17 00:00:00 2001 From: Guillaume Roux Date: Thu, 12 Oct 2023 09:22:55 +0200 Subject: [PATCH 8/8] chore: update CHANGELOG --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d2aeb79..4c05cbf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## [4.1.1] + +* Bump device_info_plus from 9.0.3 to 10.0.0 by @dependabot in https://github.com/Floating-Dartists/matomo-tracker/pull/123 +* Bump package_info_plus from 4.1.0 to 5.0.0 by @dependabot in https://github.com/Floating-Dartists/matomo-tracker/pull/122 +* chore: bump dependencies, fix formatting by @TesteurManiak in https://github.com/Floating-Dartists/matomo-tracker/pull/124 + + +**Full Changelog**: https://github.com/Floating-Dartists/matomo-tracker/compare/4.1.0...4.1.1 + ## [4.1.0] * Bump custom_lint from 0.4.0 to 0.5.0 by @dependabot in https://github.com/Floating-Dartists/matomo-tracker/pull/114