Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public static class Param {
public static final String TRIGGER_SOURCE_MENU = "menu";
public static final String TRIGGER_SOURCE_SNACKBAR = "snackbar";
public static final String TRIGGER_SOURCE_AUTO = "auto";
public static final String DURATION = "duration";
public static final String TRIPLES_FOUND = "triples_found";

private Param() {}
;
Expand Down
14 changes: 13 additions & 1 deletion app/src/main/java/com/antsapps/triples/BaseGameActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,17 @@ public void animateFoundTriple(Set<Card> triple, boolean hintUsed) {
}

protected void logTripleFoundEvent(boolean hintUsed) {
List<Long> findTimes = getGame().getTripleFindTimes();
long duration = 0;
if (!findTimes.isEmpty()) {
long lastTime = findTimes.size() > 1 ? findTimes.get(findTimes.size() - 2) : 0;
duration = findTimes.get(findTimes.size() - 1) - lastTime;
}

Bundle bundle = new Bundle();
bundle.putString(AnalyticsConstants.Param.GAME_TYPE, getGame().getGameTypeForAnalytics());
bundle.putBoolean(AnalyticsConstants.Param.HINT_USED, hintUsed);
bundle.putLong(AnalyticsConstants.Param.DURATION, duration);
mFirebaseAnalytics.logEvent(AnalyticsConstants.Event.FIND_TRIPLE, bundle);
}

Expand Down Expand Up @@ -354,7 +362,11 @@ public void onUpdateGameState(GameState state) {
public void gameFinished() {
Log.i("BaseGameActivity", "game finished");
updateViewSwitcher();
logGameEvent(AnalyticsConstants.Event.FINISH_GAME);
Bundle bundle = new Bundle();
bundle.putString(AnalyticsConstants.Param.GAME_TYPE, getGame().getGameTypeForAnalytics());
bundle.putLong(AnalyticsConstants.Param.DURATION, getGame().getTimeElapsed());
bundle.putLong(AnalyticsConstants.Param.TRIPLES_FOUND, getGame().getNumTriplesFound());
mFirebaseAnalytics.logEvent(AnalyticsConstants.Event.FINISH_GAME, bundle);
if (isSignedIn()) {
submitScore();
if (!getGame().areHintsUsed()) {
Expand Down
16 changes: 16 additions & 0 deletions app/src/test/java/com/antsapps/triples/GameEndFlowTest.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.antsapps.triples;

import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ViewAnimator;
import androidx.test.core.app.ActivityScenario;
Expand Down Expand Up @@ -89,6 +93,18 @@ public void testClassicGameEndFlow_unshuffledDeck() {

View statsButton = activity.findViewById(R.id.statistics_button);
assertThat(statsButton.getVisibility()).isEqualTo(View.VISIBLE);

// Verify finish game analytics
org.mockito.ArgumentCaptor<Bundle> bundleCaptor =
org.mockito.ArgumentCaptor.forClass(Bundle.class);
verify(mockFirebaseAnalytics, atLeastOnce())
.logEvent(eq(AnalyticsConstants.Event.FINISH_GAME), bundleCaptor.capture());

Bundle capturedBundle = bundleCaptor.getValue();
assertThat(capturedBundle.getString(AnalyticsConstants.Param.GAME_TYPE))
.isEqualTo(ClassicGame.GAME_TYPE_FOR_ANALYTICS);
assertThat(capturedBundle.containsKey(AnalyticsConstants.Param.DURATION)).isTrue();
assertThat(capturedBundle.containsKey(AnalyticsConstants.Param.TRIPLES_FOUND)).isTrue();
});
}
}
Expand Down
1 change: 1 addition & 0 deletions app/src/test/java/com/antsapps/triples/GameFlowTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public void testClassicGameFlow() {
assertThat(capturedBundle.getString(AnalyticsConstants.Param.GAME_TYPE))
.isEqualTo(ClassicGame.GAME_TYPE_FOR_ANALYTICS);
assertThat(capturedBundle.getBoolean(AnalyticsConstants.Param.HINT_USED)).isFalse();
assertThat(capturedBundle.containsKey(AnalyticsConstants.Param.DURATION)).isTrue();

// Verify remaining count decreased
TextView remainingText = activity.findViewById(R.id.cards_remaining_text);
Expand Down
Loading