Skip to content

Commit

Permalink
Adding analytics to the links on the details page
Browse files Browse the repository at this point in the history
  • Loading branch information
mkieres committed Jul 11, 2021
1 parent be15e04 commit c255513
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 27 deletions.
6 changes: 5 additions & 1 deletion board_games_companion/lib/common/analytics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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";
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
22 changes: 19 additions & 3 deletions board_games_companion/lib/stores/board_game_details_store.dart
Original file line number Diff line number Diff line change
@@ -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<BoardGameDetails> loadBoardGameDetails(String boardGameId) async {
try {
Expand Down Expand Up @@ -43,4 +50,13 @@ class BoardGameDetailsStore with ChangeNotifier {

return _boardGameDetails;
}

Future<void> captureLinkAnalytics(String linkName) async {
await _analyticsService.logEvent(
name: Analytics.BoardGameDetailsLinks,
parameters: {
Analytics.BoardGameDetailsLinksName: linkName,
},
);
}
}
38 changes: 19 additions & 19 deletions board_games_companion/lib/stores/board_games_store.dart
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions board_games_companion/lib/utilities/navigator_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit c255513

Please sign in to comment.