Skip to content

Commit

Permalink
feat: openfoodfacts#2852 - Matomo message when barcode is not found (o…
Browse files Browse the repository at this point in the history
…penfoodfacts#2854)

Impacted files:
* `analytics_helper.dart`: new method about barcode not found; fixed typos
* `barcode_product_query.dart`: added Matomo (and not Sentry) message when barcode is not found
  • Loading branch information
monsieurtanuki authored Aug 29, 2022
1 parent 4187014 commit 3dca648
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
26 changes: 21 additions & 5 deletions packages/smooth_app/lib/helpers/analytics_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:matomo_tracker/matomo_tracker.dart';
import 'package:openfoodfacts/model/Product.dart';
import 'package:openfoodfacts/utils/CountryHelper.dart';
import 'package:openfoodfacts/utils/LanguageHelper.dart';
import 'package:openfoodfacts/utils/OpenFoodAPIConfiguration.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
Expand All @@ -25,10 +27,11 @@ class AnalyticsHelper {
static const String _scanAction = 'scanned product';
static const String _productPageAction = 'opened product page';
static const String _personalizedRankingAction = 'personalized ranking';
static const String _shareProductActionn = 'shared product';
static const String _shareProductAction = 'shared product';
static const String _loginAction = 'logged in';
static const String _registerAction = 'register';
static const String _userManagmentCategory = 'user management';
static const String _userManagementCategory = 'user management';
static const String _couldNotFindProduct = 'could not find product';

static String latestSearch = '';

Expand Down Expand Up @@ -139,17 +142,30 @@ class AnalyticsHelper {

static void trackShareProduct({required String barcode}) =>
MatomoTracker.instance.trackEvent(
eventName: _shareProductActionn,
eventName: _shareProductAction,
action: 'shared',
eventCategory: 'product page',
eventValue: int.tryParse(barcode),
);

static void trackLogin() => MatomoTracker.instance
.trackEvent(action: _loginAction, eventCategory: _userManagmentCategory);
.trackEvent(action: _loginAction, eventCategory: _userManagementCategory);

static void trackRegister() => MatomoTracker.instance.trackEvent(
action: _registerAction, eventCategory: _userManagmentCategory);
action: _registerAction, eventCategory: _userManagementCategory);

static void trackUnknownProduct({
required String barcode,
required bool isScanned,
required OpenFoodFactsLanguage? language,
required OpenFoodFactsCountry? country,
}) =>
MatomoTracker.instance.trackEvent(
eventName: _couldNotFindProduct,
action: '${language?.code ?? 'xx'}_${country?.iso2Code ?? 'xx'}',
eventCategory: isScanned ? 'scan' : 'not scan',
eventValue: int.tryParse(barcode),
);

static int _formatBarcode(String barcode) {
const int fallback = 000000000;
Expand Down
14 changes: 12 additions & 2 deletions packages/smooth_app/lib/query/barcode_product_query.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import 'dart:async';

import 'package:openfoodfacts/openfoodfacts.dart';
import 'package:openfoodfacts/utils/CountryHelper.dart';
import 'package:smooth_app/data_models/fetched_product.dart';
import 'package:smooth_app/database/dao_product.dart';
import 'package:smooth_app/helpers/analytics_helper.dart';
import 'package:smooth_app/query/product_query.dart';

class BarcodeProductQuery {
Expand All @@ -17,11 +19,13 @@ class BarcodeProductQuery {
final bool isScanned;

Future<FetchedProduct> getFetchedProduct() async {
final OpenFoodFactsLanguage? language = ProductQuery.getLanguage();
final OpenFoodFactsCountry? country = ProductQuery.getCountry();
final ProductQueryConfiguration configuration = ProductQueryConfiguration(
barcode,
fields: ProductQuery.fields,
language: ProductQuery.getLanguage(),
country: ProductQuery.getCountry(),
language: language,
country: country,
);

final ProductResult result;
Expand All @@ -45,6 +49,12 @@ class BarcodeProductQuery {
(result.barcode == null || result.barcode!.isEmpty)) {
return FetchedProduct.error(FetchedProductStatus.codeInvalid);
}
AnalyticsHelper.trackUnknownProduct(
barcode: barcode,
isScanned: isScanned,
language: language,
country: country,
);
return FetchedProduct.error(FetchedProductStatus.internetNotFound);
}
}

0 comments on commit 3dca648

Please sign in to comment.