From c255513902be54d239293f9db41799b1ac7100ea Mon Sep 17 00:00:00 2001 From: Mikolaj Kieres Date: Sun, 11 Jul 2021 12:27:19 +1000 Subject: [PATCH] Adding analytics to the links on the details page --- .../lib/common/analytics.dart | 6 ++- .../board_game_details_page.dart | 6 ++- .../lib/stores/board_game_details_store.dart | 22 +++++++++-- .../lib/stores/board_games_store.dart | 38 +++++++++---------- .../lib/utilities/navigator_helper.dart | 7 +++- 5 files changed, 52 insertions(+), 27 deletions(-) diff --git a/board_games_companion/lib/common/analytics.dart b/board_games_companion/lib/common/analytics.dart index 81de5b5e..5c73d764 100644 --- a/board_games_companion/lib/common/analytics.dart +++ b/board_games_companion/lib/common/analytics.dart @@ -6,6 +6,7 @@ class Analytics { static const String ViewGameDetails = "view_game_details"; static const String ViewHotBoardGame = "view_hot_board_game"; static const String SearchBoardGames = "search_board_games"; + static const String BoardGameDetailsLinks = "board_game_details_links"; static const String BoardGameIdParameter = "board_game_id"; static const String BoardGameNameParameter = "board_game_name"; @@ -16,6 +17,9 @@ class Analytics { static const String FilterByParameter = "filter_by"; static const String FilterByValueParameter = "filter_by_value"; - + static const String SearchBoardGamesPhraseParameter = "phrase"; + + static const String BoardGameDetailsLinksName = + "board_game_details_link_name"; } diff --git a/board_games_companion/lib/pages/board_game_details/board_game_details_page.dart b/board_games_companion/lib/pages/board_game_details/board_game_details_page.dart index 2dc3061f..882bfd1f 100644 --- a/board_games_companion/lib/pages/board_game_details/board_game_details_page.dart +++ b/board_games_companion/lib/pages/board_game_details/board_game_details_page.dart @@ -486,11 +486,13 @@ class _Link extends StatelessWidget { @override Widget build(BuildContext context) { - // var a = Localizations.localeOf(context); return Material( color: Colors.transparent, child: InkWell( - onTap: onPressed, + onTap: () async { + onPressed?.call(); + await boardGameDetailsStore.captureLinkAnalytics(title); + }, child: Padding( padding: const EdgeInsets.all(Dimensions.standardSpacing), child: Column( diff --git a/board_games_companion/lib/stores/board_game_details_store.dart b/board_games_companion/lib/stores/board_game_details_store.dart index efef1161..e26d2a0f 100644 --- a/board_games_companion/lib/stores/board_game_details_store.dart +++ b/board_games_companion/lib/stores/board_game_details_store.dart @@ -1,18 +1,25 @@ -import 'package:board_games_companion/models/hive/board_game_details.dart'; -import 'package:board_games_companion/services/board_games_geek_service.dart'; import 'package:firebase_crashlytics/firebase_crashlytics.dart'; import 'package:flutter/foundation.dart'; +import '../common/analytics.dart'; +import '../models/hive/board_game_details.dart'; +import '../services/board_games_geek_service.dart'; import 'board_games_store.dart'; class BoardGameDetailsStore with ChangeNotifier { final BoardGamesGeekService _boardGameGeekService; final BoardGamesStore _boardGamesStore; + final _analyticsService; BoardGameDetails _boardGameDetails; + BoardGameDetails get boardGameDetails => _boardGameDetails; - BoardGameDetailsStore(this._boardGameGeekService, this._boardGamesStore); + BoardGameDetailsStore( + this._boardGameGeekService, + this._boardGamesStore, + this._analyticsService, + ); Future loadBoardGameDetails(String boardGameId) async { try { @@ -43,4 +50,13 @@ class BoardGameDetailsStore with ChangeNotifier { return _boardGameDetails; } + + Future captureLinkAnalytics(String linkName) async { + await _analyticsService.logEvent( + name: Analytics.BoardGameDetailsLinks, + parameters: { + Analytics.BoardGameDetailsLinksName: linkName, + }, + ); + } } diff --git a/board_games_companion/lib/stores/board_games_store.dart b/board_games_companion/lib/stores/board_games_store.dart index 67f25df1..65464a16 100644 --- a/board_games_companion/lib/stores/board_games_store.dart +++ b/board_games_companion/lib/stores/board_games_store.dart @@ -1,24 +1,24 @@ -import 'package:board_games_companion/common/enums/enums.dart'; -import 'package:board_games_companion/common/enums/order_by.dart'; -import 'package:board_games_companion/common/enums/sort_by_option.dart'; -import 'package:board_games_companion/common/hive_boxes.dart'; -import 'package:board_games_companion/models/collection_sync_result.dart'; -import 'package:board_games_companion/models/hive/board_game_category.dart'; -import 'package:board_games_companion/models/hive/board_game_details.dart'; -import 'package:board_games_companion/models/hive/board_game_expansion.dart'; - -import 'package:board_games_companion/services/board_games_service.dart'; -import 'package:board_games_companion/services/player_service.dart'; -import 'package:board_games_companion/services/playthroughs_service.dart'; -import 'package:board_games_companion/services/score_service.dart'; -import 'package:board_games_companion/stores/board_games_filters_store.dart'; -import 'package:board_games_companion/extensions/date_time_extensions.dart'; -import 'package:board_games_companion/extensions/int_extensions.dart'; -import 'package:board_games_companion/extensions/double_extensions.dart'; -import 'package:board_games_companion/extensions/string_extensions.dart'; import 'package:firebase_crashlytics/firebase_crashlytics.dart'; import 'package:flutter/foundation.dart'; +import '../common/enums/enums.dart'; +import '../common/enums/order_by.dart'; +import '../common/enums/sort_by_option.dart'; +import '../common/hive_boxes.dart'; +import '../extensions/date_time_extensions.dart'; +import '../extensions/double_extensions.dart'; +import '../extensions/int_extensions.dart'; +import '../extensions/string_extensions.dart'; +import '../models/collection_sync_result.dart'; +import '../models/hive/board_game_category.dart'; +import '../models/hive/board_game_details.dart'; +import '../models/hive/board_game_expansion.dart'; +import '../services/board_games_service.dart'; +import '../services/player_service.dart'; +import '../services/playthroughs_service.dart'; +import '../services/score_service.dart'; +import 'board_games_filters_store.dart'; + class BoardGamesStore with ChangeNotifier { final BoardGamesService _boardGamesService; final PlaythroughService _playthroughService; @@ -266,7 +266,7 @@ class BoardGamesStore with ChangeNotifier { ?.toList(); if (selectedSortBy != null) { - filteredBoardGames.sort((a, b) { + filteredBoardGames?.sort((a, b) { if (selectedSortBy.orderBy == OrderBy.Descending) { final buffer = a; a = b; diff --git a/board_games_companion/lib/utilities/navigator_helper.dart b/board_games_companion/lib/utilities/navigator_helper.dart index e53ea2ee..21fa718a 100644 --- a/board_games_companion/lib/utilities/navigator_helper.dart +++ b/board_games_companion/lib/utilities/navigator_helper.dart @@ -64,8 +64,11 @@ class NavigatorHelper { context, listen: false, ); - final _boardGameDetailsStore = - BoardGameDetailsStore(_boardGamesGeekService, _boardGamesStore); + final _boardGameDetailsStore = BoardGameDetailsStore( + _boardGamesGeekService, + _boardGamesStore, + _analytics, + ); return BoardGamesDetailsPage( boardGameId: boardGameId, boardGameName: boardGameName,