mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-04-14 19:56:32 +00:00
Add amplitude support
This commit is contained in:
parent
d74ad6040e
commit
7832e4e81b
13 changed files with 131 additions and 6 deletions
|
|
@ -2,7 +2,7 @@
|
|||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="com.habitrpg.android.habitica"
|
||||
android:versionCode="34"
|
||||
android:versionCode="35"
|
||||
android:versionName="0.0.26"
|
||||
android:screenOrientation="portrait"
|
||||
android:installLocation="auto" >
|
||||
|
|
|
|||
|
|
@ -88,6 +88,8 @@ dependencies {
|
|||
|
||||
compile 'fr.avianey.com.viewpagerindicator:library:2.4.1@aar'
|
||||
|
||||
compile 'com.amplitude:android-sdk:2.5.0'
|
||||
|
||||
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1'
|
||||
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1'
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import android.app.Activity;
|
|||
import android.content.DialogInterface;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
|
||||
import com.amplitude.api.Amplitude;
|
||||
import com.google.gson.ExclusionStrategy;
|
||||
import com.google.gson.FieldAttributes;
|
||||
import com.google.gson.Gson;
|
||||
|
|
@ -71,6 +72,7 @@ public class APIHelper implements ErrorHandler, Profiler {
|
|||
//private HostConfig mConfig;
|
||||
public APIHelper(final HostConfig cfg) {
|
||||
this.cfg = cfg;
|
||||
Amplitude.getInstance().setUserId(cfg.getUser());
|
||||
|
||||
RequestInterceptor requestInterceptor = new RequestInterceptor() {
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import android.support.annotation.NonNull;
|
|||
import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
|
||||
import com.amplitude.api.Amplitude;
|
||||
import com.crashlytics.android.Crashlytics;
|
||||
import com.crashlytics.android.core.CrashlyticsCore;
|
||||
import com.facebook.FacebookSdk;
|
||||
|
|
@ -60,6 +61,7 @@ public class HabiticaApplication extends Application {
|
|||
setupCrashlytics();
|
||||
createBillingAndCheckout();
|
||||
registerActivityLifecycleCallbacks();
|
||||
Amplitude.getInstance().initialize(this, getString(R.string.amplitude_app_id)).enableForegroundTracking(this);
|
||||
}
|
||||
|
||||
private void setupLeakCanary() {
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import android.widget.ProgressBar;
|
|||
import android.widget.TableRow;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.amplitude.api.Amplitude;
|
||||
import com.facebook.AccessToken;
|
||||
import com.facebook.CallbackManager;
|
||||
import com.facebook.FacebookCallback;
|
||||
|
|
@ -146,6 +147,16 @@ public class LoginActivity extends AppCompatActivity
|
|||
mApiHelper = new APIHelper(hc);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
private void resetLayout() {
|
||||
|
|
@ -333,6 +344,14 @@ public class LoginActivity extends AppCompatActivity
|
|||
if (this.isRegistering) {
|
||||
this.startSetupActivity();
|
||||
} else {
|
||||
JSONObject eventProperties = new JSONObject();
|
||||
try {
|
||||
eventProperties.put("eventAction", "lofin");
|
||||
eventProperties.put("eventCategory", "behaviour");
|
||||
eventProperties.put("hitType", "event");
|
||||
} catch (JSONException exception) {
|
||||
}
|
||||
Amplitude.getInstance().logEvent("login", eventProperties);
|
||||
this.startMainActivity();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import android.widget.ImageView;
|
|||
import android.widget.TextView;
|
||||
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.amplitude.api.Amplitude;
|
||||
import com.habitrpg.android.habitica.APIHelper;
|
||||
import com.habitrpg.android.habitica.HabiticaApplication;
|
||||
import com.habitrpg.android.habitica.HostConfig;
|
||||
|
|
@ -73,6 +74,8 @@ import com.raizlabs.android.dbflow.sql.language.From;
|
|||
import com.raizlabs.android.dbflow.sql.language.Select;
|
||||
import com.raizlabs.android.dbflow.sql.language.Where;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.solovyev.android.checkout.ActivityCheckout;
|
||||
import org.solovyev.android.checkout.Checkout;
|
||||
|
||||
|
|
@ -803,6 +806,18 @@ public class MainActivity extends BaseActivity implements HabitRPGUserCallback.O
|
|||
view.onReaction = this;
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -813,6 +828,18 @@ public class MainActivity extends BaseActivity implements HabitRPGUserCallback.O
|
|||
mAPIHelper.apiService.updateUser(updateData, new HabitRPGUserCallback(this));
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import android.util.AttributeSet;
|
|||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
|
||||
import com.amplitude.api.Amplitude;
|
||||
import com.habitrpg.android.habitica.APIHelper;
|
||||
import com.habitrpg.android.habitica.HabiticaApplication;
|
||||
import com.habitrpg.android.habitica.HostConfig;
|
||||
|
|
@ -23,6 +24,9 @@ import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
|
|||
import com.raizlabs.android.dbflow.sql.builder.Condition;
|
||||
import com.raizlabs.android.dbflow.sql.language.Select;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
|
@ -74,6 +78,16 @@ public class SetupActivity extends BaseActivity implements View.OnClickListener,
|
|||
this.nextButton.setOnClickListener(this);
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -147,6 +161,17 @@ public class SetupActivity extends BaseActivity implements View.OnClickListener,
|
|||
this.pager.setCurrentItem(this.pager.getCurrentItem()+1);
|
||||
} 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);
|
||||
this.startMainActivity();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -185,6 +210,16 @@ public class SetupActivity extends BaseActivity implements View.OnClickListener,
|
|||
this.avatarSetupFragment.setUser(user);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.habitrpg.android.habitica.ui.fragments;
|
|||
|
||||
import android.support.v4.app.Fragment;
|
||||
|
||||
import com.amplitude.api.Amplitude;
|
||||
import com.habitrpg.android.habitica.events.DisplayTutorialEvent;
|
||||
import com.habitrpg.android.habitica.ui.activities.MainActivity;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.TutorialStep;
|
||||
|
|
@ -10,6 +11,9 @@ import com.raizlabs.android.dbflow.runtime.transaction.TransactionListener;
|
|||
import com.raizlabs.android.dbflow.sql.builder.Condition;
|
||||
import com.raizlabs.android.dbflow.sql.language.Select;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
|
@ -23,10 +27,30 @@ public class BaseFragment extends Fragment {
|
|||
public void setUserVisibleHint(boolean isVisibleToUser) {
|
||||
super.setUserVisibleHint(isVisibleToUser);
|
||||
if (isVisibleToUser) {
|
||||
new Select().from(TutorialStep.class).where(Condition.column("identifier").eq(tutorialStepIdentifier)).async().querySingle(tutorialStepTransactionListener);
|
||||
if (this.tutorialStepIdentifier != null) {
|
||||
new Select().from(TutorialStep.class).where(Condition.column("identifier").eq(tutorialStepIdentifier)).async().querySingle(tutorialStepTransactionListener);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getDisplayedClassName() {
|
||||
return this.getClass().getSimpleName();
|
||||
}
|
||||
|
||||
private TransactionListener<TutorialStep> tutorialStepTransactionListener = new TransactionListener<TutorialStep>() {
|
||||
@Override
|
||||
public void onResultReceived(TutorialStep step) {
|
||||
|
|
@ -49,4 +73,6 @@ public class BaseFragment extends Fragment {
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import com.habitrpg.android.habitica.R;
|
|||
import com.habitrpg.android.habitica.ui.activities.SetupActivity;
|
||||
import com.habitrpg.android.habitica.ui.adapter.SkillsRecyclerViewAdapter;
|
||||
import com.habitrpg.android.habitica.ui.adapter.setup.CustomizationSetupAdapter;
|
||||
import com.habitrpg.android.habitica.ui.fragments.BaseFragment;
|
||||
import com.habitrpg.android.habitica.ui.helpers.MarginDecoration;
|
||||
import com.habitrpg.android.habitica.userpicture.UserPicture;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.Customization;
|
||||
|
|
@ -29,7 +30,7 @@ import java.util.List;
|
|||
import butterknife.Bind;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
public class AvatarSetupFragment extends Fragment {
|
||||
public class AvatarSetupFragment extends BaseFragment {
|
||||
|
||||
View view;
|
||||
public SetupActivity activity;
|
||||
|
|
|
|||
|
|
@ -12,12 +12,12 @@ import android.widget.ImageView;
|
|||
import android.widget.TextView;
|
||||
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.ui.fragments.BaseFragment;
|
||||
|
||||
import butterknife.Bind;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
public class IntroFragment extends Fragment {
|
||||
|
||||
public class IntroFragment extends BaseFragment {
|
||||
|
||||
@Bind(R.id.titleTextView)
|
||||
TextView titleTextView;
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import android.view.ViewGroup;
|
|||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.ui.activities.SetupActivity;
|
||||
import com.habitrpg.android.habitica.ui.adapter.setup.TaskSetupAdapter;
|
||||
import com.habitrpg.android.habitica.ui.fragments.BaseFragment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
|
@ -24,7 +25,7 @@ import java.util.Map;
|
|||
import butterknife.Bind;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
public class TaskSetupFragment extends Fragment {
|
||||
public class TaskSetupFragment extends BaseFragment {
|
||||
|
||||
|
||||
View view;
|
||||
|
|
|
|||
|
|
@ -102,4 +102,9 @@ public class TaskRecyclerViewFragment extends BaseFragment implements View.OnCli
|
|||
|
||||
EventBus.getDefault().post(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayedClassName() {
|
||||
return this.classType + super.getDisplayedClassName();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -531,4 +531,9 @@ public class TasksFragment extends BaseMainFragment implements OnCheckedChangeLi
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayedClassName() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue