From 744071b61dcbf7c4c6c7ac87aef3e34857140177 Mon Sep 17 00:00:00 2001 From: Zvi Karp Date: Tue, 26 Mar 2024 11:41:02 +0200 Subject: [PATCH 1/2] feat: added option to toggle off cookieless --- lib/src/matomo.dart | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/lib/src/matomo.dart b/lib/src/matomo.dart index 709a236..b79376f 100644 --- a/lib/src/matomo.dart +++ b/lib/src/matomo.dart @@ -147,7 +147,23 @@ class MatomoTracker { bool _cookieless = false; bool get cookieless => _cookieless; - late final LocalStorage _localStorage; + void setCookieless({ + required bool cookieless, + LocalStorage? localStorage, + }) { + if (_cookieless == cookieless) return; + _cookieless = cookieless; + _setLocalStorage(localStorage); + } + + void _setLocalStorage(LocalStorage? localStorage) { + final effectiveLocalStorage = localStorage ?? SharedPrefsStorage(); + _localStorage = cookieless + ? CookielessStorage(storage: effectiveLocalStorage) + : effectiveLocalStorage; + } + + late LocalStorage _localStorage; @visibleForTesting late final Queue> queue; @@ -258,10 +274,7 @@ class MatomoTracker { this.attachLastScreenInfo = attachLastScreenInfo; _dispatchSettings = dispatchSettings; - final effectiveLocalStorage = localStorage ?? SharedPrefsStorage(); - _localStorage = cookieless - ? CookielessStorage(storage: effectiveLocalStorage) - : effectiveLocalStorage; + _setLocalStorage(localStorage); final onLoad = _dispatchSettings.onLoad; queue = _dispatchSettings.persistentQueue && onLoad != null @@ -301,7 +314,7 @@ class MatomoTracker { firstVisit = localFirstVisit; } else { unawaited(_localStorage.setFirstVisit(now)); - + // Save the visitorId for future visits. unawaited(_saveVisitorId(localVisitorId)); } @@ -983,4 +996,4 @@ class MatomoTracker { String? _inferPath(String? path) => path ?? (attachLastScreenInfo ? _lastPageView?.path : null); -} +} \ No newline at end of file From 9616d3c750efd054f99c76728bf04c46ad6c9dde Mon Sep 17 00:00:00 2001 From: Zvi Karp Date: Tue, 26 Mar 2024 12:26:47 +0200 Subject: [PATCH 2/2] fix: formatting --- lib/src/matomo.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/matomo.dart b/lib/src/matomo.dart index b79376f..d355c05 100644 --- a/lib/src/matomo.dart +++ b/lib/src/matomo.dart @@ -996,4 +996,4 @@ class MatomoTracker { String? _inferPath(String? path) => path ?? (attachLastScreenInfo ? _lastPageView?.path : null); -} \ No newline at end of file +}