Skip to content
Permalink
Browse files

Reinstating Firebase Analytics functionality.

Revert "[Mobile] Removed analytics code."

This reverts commit eb9c15e.
  • Loading branch information...
thecosmicfrog committed Nov 22, 2018
1 parent 960ce5c commit 11442f5fee2a6f34da15df6f109a8d5db92b816a
@@ -30,6 +30,7 @@
import android.widget.TextView;

import org.thecosmicfrog.luasataglance.R;
import org.thecosmicfrog.luasataglance.util.Analytics;

public class AboutActivity extends FragmentActivity {

@@ -52,6 +53,16 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_about);

TextView textViewSourceCode = (TextView) findViewById(R.id.textview_sourcecode);
textViewSourceCode.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Analytics.selectContent(
getApplicationContext(),
"link_tapped",
"sourcecode_tapped"
);
}
});

TextView textViewLicense = (TextView) findViewById(R.id.textview_license);
textViewLicense.setOnClickListener(new View.OnClickListener() {
@@ -63,6 +74,12 @@ public void onClick(View v) {
LicenseActivity.class
)
);

Analytics.selectContent(
getApplicationContext(),
"link_tapped",
"license_tapped"
);
}
});
}
@@ -48,6 +48,7 @@
import org.thecosmicfrog.luasataglance.object.NotifyTimesMap;
import org.thecosmicfrog.luasataglance.object.StopForecast;
import org.thecosmicfrog.luasataglance.object.StopNameIdMap;
import org.thecosmicfrog.luasataglance.util.Analytics;
import org.thecosmicfrog.luasataglance.util.Constant;
import org.thecosmicfrog.luasataglance.util.Preferences;
import org.thecosmicfrog.luasataglance.util.Settings;
@@ -815,6 +816,12 @@ public void success(ApiTimes apiTimes, Response response) {
/* Stop the refresh animations. */
setIsLoading(false);
swipeRefreshLayout.setRefreshing(false);
} else {
Analytics.nullApitimes(
getContext(),
"null",
"null_apitimes_mobile"
);
}
}
}
@@ -858,6 +865,12 @@ public void failure(RetrofitError retrofitError) {
if (retrofitError.getKind() != null) {
Log.e(LOG_TAG, "Kind: " + retrofitError.getKind().toString());
}

Analytics.httpError(
getContext(),
"http_error",
"http_error_general_mobile"
);
}
};

@@ -38,6 +38,7 @@
import android.widget.TextView;

import org.thecosmicfrog.luasataglance.R;
import org.thecosmicfrog.luasataglance.util.Analytics;
import org.thecosmicfrog.luasataglance.util.Constant;
import org.thecosmicfrog.luasataglance.util.Preferences;
import org.thecosmicfrog.luasataglance.view.TutorialCardView;
@@ -163,6 +164,12 @@ public void onClick(View v) {
)
);
}

Analytics.selectContent(
getApplicationContext(),
"button_tapped",
"map_tapped"
);
}
});
}
@@ -189,6 +196,12 @@ public void onClick(View v) {
FavouritesActivity.class
)
);

Analytics.selectContent(
getApplicationContext(),
"button_tapped",
"favourites_tapped"
);
}
});
}
@@ -209,6 +222,12 @@ public void onClick(View v) {
FaresActivity.class
)
);

Analytics.selectContent(
getApplicationContext(),
"button_tapped",
"fares_tapped"
);
}
});
}
@@ -228,6 +247,12 @@ public void onClick(View v) {
NewsActivity.class
).putExtra(Constant.NEWS_TYPE, Constant.NEWS_TYPE_TRAVEL_UPDATES)
);

Analytics.selectContent(
getApplicationContext(),
"button_tapped",
"alerts_tapped"
);
}
});
}
@@ -37,6 +37,7 @@
import org.thecosmicfrog.luasataglance.R;
import org.thecosmicfrog.luasataglance.object.NotifyTimesMap;
import org.thecosmicfrog.luasataglance.receiver.NotifyTimesReceiver;
import org.thecosmicfrog.luasataglance.util.Analytics;
import org.thecosmicfrog.luasataglance.util.Constant;
import org.thecosmicfrog.luasataglance.util.Preferences;

@@ -112,6 +113,12 @@ public void onClick(View v) {
/* Send the Intent. */
sendBroadcast(intent);

Analytics.selectContent(
getApplicationContext(),
"schedule_created",
"schedule_created"
);

/* Dismiss the Dialog. */
finish();
}
@@ -36,6 +36,7 @@
import org.thecosmicfrog.luasataglance.object.StopForecast;
import org.thecosmicfrog.luasataglance.object.StopNameIdMap;
import org.thecosmicfrog.luasataglance.object.Tram;
import org.thecosmicfrog.luasataglance.util.Analytics;
import org.thecosmicfrog.luasataglance.util.Constant;
import org.thecosmicfrog.luasataglance.util.Serializer;

@@ -150,6 +151,12 @@ public void run() {
replyStopForecast(Constant.PATH_STOPFORECAST_FETCH_WEAR, stopForecast);
}
}).start();
} else {
Analytics.nullApitimes(
getApplicationContext(),
"null",
"null_apitimes_wear"
);
}
}

@@ -190,6 +197,12 @@ public void failure(RetrofitError retrofitError) {
*/
if (retrofitError.getKind() != null)
Log.e(LOG_TAG, retrofitError.getKind().toString());

Analytics.httpError(
getApplicationContext(),
"http_error",
"http_error_general_wear"
);
}
};

@@ -44,6 +44,7 @@
import org.thecosmicfrog.luasataglance.object.StopForecast;
import org.thecosmicfrog.luasataglance.object.StopNameIdMap;
import org.thecosmicfrog.luasataglance.object.Tram;
import org.thecosmicfrog.luasataglance.util.Analytics;
import org.thecosmicfrog.luasataglance.util.Constant;

import java.io.BufferedInputStream;
@@ -257,6 +258,12 @@ public void success(ApiTimes apiTimes, Response response) {
updateStopForecast(context, views, stopForecast);

appWidgetManager.partiallyUpdateAppWidget(widgetId, views);
} else {
Analytics.nullApitimes(
getApplicationContext(),
"null",
"null_apitimes_widget"
);
}

/* Stop the refresh animations. */
@@ -301,6 +308,12 @@ public void failure(RetrofitError retrofitError) {
*/
if (retrofitError.getKind() != null)
Log.e(LOG_TAG, retrofitError.getKind().toString());

Analytics.httpError(
getApplicationContext(),
"http_error",
"http_error_general_widget"
);
}
};

@@ -0,0 +1,104 @@
/**
* @author Aaron Hastings
*
* Copyright 2015-2018 Aaron Hastings
*
* This file is part of Luas at a Glance.
*
* Luas at a Glance is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Luas at a Glance is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Luas at a Glance. If not, see <http://www.gnu.org/licenses/>.
*/

package org.thecosmicfrog.luasataglance.util;

import android.content.Context;
import android.os.Bundle;
import android.util.Log;

import com.google.firebase.analytics.FirebaseAnalytics;

import org.thecosmicfrog.luasataglance.activity.LineFragment;

public final class Analytics {

private static final String EVENT_HTTP_ERROR = "http_error";
private static final String EVENT_NULL_APITIMES = "null_apitimes";
private static final String LOG_TAG = Analytics.class.getSimpleName();

private static FirebaseAnalytics firebaseAnalytics;

public static void httpError(Context context, String contentType, String itemId) {

try {
firebaseAnalytics = FirebaseAnalytics.getInstance(context);
} catch (Exception e) {
Log.e(LOG_TAG, "Error gathering analytics for " + itemId + ".");
Log.e(LOG_TAG, Log.getStackTraceString(e));
}

if (firebaseAnalytics != null) {
Bundle params = new Bundle();
params.putString(FirebaseAnalytics.Param.CONTENT_TYPE, contentType);
params.putString(FirebaseAnalytics.Param.ITEM_ID, itemId);
firebaseAnalytics.logEvent(EVENT_HTTP_ERROR, params);
}
}

public static void nullApitimes(Context context, String contentType, String itemId) {
try {
firebaseAnalytics = FirebaseAnalytics.getInstance(context);
} catch (Exception e) {
Log.e(LOG_TAG, "Error gathering analytics for " + itemId + ".");
Log.e(LOG_TAG, Log.getStackTraceString(e));
}

if (firebaseAnalytics != null) {
Bundle params = new Bundle();
params.putString(FirebaseAnalytics.Param.CONTENT_TYPE, contentType);
params.putString(FirebaseAnalytics.Param.ITEM_ID, itemId);
firebaseAnalytics.logEvent(EVENT_NULL_APITIMES, params);
}
}

public static void selectContent(Context context, String contentType, String itemId) {
try {
firebaseAnalytics = FirebaseAnalytics.getInstance(context);
} catch (Exception e) {
Log.e(LOG_TAG, "Error gathering analytics for " + itemId + ".");
Log.e(LOG_TAG, Log.getStackTraceString(e));
}

if (firebaseAnalytics != null) {
Bundle params = new Bundle();
params.putString(FirebaseAnalytics.Param.CONTENT_TYPE, contentType);
params.putString(FirebaseAnalytics.Param.ITEM_ID, itemId);
firebaseAnalytics.logEvent(FirebaseAnalytics.Event.SELECT_CONTENT, params);
}
}

public static void tutorialBegin(Context context, String contentType, String itemId) {
try {
firebaseAnalytics = FirebaseAnalytics.getInstance(context);
} catch (Exception e) {
Log.e(LOG_TAG, "Error gathering analytics for " + itemId + ".");
Log.e(LOG_TAG, Log.getStackTraceString(e));
}

if (firebaseAnalytics != null) {
Bundle params = new Bundle();
params.putString(FirebaseAnalytics.Param.CONTENT_TYPE, contentType);
params.putString(FirebaseAnalytics.Param.ITEM_ID, itemId);
firebaseAnalytics.logEvent(FirebaseAnalytics.Event.TUTORIAL_BEGIN, params);
}
}
}
@@ -51,6 +51,12 @@ public static void getSettings(Context context, MenuItem item) {
NewsActivity.class
).putExtra(Constant.NEWS_TYPE, Constant.NEWS_TYPE_LUAS_NEWS)
);

Analytics.selectContent(
context,
"menuitem_tapped",
"news_tapped"
);
}

if (id == R.id.action_settings) {
@@ -60,6 +66,12 @@ public static void getSettings(Context context, MenuItem item) {
SettingsActivity.class
)
);

Analytics.selectContent(
context,
"menuitem_tapped",
"settings_tapped"
);
}

if (id == R.id.action_about) {
@@ -69,6 +81,12 @@ public static void getSettings(Context context, MenuItem item) {
AboutActivity.class
)
);

Analytics.selectContent(
context,
"menuitem_tapped",
"about_tapped"
);
}
}
}
Oops, something went wrong.

0 comments on commit 11442f5

Please sign in to comment.
You can’t perform that action at this time.