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

feat: 3843 - matomo for new product page #4217

Merged
merged 2 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions packages/smooth_app/lib/helpers/analytics_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ enum AnalyticsCategory {
share(tag: 'share'),
couldNotFindProduct(tag: 'could not find product'),
productEdit(tag: 'product edit'),
newProduct(tag: 'new product'),
list(tag: 'list'),
deepLink(tag: 'deep link');

Expand Down Expand Up @@ -47,6 +48,30 @@ enum AnalyticsEvent {
tag: 'opened product edit page',
category: AnalyticsCategory.productEdit,
),
openNewProductPage(
tag: 'opened new product page',
category: AnalyticsCategory.newProduct,
),
categoriesNewProductPage(
tag: 'set categories on new product page',
category: AnalyticsCategory.newProduct,
),
nutritionNewProductPage(
tag: 'set nutrition facts on new product page',
category: AnalyticsCategory.newProduct,
),
ingredientsNewProductPage(
tag: 'set ingredients on new product page',
category: AnalyticsCategory.newProduct,
),
imagesNewProductPage(
tag: 'set at least one image on new product page',
category: AnalyticsCategory.newProduct,
),
closeEmptyNewProductPage(
tag: 'closed new product page without any input',
category: AnalyticsCategory.newProduct,
),
shareList(tag: 'shared a list', category: AnalyticsCategory.list),
openListWeb(tag: 'open a list in wbe', category: AnalyticsCategory.list),
productDeepLink(
Expand Down
119 changes: 96 additions & 23 deletions packages/smooth_app/lib/pages/product/add_new_product_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:matomo_tracker/matomo_tracker.dart';
import 'package:openfoodfacts/openfoodfacts.dart';
import 'package:provider/provider.dart';
import 'package:smooth_app/data_models/product_list.dart';
Expand All @@ -12,6 +13,7 @@ import 'package:smooth_app/generic_lib/design_constants.dart';
import 'package:smooth_app/generic_lib/dialogs/smooth_alert_dialog.dart';
import 'package:smooth_app/generic_lib/svg_icon_chip.dart';
import 'package:smooth_app/generic_lib/widgets/smooth_card.dart';
import 'package:smooth_app/helpers/analytics_helper.dart';
import 'package:smooth_app/helpers/image_field_extension.dart';
import 'package:smooth_app/pages/image_crop_page.dart';
import 'package:smooth_app/pages/product/common/product_dialog_helper.dart';
Expand Down Expand Up @@ -43,7 +45,8 @@ class AddNewProductPage extends StatefulWidget {
State<AddNewProductPage> createState() => _AddNewProductPageState();
}

class _AddNewProductPageState extends State<AddNewProductPage> {
class _AddNewProductPageState extends State<AddNewProductPage>
with TraceableClientMixin {
// Just one file per main image field
final Map<ImageField, File> _uploadedImages = <ImageField, File>{};

Expand Down Expand Up @@ -75,6 +78,17 @@ class _AddNewProductPageState extends State<AddNewProductPage> {

bool _ecoscoreExpanded = false;

bool _trackedPopulatedCategories = false;
bool _trackedPopulatedIngredients = false;
bool _trackedPopulatedNutrition = false;
bool _trackedPopulatedImages = false;

@override
String get traceName => 'Opened add_new_product_page';

@override
String get traceTitle => 'add_new_product_page';

@override
void initState() {
super.initState();
Expand All @@ -90,6 +104,10 @@ class _AddNewProductPageState extends State<AddNewProductPage> {
_localDatabase = context.read<LocalDatabase>();
_localDatabase.upToDate.showInterest(barcode);
_daoProductList = DaoProductList(_localDatabase);
AnalyticsHelper.trackEvent(
monsieurtanuki marked this conversation as resolved.
Show resolved Hide resolved
AnalyticsEvent.openNewProductPage,
barcode: barcode,
);
}

@override
Expand Down Expand Up @@ -129,6 +147,12 @@ class _AddNewProductPageState extends State<AddNewProductPage> {
),
),
);
if (leaveThePage == true) {
AnalyticsHelper.trackEvent(
AnalyticsEvent.closeEmptyNewProductPage,
barcode: barcode,
);
}
return leaveThePage ?? false;
},
child: SmoothScaffold(
Expand Down Expand Up @@ -250,7 +274,7 @@ class _AddNewProductPageState extends State<AddNewProductPage> {
if (_ecoscoreExpanded) _buildEditorButton(context, _originEditor),
if (_ecoscoreExpanded) _buildEditorButton(context, _labelEditor),
if (_ecoscoreExpanded) _buildEditorButton(context, _packagingEditor),
if (_ecoscoreExpanded) _buildEditorButton(context, _ingredientsEditor),
if (_ecoscoreExpanded) _buildIngredientsButton(context),
];
}

Expand All @@ -267,9 +291,8 @@ class _AddNewProductPageState extends State<AddNewProductPage> {
style: _getSubtitleStyle(context),
),
_buildCategoriesButton(context),
_buildEditorButton(
_buildIngredientsButton(
context,
_ingredientsEditor,
forceIconData: Icons.filter_2,
disabled: !_categoryEditor.isPopulated(_product),
),
Expand Down Expand Up @@ -339,6 +362,13 @@ class _AddNewProductPageState extends State<AddNewProductPage> {
);
if (finalPhoto != null) {
setState(() {
if (!_trackedPopulatedImages) {
_trackedPopulatedImages = true;
AnalyticsHelper.trackEvent(
AnalyticsEvent.imagesNewProductPage,
barcode: barcode,
);
}
if (imageField == ImageField.OTHER) {
_otherUploadedImages.add(finalPhoto);
} else {
Expand All @@ -350,19 +380,30 @@ class _AddNewProductPageState extends State<AddNewProductPage> {
done: imageFile != null,
);

Widget _buildNutritionInputButton(final BuildContext context) => _MyButton(
AppLocalizations.of(context).nutritional_facts_input_button_label,
Icons.filter_2,
// deactivated when the categories were not set beforehand
!_categoryEditor.isPopulated(_product)
? null
: () async => NutritionPageLoaded.showNutritionPage(
product: _product,
isLoggedInMandatory: false,
widget: this,
),
done: _nutritionFactsAdded,
);
Widget _buildNutritionInputButton(final BuildContext context) {
if (!_trackedPopulatedNutrition) {
if (_nutritionFactsAdded) {
_trackedPopulatedNutrition = true;
AnalyticsHelper.trackEvent(
AnalyticsEvent.nutritionNewProductPage,
barcode: barcode,
);
}
}
return _MyButton(
AppLocalizations.of(context).nutritional_facts_input_button_label,
Icons.filter_2,
// deactivated when the categories were not set beforehand
!_categoryEditor.isPopulated(_product)
? null
: () async => NutritionPageLoaded.showNutritionPage(
product: _product,
isLoggedInMandatory: false,
widget: this,
),
done: _nutritionFactsAdded,
);
}

Widget _buildEditorButton(
final BuildContext context,
Expand All @@ -385,12 +426,22 @@ class _AddNewProductPageState extends State<AddNewProductPage> {
);
}

Widget _buildCategoriesButton(final BuildContext context) =>
_buildEditorButton(
context,
_categoryEditor,
forceIconData: Icons.filter_1,
);
Widget _buildCategoriesButton(final BuildContext context) {
if (!_trackedPopulatedCategories) {
if (_categoryEditor.isPopulated(_product)) {
_trackedPopulatedCategories = true;
AnalyticsHelper.trackEvent(
AnalyticsEvent.categoriesNewProductPage,
barcode: barcode,
);
}
}
return _buildEditorButton(
context,
_categoryEditor,
forceIconData: Icons.filter_1,
);
}

List<Widget> _getMiscRows(final BuildContext context) {
final AppLocalizations appLocalizations = AppLocalizations.of(context);
Expand All @@ -402,6 +453,28 @@ class _AddNewProductPageState extends State<AddNewProductPage> {
_buildEditorButton(context, _detailsEditor),
];
}

Widget _buildIngredientsButton(
final BuildContext context, {
final IconData? forceIconData,
final bool disabled = false,
}) {
if (!_trackedPopulatedIngredients) {
if (_ingredientsEditor.isPopulated(_product)) {
_trackedPopulatedIngredients = true;
AnalyticsHelper.trackEvent(
AnalyticsEvent.ingredientsNewProductPage,
barcode: barcode,
);
}
}
return _buildEditorButton(
context,
_ingredientsEditor,
forceIconData: forceIconData,
disabled: disabled,
);
}
}

/// Standard button.
Expand Down