mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-18 11:49:01 +00:00
refactor analytics handling
This commit is contained in:
parent
dbe956b200
commit
03a3417cfc
5 changed files with 81 additions and 75 deletions
|
|
@ -0,0 +1,44 @@
|
|||
package com.habitrpg.android.habitica.helpers;
|
||||
|
||||
import com.amplitude.api.Amplitude;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Created by viirus on 23-Sep-16.
|
||||
*/
|
||||
|
||||
public class AmplitudeManager {
|
||||
|
||||
public static String EVENT_CATEGORY_BEHAVIOUR = "behaviour";
|
||||
public static String EVENT_CATEGORY_NAVIGATION = "navigation";
|
||||
|
||||
public static String EVENT_HITTYPE_EVENT = "event";
|
||||
public static String EVENT_HITTYPE_PAGEVIEW= "pageview";
|
||||
|
||||
public static void sendEvent(String eventAction, String eventCategory, String hitType) {
|
||||
sendEvent(eventAction, eventCategory, hitType, null);
|
||||
}
|
||||
|
||||
public static void sendEvent(String eventAction, String eventCategory, String hitType, Map<String, Object> additionalData) {
|
||||
JSONObject eventProperties = new JSONObject();
|
||||
try {
|
||||
eventProperties.put("eventAction", eventAction);
|
||||
eventProperties.put("eventCategory", eventCategory);
|
||||
eventProperties.put("hitType", hitType);
|
||||
eventProperties.put("status", "displayed");
|
||||
if (additionalData != null) {
|
||||
for (Map.Entry<String, Object> entry : additionalData.entrySet()) {
|
||||
eventProperties.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
} catch (JSONException exception) {
|
||||
}
|
||||
Amplitude.getInstance().logEvent(eventAction, eventProperties);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -27,6 +27,7 @@ import com.habitrpg.android.habitica.BuildConfig;
|
|||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.callbacks.HabitRPGUserCallback;
|
||||
import com.habitrpg.android.habitica.components.AppComponent;
|
||||
import com.habitrpg.android.habitica.helpers.AmplitudeManager;
|
||||
import com.habitrpg.android.habitica.prefs.scanner.IntentIntegrator;
|
||||
import com.habitrpg.android.habitica.prefs.scanner.IntentResult;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
|
||||
|
|
@ -59,6 +60,8 @@ import android.widget.TableRow;
|
|||
import android.widget.TextView;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
|
|
@ -163,15 +166,9 @@ public class LoginActivity extends BaseActivity
|
|||
|
||||
this.isRegistering = true;
|
||||
|
||||
JSONObject eventProperties = new JSONObject();
|
||||
try {
|
||||
eventProperties.put("eventAction", "navigate");
|
||||
eventProperties.put("eventCategory", "navigation");
|
||||
eventProperties.put("hitType", "pageview");
|
||||
eventProperties.put("page", this.getClass().getSimpleName());
|
||||
} catch (JSONException exception) {
|
||||
}
|
||||
Amplitude.getInstance().logEvent("navigate", eventProperties);
|
||||
Map<String, String> additionalData = new HashMap<>();
|
||||
additionalData.put("page", this.getClass().getSimpleName());
|
||||
AmplitudeManager.sendEvent("navigate", AmplitudeManager.EVENT_CATEGORY_NAVIGATION, AmplitudeManager.EVENT_HITTYPE_PAGEVIEW, additionalData);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -407,14 +404,7 @@ public class LoginActivity extends BaseActivity
|
|||
if (this.isRegistering || userAuthResponse.getNewUser()) {
|
||||
this.startSetupActivity();
|
||||
} else {
|
||||
JSONObject eventProperties = new JSONObject();
|
||||
try {
|
||||
eventProperties.put("eventAction", "login");
|
||||
eventProperties.put("eventCategory", "behaviour");
|
||||
eventProperties.put("hitType", "event");
|
||||
} catch (JSONException exception) {
|
||||
}
|
||||
Amplitude.getInstance().logEvent("login", eventProperties);
|
||||
AmplitudeManager.sendEvent("login", AmplitudeManager.EVENT_CATEGORY_BEHAVIOUR, AmplitudeManager.EVENT_HITTYPE_EVENT);
|
||||
this.startMainActivity();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,6 +75,7 @@ import com.habitrpg.android.habitica.events.commands.OpenMenuItemCommand;
|
|||
import com.habitrpg.android.habitica.events.commands.SellItemCommand;
|
||||
import com.habitrpg.android.habitica.events.commands.UnlockPathCommand;
|
||||
import com.habitrpg.android.habitica.events.commands.UpdateUserCommand;
|
||||
import com.habitrpg.android.habitica.helpers.AmplitudeManager;
|
||||
import com.habitrpg.android.habitica.helpers.LanguageHelper;
|
||||
import com.habitrpg.android.habitica.helpers.notifications.PushNotificationManager;
|
||||
import com.habitrpg.android.habitica.ui.AvatarView;
|
||||
|
|
@ -145,6 +146,7 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.TimeZone;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
|
@ -1391,17 +1393,11 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
|
|||
this.overlayFrameLayout.addView(view);
|
||||
this.activeTutorialView = view;
|
||||
|
||||
JSONObject eventProperties = new JSONObject();
|
||||
try {
|
||||
eventProperties.put("eventAction", "tutorial");
|
||||
eventProperties.put("eventCategory", "behaviour");
|
||||
eventProperties.put("hitType", "event");
|
||||
eventProperties.put("eventLabel", step.getIdentifier() + "-android");
|
||||
eventProperties.put("eventValue", step.getIdentifier());
|
||||
eventProperties.put("complete", false);
|
||||
} catch (JSONException exception) {
|
||||
}
|
||||
Amplitude.getInstance().logEvent("tutorial", eventProperties);
|
||||
Map<String, Object> additionalData = new HashMap<>();
|
||||
additionalData.put("eventLabel", step.getIdentifier() + "-android");
|
||||
additionalData.put("eventValue", step.getIdentifier());
|
||||
additionalData.put("complete", false);
|
||||
AmplitudeManager.sendEvent("tutorial", AmplitudeManager.EVENT_CATEGORY_BEHAVIOUR, AmplitudeManager.EVENT_HITTYPE_EVENT, additionalData);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -1416,17 +1412,11 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
|
|||
this.overlayFrameLayout.removeView(this.activeTutorialView);
|
||||
this.removeActiveTutorialView();
|
||||
|
||||
JSONObject eventProperties = new JSONObject();
|
||||
try {
|
||||
eventProperties.put("eventAction", "tutorial");
|
||||
eventProperties.put("eventCategory", "behaviour");
|
||||
eventProperties.put("hitType", "event");
|
||||
eventProperties.put("eventLabel", step.getIdentifier() + "-android");
|
||||
eventProperties.put("eventValue", step.getIdentifier());
|
||||
eventProperties.put("complete", true);
|
||||
} catch (JSONException exception) {
|
||||
}
|
||||
Amplitude.getInstance().logEvent("tutorial", eventProperties);
|
||||
Map<String, Object> additionalData = new HashMap<>();
|
||||
additionalData.put("eventLabel", step.getIdentifier() + "-android");
|
||||
additionalData.put("eventValue", step.getIdentifier());
|
||||
additionalData.put("complete", true);
|
||||
AmplitudeManager.sendEvent("tutorial", AmplitudeManager.EVENT_CATEGORY_BEHAVIOUR, AmplitudeManager.EVENT_HITTYPE_EVENT, additionalData);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import com.habitrpg.android.habitica.callbacks.HabitRPGUserCallback;
|
|||
import com.habitrpg.android.habitica.callbacks.MergeUserCallback;
|
||||
import com.habitrpg.android.habitica.components.AppComponent;
|
||||
import com.habitrpg.android.habitica.events.commands.UpdateUserCommand;
|
||||
import com.habitrpg.android.habitica.helpers.AmplitudeManager;
|
||||
import com.habitrpg.android.habitica.ui.fragments.setup.AvatarSetupFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.setup.TaskSetupFragment;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
|
||||
|
|
@ -31,8 +32,10 @@ import org.json.JSONException;
|
|||
import org.json.JSONObject;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
|
|
@ -72,15 +75,9 @@ public class SetupActivity extends BaseActivity implements View.OnClickListener,
|
|||
this.previousButton.setOnClickListener(this);
|
||||
this.completedSetup = false;
|
||||
|
||||
JSONObject eventProperties = new JSONObject();
|
||||
try {
|
||||
eventProperties.put("eventAction", "setup");
|
||||
eventProperties.put("eventCategory", "behaviour");
|
||||
eventProperties.put("hitType", "event");
|
||||
eventProperties.put("status", "displayed");
|
||||
} catch (JSONException exception) {
|
||||
}
|
||||
Amplitude.getInstance().logEvent("setup", eventProperties);
|
||||
Map<String, String> additionalData = new HashMap<>();
|
||||
additionalData.put("status", "displayed");
|
||||
AmplitudeManager.sendEvent("setup", AmplitudeManager.EVENT_CATEGORY_BEHAVIOUR, AmplitudeManager.EVENT_HITTYPE_EVENT, additionalData);
|
||||
|
||||
String currentDeviceLanguage = Locale.getDefault().getLanguage();
|
||||
for (String language : getResources().getStringArray(R.array.LanguageValues)) {
|
||||
|
|
@ -183,15 +180,9 @@ public class SetupActivity extends BaseActivity implements View.OnClickListener,
|
|||
} else if (v == this.previousButton) {
|
||||
this.pager.setCurrentItem(this.pager.getCurrentItem() - 1);
|
||||
} else if (v == this.skipButton) {
|
||||
JSONObject eventProperties = new JSONObject();
|
||||
try {
|
||||
eventProperties.put("eventAction", "setup");
|
||||
eventProperties.put("eventCategory", "behaviour");
|
||||
eventProperties.put("hitType", "event");
|
||||
eventProperties.put("status", "skipped");
|
||||
} catch (JSONException exception) {
|
||||
}
|
||||
Amplitude.getInstance().logEvent("setup", eventProperties);
|
||||
Map<String, String> additionalData = new HashMap<>();
|
||||
additionalData.put("status", "skipped");
|
||||
AmplitudeManager.sendEvent("setup", AmplitudeManager.EVENT_CATEGORY_BEHAVIOUR, AmplitudeManager.EVENT_HITTYPE_EVENT, additionalData);
|
||||
this.startMainActivity();
|
||||
}
|
||||
}
|
||||
|
|
@ -232,15 +223,9 @@ public class SetupActivity extends BaseActivity implements View.OnClickListener,
|
|||
}
|
||||
}
|
||||
|
||||
JSONObject eventProperties = new JSONObject();
|
||||
try {
|
||||
eventProperties.put("eventAction", "setup");
|
||||
eventProperties.put("eventCategory", "behaviour");
|
||||
eventProperties.put("hitType", "event");
|
||||
eventProperties.put("status", "completed");
|
||||
} catch (JSONException exception) {
|
||||
}
|
||||
Amplitude.getInstance().logEvent("setup", eventProperties);
|
||||
Map<String, String> additionalData = new HashMap<>();
|
||||
additionalData.put("status", "completed");
|
||||
AmplitudeManager.sendEvent("setup", AmplitudeManager.EVENT_CATEGORY_BEHAVIOUR, AmplitudeManager.EVENT_HITTYPE_EVENT, additionalData);
|
||||
}
|
||||
|
||||
private void startMainActivity() {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.habitrpg.android.habitica.ui.fragments;
|
|||
import com.amplitude.api.Amplitude;
|
||||
import com.habitrpg.android.habitica.components.AppComponent;
|
||||
import com.habitrpg.android.habitica.events.DisplayTutorialEvent;
|
||||
import com.habitrpg.android.habitica.helpers.AmplitudeManager;
|
||||
import com.habitrpg.android.habitica.ui.activities.BaseActivity;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.TutorialStep;
|
||||
import com.raizlabs.android.dbflow.runtime.transaction.BaseTransaction;
|
||||
|
|
@ -24,6 +25,8 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.Unbinder;
|
||||
|
|
@ -67,15 +70,9 @@ public abstract class BaseFragment extends DialogFragment {
|
|||
String displayedClassName = this.getDisplayedClassName();
|
||||
|
||||
if (displayedClassName != null) {
|
||||
JSONObject eventProperties = new JSONObject();
|
||||
try {
|
||||
eventProperties.put("eventAction", "navigate");
|
||||
eventProperties.put("eventCategory", "navigation");
|
||||
eventProperties.put("hitType", "pageview");
|
||||
eventProperties.put("page", displayedClassName);
|
||||
} catch (JSONException exception) {
|
||||
}
|
||||
Amplitude.getInstance().logEvent("navigate", eventProperties);
|
||||
Map<String, String> additionalData = new HashMap<>();
|
||||
additionalData.put("page", displayedClassName);
|
||||
AmplitudeManager.sendEvent("navigate", AmplitudeManager.EVENT_CATEGORY_NAVIGATION, AmplitudeManager.EVENT_HITTYPE_PAGEVIEW, additionalData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue