Add fragments to GA

This commit is contained in:
serso 2016-04-06 17:54:25 +02:00
parent 5571ff9c8a
commit 1090ba856f
2 changed files with 20 additions and 9 deletions

View File

@ -1,7 +1,5 @@
package org.solovyev.android.calculator; package org.solovyev.android.calculator;
import static org.solovyev.android.calculator.App.cast;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.SharedPreferences; import android.content.SharedPreferences;
@ -17,13 +15,20 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import android.widget.Button; import android.widget.Button;
import com.google.android.gms.analytics.HitBuilders;
import com.google.android.gms.analytics.Tracker;
import org.solovyev.android.calculator.ga.Ga;
import javax.inject.Inject; import javax.inject.Inject;
import static org.solovyev.android.calculator.App.cast;
public abstract class BaseDialogFragment extends DialogFragment implements View.OnClickListener, DialogInterface.OnClickListener { public abstract class BaseDialogFragment extends DialogFragment implements View.OnClickListener, DialogInterface.OnClickListener {
@Inject @Inject
protected SharedPreferences preferences; protected SharedPreferences preferences;
@Inject
Ga ga;
@Nullable @Nullable
private Button positiveButton; private Button positiveButton;
@Nullable @Nullable
@ -67,6 +72,14 @@ public abstract class BaseDialogFragment extends DialogFragment implements View.
return dialog; return dialog;
} }
@Override
public void onResume() {
super.onResume();
final Tracker tracker = ga.getTracker();
tracker.setScreenName(getClass().getSimpleName());
tracker.send(new HitBuilders.ScreenViewBuilder().build());
}
protected void onShowDialog(@NonNull AlertDialog dialog, boolean firstTime) { protected void onShowDialog(@NonNull AlertDialog dialog, boolean firstTime) {
} }

View File

@ -46,6 +46,11 @@ public final class Ga implements SharedPreferences.OnSharedPreferenceChangeListe
return analytics; return analytics;
} }
@Nonnull
public Tracker getTracker() {
return tracker;
}
public void onButtonPressed(@Nullable String text) { public void onButtonPressed(@Nullable String text) {
if (TextUtils.isEmpty(text)) { if (TextUtils.isEmpty(text)) {
return; return;
@ -72,13 +77,6 @@ public final class Ga implements SharedPreferences.OnSharedPreferenceChangeListe
reportTheme(Preferences.Gui.theme.getPreferenceNoError(preferences)); reportTheme(Preferences.Gui.theme.getPreferenceNoError(preferences));
} }
public void onBootStart() {
final HitBuilders.EventBuilder b = new HitBuilders.EventBuilder();
b.setCategory("lifecycle");
b.setAction("boot");
tracker.send(b.build());
}
public void onFloatingCalculatorOpened() { public void onFloatingCalculatorOpened() {
final HitBuilders.EventBuilder b = new HitBuilders.EventBuilder(); final HitBuilders.EventBuilder b = new HitBuilders.EventBuilder();
b.setCategory("lifecycle"); b.setCategory("lifecycle");