Skip to content

Commit

Permalink
Track custom build event
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolfteam committed Jan 24, 2022
1 parent 843bd5f commit f7576d9
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 48 deletions.
6 changes: 5 additions & 1 deletion lib/application/custom_build/custom_build_bloc.dart
Expand Up @@ -7,6 +7,7 @@ import 'package:shiori/domain/extensions/string_extensions.dart';
import 'package:shiori/domain/models/models.dart';
import 'package:shiori/domain/services/data_service.dart';
import 'package:shiori/domain/services/genshin_service.dart';
import 'package:shiori/domain/services/telemetry_service.dart';

part 'custom_build_bloc.freezed.dart';
part 'custom_build_event.dart';
Expand All @@ -15,6 +16,7 @@ part 'custom_build_state.dart';
class CustomBuildBloc extends Bloc<CustomBuildEvent, CustomBuildState> {
final GenshinService _genshinService;
final DataService _dataService;
final TelemetryService _telemetryService;
final CustomBuildsBloc _customBuildsBloc;

static int maxTitleLength = 40;
Expand All @@ -29,7 +31,7 @@ class CustomBuildBloc extends Bloc<CustomBuildEvent, CustomBuildState> {
static int maxNumberOfWeapons = 10;
static int maxNumberOfTeamCharacters = 10;

CustomBuildBloc(this._genshinService, this._dataService, this._customBuildsBloc) : super(const CustomBuildState.loading());
CustomBuildBloc(this._genshinService, this._dataService, this._telemetryService, this._customBuildsBloc) : super(const CustomBuildState.loading());

@override
Stream<CustomBuildState> mapEventToState(CustomBuildEvent event) async* {
Expand Down Expand Up @@ -456,6 +458,7 @@ class CustomBuildBloc extends Bloc<CustomBuildEvent, CustomBuildState> {
state.skillPriorities,
);

await _telemetryService.trackCustomBuildSaved(state.character.key, state.type, state.subType);
_customBuildsBloc.add(const CustomBuildsEvent.load());
return _init(state.key, state.title);
}
Expand All @@ -473,6 +476,7 @@ class CustomBuildBloc extends Bloc<CustomBuildEvent, CustomBuildState> {
state.skillPriorities,
);

await _telemetryService.trackCustomBuildSaved(state.character.key, state.type, state.subType);
_customBuildsBloc.add(const CustomBuildsEvent.load());
return _init(build.key, state.title);
}
Expand Down
2 changes: 2 additions & 0 deletions lib/domain/services/telemetry_service.dart
Expand Up @@ -53,4 +53,6 @@ abstract class TelemetryService {
Future<void> trackNotificationRestarted(AppNotificationType type);

Future<void> trackNotificationStopped(AppNotificationType type);

Future<void> trackCustomBuildSaved(String charKey, CharacterRoleType roleType, CharacterRoleSubType subType);
}
10 changes: 10 additions & 0 deletions lib/infrastructure/telemetry/telemetry_service.dart
Expand Up @@ -140,4 +140,14 @@ class TelemetryServiceImpl implements TelemetryService {
@override
Future<void> trackNotificationUpdated(AppNotificationType type) =>
trackEventAsync('Notification-Updated', {'Type': EnumToString.convertToString(type)});

@override
Future<void> trackCustomBuildSaved(String charKey, CharacterRoleType roleType, CharacterRoleSubType subType) => trackEventAsync(
'Custom-Build-Saved',
{
'CharKey': charKey,
'RoleType': EnumToString.convertToString(roleType),
'SubType': EnumToString.convertToString(subType),
},
);
}
3 changes: 2 additions & 1 deletion lib/injection.dart
Expand Up @@ -175,7 +175,8 @@ class Injection {
static CustomBuildBloc getCustomBuildBloc(CustomBuildsBloc bloc) {
final genshinService = getIt<GenshinService>();
final dataService = getIt<DataService>();
return CustomBuildBloc(genshinService, dataService, bloc);
final telemetryService = getIt<TelemetryService>();
return CustomBuildBloc(genshinService, dataService, telemetryService, bloc);
}

static Future<void> init() async {
Expand Down

0 comments on commit f7576d9

Please sign in to comment.