Skip to content

Commit

Permalink
Merge pull request #143 from zvikarp/main
Browse files Browse the repository at this point in the history
feat: added option to toggle off cookieless
  • Loading branch information
TesteurManiak authored Mar 29, 2024
2 parents 08446c1 + 9616d3c commit d7dd890
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions lib/src/matomo.dart
Original file line number Diff line number Diff line change
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 d7dd890

Please sign in to comment.