Skip to content

Commit

Permalink
Merge 9616d3c into 08446c1
Browse files Browse the repository at this point in the history
  • Loading branch information
zvikarp committed Mar 26, 2024
2 parents 08446c1 + 9616d3c commit 03b9039
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions lib/src/matomo.dart
Expand Up @@ -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<Map<String, String>> queue;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -301,7 +314,7 @@ class MatomoTracker {
firstVisit = localFirstVisit;
} else {
unawaited(_localStorage.setFirstVisit(now));

// Save the visitorId for future visits.
unawaited(_saveVisitorId(localVisitorId));
}
Expand Down

0 comments on commit 03b9039

Please sign in to comment.