Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 3679 - reporting with a 000000000000 matomo user id #3840

Merged
merged 11 commits into from
Apr 4, 2023
19 changes: 15 additions & 4 deletions packages/smooth_app/lib/helpers/analytics_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ class AnalyticsHelper {

static String latestSearch = '';

/// Did the user allow the analytic reports?
static bool _allow = false;

static Future<void> initSentry({
required Function()? appRunner,
}) async {
Expand All @@ -114,7 +117,8 @@ class AnalyticsHelper {
_crashReports = crashReports;

static Future<void> setAnalyticsReports(final bool allow) async {
await MatomoTracker.instance.setOptOut(optout: !allow);
_allow = allow;
await MatomoTracker.instance.setOptOut(optout: false);
}

static FutureOr<SentryEvent?> _beforeSend(SentryEvent event,
Expand All @@ -133,7 +137,6 @@ class AnalyticsHelper {
setAnalyticsReports(false);
return;
}

try {
await MatomoTracker.instance.initialize(
url: 'https://analytics.openfoodfacts.org/matomo.php',
Expand All @@ -146,8 +149,16 @@ class AnalyticsHelper {
}

/// A UUID must be at least one 16 characters
static String? get uuid =>
kDebugMode ? 'smoothie-debug--' : OpenFoodAPIConfiguration.uuid;
static String? get uuid {
// if user opts out then track anonymously with userId containg zeros
if (kDebugMode) {
return 'smoothie_debug--';
}
if (!_allow) {
return '0' * 16;
}
return OpenFoodAPIConfiguration.uuid;
}

static void trackEvent(
AnalyticsEvent msg, {
Expand Down