analytics

This commit is contained in:
danijoo
2016-01-09 02:31:48 +01:00
parent cd3bc60759
commit 2db65c947a
16 changed files with 176 additions and 3 deletions

View File

@@ -53,4 +53,6 @@ dependencies {
compile('com.mikepenz:aboutlibraries:5.3.6@aar') {
transitive = true
}
compile 'com.google.android.gms:play-services-analytics:8.4.0'
}

45
app/google-services.json Normal file
View File

@@ -0,0 +1,45 @@
{
"project_info": {
"project_id": "notificationlogger",
"project_number": "592676030769",
"name": "notificationlogger"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:592676030769:android:01536270f9b0bf2a",
"client_id": "android:net.headlezz.notificationlogger",
"client_type": 1,
"android_client_info": {
"package_name": "net.headlezz.notificationlogger"
}
},
"oauth_client": [],
"api_key": [],
"services": {
"analytics_service": {
"status": 2,
"analytics_property": {
"tracking_id": "UA-39570140-8"
}
},
"cloud_messaging_service": {
"status": 1,
"apns_config": []
},
"appinvite_service": {
"status": 1,
"other_platform_oauth_client": []
},
"google_signin_service": {
"status": 1
},
"ads_service": {
"status": 1
}
}
}
],
"client_info": [],
"ARTIFACT_VERSION": "1"
}

View File

@@ -2,6 +2,8 @@
package="net.headlezz.notificationlogger">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:name=".Application"

View File

@@ -0,0 +1,36 @@
package net.headlezz.notificationlogger;
import android.support.v4.app.Fragment;
import com.google.android.gms.analytics.HitBuilders;
import com.google.android.gms.analytics.Tracker;
public class Analytics {
public static final String ACTION_APP_INFO_OPENED = "App Info opened";
public static final String ACTION_NOTIFICATION_DETAILS_SHOWN = "Notification details shown";
public static final String ACTION_CUSTOM_NOTIFICATION_DISPATCHED = "Notification dispatched";
public static final String ACTION_CUSTOM_NOTIFICATION_SCHEDULED= "Notification scheduled";
public static final String ACTION_ABOUT= "About opened";
public static final String ACTION_DATABASE_CLEARED= "database cleared";
public static final String ACTION_EXPORTED = "Notifications exported";
private static Tracker getTracker() {
return Application.singleton.getDefaultTracker();
}
public static void trackFragment(Fragment frag) {
Tracker tracker = getTracker();
tracker.setScreenName(frag.getClass().getSimpleName());
tracker.send(new HitBuilders.ScreenViewBuilder().build());
}
public static void trackEvent(String action) {
Tracker tracker = getTracker();
tracker.send(new HitBuilders.EventBuilder()
.setCategory("Action")
.setAction(action)
.build());
}
}

View File

@@ -1,12 +1,35 @@
package net.headlezz.notificationlogger;
import com.google.android.gms.analytics.GoogleAnalytics;
import com.google.android.gms.analytics.Tracker;
import timber.log.Timber;
public class Application extends android.app.Application {
public static Application singleton;
private Tracker mTracker;
@Override
public void onCreate() {
super.onCreate();
singleton = this;
Timber.plant(new Timber.DebugTree());
}
/**
* Gets the default {@link Tracker} for this {@link Application}.
* @return tracker
*/
synchronized public Tracker getDefaultTracker() {
if (mTracker == null) {
GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
if(BuildConfig.DEBUG)
analytics.setDryRun(true);
// To enable debug logging use: adb shell setprop log.tag.GAv4 DEBUG
mTracker = analytics.newTracker(R.xml.global_tracker);
}
return mTracker;
}
}

View File

@@ -13,6 +13,9 @@ import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import com.google.android.gms.analytics.HitBuilders;
import com.google.android.gms.analytics.Tracker;
import net.headlezz.notificationlogger.createnotification.NotificationCreationFragment;
import net.headlezz.notificationlogger.logger.LoggerUtils;
import net.headlezz.notificationlogger.notificationlist.NotificationListFragment;
@@ -38,6 +41,7 @@ public class MainActivity extends AppCompatActivity implements SharedPreferences
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
ButterKnife.bind(this);
setSupportActionBar(mToolbar);

View File

@@ -2,6 +2,7 @@ package net.headlezz.notificationlogger;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.text.Html;
import android.text.Spanned;
@@ -48,4 +49,10 @@ public class NotificationInfoDialog extends AlertDialog implements DialogInterfa
Toast.makeText(getContext(), R.string.notification_info_dialog_app_info_error, Toast.LENGTH_LONG).show();
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Analytics.trackEvent(Analytics.ACTION_NOTIFICATION_DETAILS_SHOWN);
}
}

View File

@@ -63,6 +63,7 @@ public class PackageUtils {
intent.setData(Uri.fromParts("package", packageName, null));
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
context.startActivity(intent);
Analytics.trackEvent(Analytics.ACTION_APP_INFO_OPENED);
return true;
} catch ( ActivityNotFoundException e ) {
Timber.e("Failed to open app info", e);

View File

@@ -14,6 +14,7 @@ import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Spinner;
import net.headlezz.notificationlogger.Analytics;
import net.headlezz.notificationlogger.R;
import java.util.Date;
@@ -109,6 +110,12 @@ public class NotificationCreationFragment extends Fragment implements View.OnCli
return view;
}
@Override
public void onResume() {
super.onResume();
Analytics.trackFragment(this);
}
@Override
public void onClick(View v) {
@@ -147,9 +154,10 @@ public class NotificationCreationFragment extends Fragment implements View.OnCli
.setCategory(categories[spCategory.getSelectedItemPosition()])
.build();
if(v.getId() == R.id.create_btDispatch)
if(v.getId() == R.id.create_btDispatch) {
dn.dispatch();
else
Analytics.trackEvent(Analytics.ACTION_CUSTOM_NOTIFICATION_DISPATCHED);
} else
sheduleNotification(dn);
}
@@ -190,8 +198,10 @@ public class NotificationCreationFragment extends Fragment implements View.OnCli
@Override
public void onDismissed(Snackbar snackbar, int event) {
super.onDismissed(snackbar, event);
if(dispatch)
if(dispatch) {
mNotification.shedule(mDispatchDate);
Analytics.trackEvent(Analytics.ACTION_CUSTOM_NOTIFICATION_SCHEDULED);
}
}
}
}

View File

@@ -17,6 +17,7 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import net.headlezz.notificationlogger.Analytics;
import net.headlezz.notificationlogger.DatabaseUtils;
import net.headlezz.notificationlogger.NotificationInfoDialog;
import net.headlezz.notificationlogger.R;
@@ -67,6 +68,12 @@ public class NotificationListFragment extends Fragment implements NotificationLi
mLoaderManager.loadNotificationsUnfiltered();
}
@Override
public void onResume() {
super.onResume();
Analytics.trackFragment(this);
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);

View File

@@ -19,6 +19,7 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import net.headlezz.notificationlogger.Analytics;
import net.headlezz.notificationlogger.DatabaseUtils;
import net.headlezz.notificationlogger.PackageUtils;
import net.headlezz.notificationlogger.R;
@@ -67,6 +68,12 @@ public class BlacklistFragment extends Fragment implements LoaderManager.LoaderC
getLoaderManager().initLoader(LOADER_ID, Bundle.EMPTY, this);
}
@Override
public void onResume() {
super.onResume();
Analytics.trackFragment(this);
}
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
Timber.d("blacklistloader created");

View File

@@ -10,6 +10,7 @@ import android.support.v7.widget.Toolbar;
import com.mikepenz.aboutlibraries.LibsBuilder;
import com.mikepenz.aboutlibraries.ui.LibsSupportFragment;
import net.headlezz.notificationlogger.Analytics;
import net.headlezz.notificationlogger.R;
import butterknife.Bind;
@@ -46,6 +47,8 @@ public class PreferenceActivity extends AppCompatActivity implements PreferenceF
.replace(R.id.fragment_holder, aboutFrag)
.addToBackStack("about")
.commit();
Analytics.trackEvent(Analytics.ACTION_ABOUT);
}
@Override

View File

@@ -27,6 +27,7 @@ import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import net.headlezz.notificationlogger.Analytics;
import net.headlezz.notificationlogger.DatabaseUtils;
import net.headlezz.notificationlogger.R;
import net.headlezz.notificationlogger.logger.LoggedNotification;
@@ -64,6 +65,12 @@ public class PreferenceFragment extends PreferenceFragmentCompat implements Pref
setBlacklistItemCount();
}
@Override
public void onResume() {
super.onResume();
Analytics.trackFragment(this);
}
private void setBlacklistItemCount() {
new AsyncTask<Void, Void, Integer>() {
@@ -188,6 +195,7 @@ public class PreferenceFragment extends PreferenceFragmentCompat implements Pref
snack.show();
}
}
Analytics.trackEvent(Analytics.ACTION_EXPORTED);
}
}.execute();
}
@@ -212,6 +220,7 @@ public class PreferenceFragment extends PreferenceFragmentCompat implements Pref
@Override
public void onClick(DialogInterface dialog, int which) {
clearDatabase();
Analytics.trackEvent(Analytics.ACTION_DATABASE_CLEARED);
}
})
.create().show();

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="analytics_tracking_id">UA-39570140-8</string>
</resources>

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<string name="ga_trackingId">@string/analytics_tracking_id</string>
<string name="ga_sampleFrequency">100.0</string>
<integer name="ga_sessionTimeout">1800</integer>
<bool name="ga_autoActivityTracking">true</bool>
<bool name="ga_anonymizeIp">false</bool>
<bool name="ga_reportUncaughtExceptions">true</bool>
<screenName name="net.headlezz.notificationlogger.MainActivity">Home Screen</screenName>
<screenName name="net.headlezz.notificationlogger.preferences.PreferenceActivity">Preference Screen</screenName>
</resources>

View File

@@ -14,6 +14,7 @@ buildscript {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.6'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:1.5.0-beta2'
}
}