6177214e-ce7c-49e3-99de-ff9721b26f63 — Commit 32943dd2
Changed files
comwell_key_app/lib/main.dart | 2 +- .../pregistration/bloc/preregistration_cubit.dart | 54 +++++++++- comwell_key_app/lib/routing/app_router.dart | 2 +- comwell_key_app/lib/tracking/FirebaseTracking.dart | 116 +++++++++++++++++++++ comwell_key_app/lib/utils/locator.dart | 2 + 5 files changed, 169 insertions(+), 7 deletions(-)
Diff
diff --git a/comwell_key_app/lib/main.dart b/comwell_key_app/lib/main.dart
index 16bba56b..5eedebdf 100644
--- a/comwell_key_app/lib/main.dart
+++ b/comwell_key_app/lib/main.dart
@@ -14,7 +14,7 @@ void runMainApp(FirebaseOptions firebaseOptions) async {
WidgetsFlutterBinding.ensureInitialized();
await EasyLocalization.ensureInitialized();
await dotenv.load(fileName: ".env");
- await configureFirebase;
+ await configureFirebase();
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
setupLocator();
runApp(EasyLocalization(
diff --git a/comwell_key_app/lib/pregistration/bloc/preregistration_cubit.dart b/comwell_key_app/lib/pregistration/bloc/preregistration_cubit.dart
index 4f80baf7..abc2d337 100644
--- a/comwell_key_app/lib/pregistration/bloc/preregistration_cubit.dart
+++ b/comwell_key_app/lib/pregistration/bloc/preregistration_cubit.dart
@@ -4,6 +4,7 @@ import 'package:comwell_key_app/pregistration/bloc/preregistration_state.dart';
import 'package:comwell_key_app/pregistration/pregistration_repository.dart';
import 'package:comwell_key_app/pregistration/preregistration_flow.dart';
import 'package:comwell_key_app/services/adyen/stored_payment_method.dart';
+import 'package:comwell_key_app/tracking/FirebaseTracking.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/cupertino.dart';
@@ -13,6 +14,7 @@ import '../../utils/locator.dart';
class PreregistrationCubit extends Cubit<PreregistrationState> {
final _profileSettingsRepository = locator<ProfileSettingsRepository>();
final _preregistrationRepository = locator<PreregistrationRepository>();
+ final _tracking = locator<FirebaseTracking>();
final pageController = PageController();
final addressTextController = TextEditingController();
@@ -24,7 +26,9 @@ class PreregistrationCubit extends Cubit<PreregistrationState> {
PreregistrationPage.fromIndex(pageController.page?.toInt() ?? 0);
bool _isAnimating = false;
- PreregistrationCubit() : super(const PreregistrationState(loading: false));
+ PreregistrationCubit() : super(const PreregistrationState(loading: false)) {
+ _tracking.trackScreenViewPrereg();
+ }
void init() async {
emit(state.copyWith(loading: true, error: null));
@@ -73,11 +77,47 @@ class PreregistrationCubit extends Cubit<PreregistrationState> {
}
}
+ void addToCart() {
+ _tracking.trackAddToCart(
+ currency: "DKK",
+ hotelName: "COMWELL",
+ itemId: "ITEM_ID",
+ itemName: "ITEM_NAME",
+ items: ["ITEM_NAME"],
+ placement: "pre-registration",
+ price: 500,
+ quantity: 5,
+ value: 5000);
+ }
+
+ void removeToCard() {
+ _tracking.trackRemoveFromCard(
+ currency: "DKK",
+ hotelName: "COMWELL",
+ itemId: "ITEM_ID",
+ itemName: "ITEM_NAME",
+ items: ["ITEM_NAME"],
+ placement: "pre-registration",
+ price: 500,
+ quantity: 5,
+ value: 5000);
+ }
+
void onPaymentMethodsContinueClicked() {
_navigateNextPage();
}
void _onConfirmPressed() async {
+ _tracking.trackBeginCheckout(
+ currency: "DKK",
+ hotelName: "COMWELL",
+ itemId: "ITEM_ID",
+ itemName: "ITEM_NAME",
+ items: ["ITEM_NAME"],
+ placement: "pre-registration",
+ price: 500,
+ quantity: 5,
+ value: 5000);
emit(state.copyWith(loading: true));
Future.delayed(const Duration(seconds: 3), () {
emit(state.copyWith(loading: false));
@@ -104,12 +144,14 @@ class PreregistrationCubit extends Cubit<PreregistrationState> {
emit(state.copyWith(selectedPaymentMethod: paymentMethod));
}
- void onBackClicked() {
- if (_isAnimating) return;
+ bool onBackClicked() {
+ if (_isAnimating) return true;
final hasPage = pageController.page != null;
if (hasPage && pageController.page! >= 1.0) {
_navigatePreviousPage();
+ return true;
}
+ return false;
}
void _navigateTo(PreregistrationPage page) async {
@@ -222,8 +264,10 @@ class PreregistrationCubit extends Cubit<PreregistrationState> {
void fetchPaymentMethods() async {
emit(state.copyWith(loading: true, error: null));
try {
- final paymentMethods = await _preregistrationRepository.getPaymentMethods();
- emit(state.copyWith(loading: false, storedPaymentMethods: paymentMethods));
+ final paymentMethods =
+ await _preregistrationRepository.getPaymentMethods();
+ emit(
+ state.copyWith(loading: false, storedPaymentMethods: paymentMethods));
} on Exception catch (e) {
emit(state.copyWith(error: e));
}
diff --git a/comwell_key_app/lib/routing/app_router.dart b/comwell_key_app/lib/routing/app_router.dart
index 6ce7c4d0..31f11afa 100644
--- a/comwell_key_app/lib/routing/app_router.dart
+++ b/comwell_key_app/lib/routing/app_router.dart
@@ -139,7 +139,7 @@ GoRouter goRouter(AuthenticationBloc authBloc) {
name: AppRoutes.preregistration.name,
builder: (context,
state) {
- return PreregistrationFlow();
+ return const PreregistrationFlow();
}),
/* GoRoute(
diff --git a/comwell_key_app/lib/tracking/FirebaseTracking.dart b/comwell_key_app/lib/tracking/FirebaseTracking.dart
new file mode 100644
index 00000000..38df1350
--- /dev/null
+++ b/comwell_key_app/lib/tracking/FirebaseTracking.dart
@@ -0,0 +1,116 @@
+import 'dart:ffi';
+
+import 'package:firebase_analytics/firebase_analytics.dart';
+import 'package:flutter/foundation.dart';
+
+class FirebaseTracking {
+ final _tracking = FirebaseAnalytics.instance;
+
+ void trackScreenViewPrereg() {
+ _track(_eventScreenView, {
+ _paramScreenClass: "prereg",
+ _paramScreenName: "prereg",
+ });
+ }
+
+ void trackAddToCart({
+ required String currency,
+ required num value,
+ required String placement,
+ required Iterable<String> items,
+ required String itemId,
+ required String itemName,
+ required num price,
+ required num quantity,
+ required String hotelName,
+ }) {
+ _track(_eventAddToCart, {
+ _paramCurrency: currency, // Currency of the items associated with the event, in 3-letter ISO 4217 format.
+ _paramValue: value, // The monetary value of the event. Set value to the sum of (price * quantity) for all items in items. Don't include shipping or tax.
+ _paramPlacement: placement, // The items for the event.
+ _paramItems: items, // Where in the app flow this event happened
+ _paramItemId: itemId, // The ID of the item. One of item_id or item_name is required.
+ _paramItemName: itemName, // The name of the item. One of item_id or item_name is required.
+ _paramPrice: price, // The monetary unit price of the item, in units of the specified currency parameter.
+ _paramQuantity: quantity, // Item quantity. If not set, quantity is set to 1.
+ _paramHotelName: hotelName // The hotel name associated with the event.
+ });
+ }
+
+ void trackRemoveFromCard({
+ required String currency,
+ required num value,
+ required String placement,
+ required Iterable<String> items,
+ required String itemId,
+ required String itemName,
+ required num price,
+ required num quantity,
+ required String hotelName,
+ }) {
+ _track(_eventRemoveFromCart, {
+ _paramCurrency: currency, // Currency of the items associated with the event, in 3-letter ISO 4217 format.
+ _paramValue: value, // The monetary value of the event. Set value to the sum of (price * quantity) for all items in items. Don't include shipping or tax.
+ _paramPlacement: placement, // The items for the event.
+ _paramItems: items, // Where in the app flow this event happened
+ _paramItemId: itemId, // The ID of the item. One of item_id or item_name is required.
+ _paramItemName: itemName, // The name of the item. One of item_id or item_name is required.
+ _paramPrice: price, // The monetary unit price of the item, in units of the specified currency parameter.
+ _paramQuantity: quantity, // Item quantity. If not set, quantity is set to 1.
+ _paramHotelName: hotelName // The hotel name associated with the event.
+ });
+ }
+
+ void trackBeginCheckout({
+ required String currency,
+ required num value,
+ required String placement,
+ required Iterable<String> items,
+ required String itemId,
+ required String itemName,
+ required num price,
+ required num quantity,
+ required String hotelName,
+ }) {
+ _track(_eventBeginCheckout, {
+ _paramCurrency: currency, // Currency of the items associated with the event, in 3-letter ISO 4217 format.
+ _paramValue: value, // The monetary value of the event. Set value to the sum of (price * quantity) for all items in items. Don't include shipping or tax.
+ _paramPlacement: placement, // The items for the event.
+ _paramItems: items, // Where in the app flow this event happened
+ _paramItemId: itemId, // The ID of the item. One of item_id or item_name is required.
+ _paramItemName: itemName, // The name of the item. One of item_id or item_name is required.
+ _paramPrice: price, // The monetary unit price of the item, in units of the specified currency parameter.
+ _paramQuantity: quantity, // Item quantity. If not set, quantity is set to 1.
+ _paramHotelName: hotelName // The hotel name associated with the event.
+ });
+ }
+
+ void _track(String name, Map<String, Object>? parameters) async {
+ try {
+ await _tracking.logEvent(name: name, parameters: parameters);
+ } catch (e) {
+ if (kDebugMode) {
+ debugPrint("qqq tracking error error=$e");
+ }
+ }
+ }
+
+ // event names
+ static const _eventScreenView = "screen_view";
+ static const _eventAddToCart = "add_to_cart";
+ static const _eventRemoveFromCart = "remove_from_cart";
+ static const _eventBeginCheckout = "begin_checkout";
+
+ // props
+ static const _paramScreenClass = "screen_class";
+ static const _paramScreenName = "screen_name";
+ static const _paramHotelName = "hotel_name";
+ static const _paramCurrency = "currency";
+ static const _paramValue = "value";
+ static const _paramPlacement = "placement";
+ static const _paramItems = "items";
+ static const _paramItemId = "itemId";
+ static const _paramItemName = "itemName";
+ static const _paramPrice = "price";
+ static const _paramQuantity = "quantity";
+}
diff --git a/comwell_key_app/lib/utils/locator.dart b/comwell_key_app/lib/utils/locator.dart
index b43caf86..0e6e6adf 100644
--- a/comwell_key_app/lib/utils/locator.dart
+++ b/comwell_key_app/lib/utils/locator.dart
@@ -5,6 +5,7 @@ import 'package:comwell_key_app/overview/repository/overview_repository.dart';
import 'package:comwell_key_app/pregistration/pregistration_repository.dart';
import 'package:comwell_key_app/profile/profile_repository.dart';
import 'package:comwell_key_app/profile_settings/repostiory/profile_settings_repository.dart';
+import 'package:comwell_key_app/tracking/FirebaseTracking.dart';
import 'package:device_info_plus/device_info_plus.dart';
import 'package:flutter/foundation.dart';
import 'package:get_it/get_it.dart';
@@ -28,5 +29,6 @@ void setupLocator() {
locator.registerFactory<ProfileRepository>(() => ProfileRepository());
locator.registerFactory<PreregistrationRepository>(
() => PreregistrationRepository());
+ locator.registerSingleton<FirebaseTracking>(FirebaseTracking());
}
}