Skip to content
This repository has been archived by the owner on May 8, 2019. It is now read-only.

Commit

Permalink
Merge pull request #1201 from 47deg/javi-1139-disable-analytics
Browse files Browse the repository at this point in the history
Added Google Analytics preference
  • Loading branch information
Javi Pacheco authored Dec 22, 2016
2 parents f3ff984 + 0b0b410 commit 9ba5f88
Show file tree
Hide file tree
Showing 20 changed files with 119 additions and 5 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions modules/app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,16 @@
<string name="wallpaperAnimationTitle">Movimiento Fondo de Pantalla</string> <!-- Pending review language -->
<string name="wallpaperAnimationSummary">La imagen de fondo se mueve en el desplazamiento entre pantallas en el launcher</string> <!-- Pending review language -->

<!-- Analytics Preferences -->

<string name="analyticsPrefTitle">Analítica</string> <!-- Pending review language -->
<string name="analyticsPrefSummary">Aprende más sobre nuestra política de analítica</string> <!-- Pending review language -->

<string name="analyticsEnabledPrefTitle">Habilitar analítica</string><!-- Pending review language -->
<string name="analyticsEnabledPrefSummary">9 Cards usa Google Analytics para trackear el comportamiento independientemente de como ellos usas las apps. La información es anónima y es usada con el propósito de la generación de estadísticas de las apps más populares, mejores colecciones y mejor experiencia del usuario. Los datos son sólo usados con este propósito y no son vendidos, publicados ni usados de otra manera que para mejorar la experiencia en el Launcher. Si prefieres que tus datos anónimos no sean usados tu puedes deshabilitarlo</string><!-- Pending review language -->

<!-- Pending review language -->

<!-- Developer Preferences -->

<string name="developerOptionsActivated">Opciones para Desarrolladores Activada</string>
Expand Down
8 changes: 8 additions & 0 deletions modules/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,14 @@
<string name="wallpaperAnimationTitle">Wallpaper movement</string>
<string name="wallpaperAnimationSummary">The background image will move along with you as you swipe left or right through your home screens</string>

<!-- Analytics Preferences -->

<string name="analyticsPrefTitle">Analytics</string><!-- Pending review language -->
<string name="analyticsPrefSummary">Learn more about our analytics</string><!-- Pending review language -->

<string name="analyticsEnabledPrefTitle">Analytics Enable</string><!-- Pending review language -->
<string name="analyticsEnabledPrefSummary">9 Cards uses Google Analytics to track user behavior regarding how they open and use apps. This user data is anonymous and is collected for the purpose of generating statistics on popular apps, best collections, and improving your user experience. The data is only used for this purpose and will not be sold, published, or used in any other manner, other than to improve the functionality of this launcher. If you prefer that your anonymous data is not used, you may opt-out here</string><!-- Pending review language -->

<!-- Developer Preferences -->

<string name="developerOptionsActivated">Developer options activated</string>
Expand Down
17 changes: 17 additions & 0 deletions modules/app/src/main/res/xml/preferences_analytics.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">

<PreferenceCategory android:title="@string/analyticsPrefTitle">

<CheckBoxPreference
android:key="analyticsEnabled"
android:defaultValue="true"
android:title="@string/analyticsEnabledPrefTitle"/>

<Preference
android:summary="@string/analyticsEnabledPrefSummary"/>

</PreferenceCategory>

</PreferenceScreen>
8 changes: 7 additions & 1 deletion modules/app/src/main/res/xml/preferences_devs_headers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
android:key="animationsKey"
android:summary="@string/animationsPrefSummary"/>

<PreferenceScreen
android:icon="@drawable/icon_preferences_analytics"
android:title="@string/analyticsPrefTitle"
android:key="analyticsKey"
android:summary="@string/analyticsPrefSummary"/>

<PreferenceScreen
android:icon="@drawable/icon_preferences_developers"
android:title="@string/developerPrefTitle"
Expand All @@ -51,7 +57,7 @@
android:summary="@string/aboutSummary"/>

<PreferenceScreen
android:icon="@drawable/icon_preferences_help"
android:icon="@drawable/icon_preferences_feedback"
android:title="@string/sendFeedbackTitle"
android:key="feedbackKey"
android:summary="@string/sendFeedbackSummary"/>
Expand Down
8 changes: 7 additions & 1 deletion modules/app/src/main/res/xml/preferences_headers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
android:key="animationsKey"
android:summary="@string/animationsPrefSummary"/>

<PreferenceScreen
android:icon="@drawable/icon_preferences_analytics"
android:title="@string/analyticsPrefTitle"
android:key="analyticsKey"
android:summary="@string/analyticsPrefSummary"/>

</PreferenceCategory>

<PreferenceCategory android:title="@string/others">
Expand All @@ -45,7 +51,7 @@
android:summary="@string/aboutSummary"/>

<PreferenceScreen
android:icon="@drawable/icon_preferences_help"
android:icon="@drawable/icon_preferences_feedback"
android:title="@string/sendFeedbackTitle"
android:key="feedbackKey"
android:summary="@string/sendFeedbackSummary"/>
Expand Down
13 changes: 10 additions & 3 deletions modules/app/src/main/scala/cards/nine/app/di/Injector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import android.content.res.Resources
import cards.nine.api.rest.client.ServiceClient
import cards.nine.api.rest.client.http.OkHttpClient
import cards.nine.app.observers.ObserverRegister
import cards.nine.app.ui.preferences.commons.{BackendV2Url, IsStethoActive, OverrideBackendV2Url}
import cards.nine.app.ui.preferences.commons.{
AnalyticsEnabled,
BackendV2Url,
IsStethoActive,
OverrideBackendV2Url
}
import cards.nine.commons.contentresolver.{ContentResolverWrapperImpl, UriCreator}
import cards.nine.commons.contexts.ContextSupport
import cards.nine.models.types.NineCardsCategory
Expand Down Expand Up @@ -55,7 +60,7 @@ import cards.nine.services.permissions.impl.AndroidSupportPermissionsServices
import cards.nine.services.persistence.impl.PersistenceServicesImpl
import cards.nine.services.plus.impl.GooglePlusServicesImpl
import cards.nine.services.shortcuts.impl.ShortcutsServicesImpl
import cards.nine.services.track.impl.ConsoleTrackServices
import cards.nine.services.track.impl.{ConsoleTrackServices, DisableTrackServices}
import cards.nine.services.widgets.impl.WidgetsServicesImpl
import cards.nine.services.connectivity.impl.ConnectivityServicesImpl
import com.facebook.stetho.okhttp3.StethoInterceptor
Expand Down Expand Up @@ -249,7 +254,9 @@ class InjectorImpl(implicit contextSupport: ContextSupport) extends Injector {
override def trackEventProcess: TrackEventProcess = {
def createService() = {
val resources = contextSupport.getResources
if (resources.getString(R.string.analytics_enabled).equalsIgnoreCase("true")) {
if (!AnalyticsEnabled.readValueWith(contextSupport.context)) {
new DisableTrackServices
} else if (resources.getString(R.string.analytics_enabled).equalsIgnoreCase("true")) {
val track = GoogleAnalytics
.getInstance(contextSupport.context)
.newTracker(resources.getString(R.string.ga_trackingId))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.preference.{Preference, PreferenceActivity, PreferenceFragment}
import android.view.MenuItem
import cards.nine.app.ui.commons.ops.TaskServiceOps._
import cards.nine.app.ui.preferences.about.AboutFragment
import cards.nine.app.ui.preferences.analytics.AnalyticsFragment
import cards.nine.app.ui.preferences.animations.AnimationsFragment
import cards.nine.app.ui.preferences.appdrawer.AppDrawerFragment
import cards.nine.app.ui.preferences.commons._
Expand Down Expand Up @@ -79,6 +80,9 @@ class NineCardsPreferencesActivity
findPreference(AnimationsPreferences.name).setOnPreferenceClickListener(
preferenceClick(AnimationsPreferences.name, new AnimationsFragment()))

findPreference(AnalyticsPreferences.name).setOnPreferenceClickListener(
preferenceClick(AnalyticsPreferences.name, new AnalyticsFragment()))

findPreference(WizardInlinePreferences.name).setOnPreferenceClickListener(
preferenceActionClick(() => jobs.cleanWizardInlinePreferences().resolveAsync()))

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package cards.nine.app.ui.preferences.analytics

import android.os.Bundle
import cards.nine.app.ui.preferences.commons.PreferenceChangeListenerFragment
import com.fortysevendeg.ninecardslauncher.R

class AnalyticsFragment extends PreferenceChangeListenerFragment {

override def onCreate(savedInstanceState: Bundle): Unit = {
super.onCreate(savedInstanceState)
withActivity { activity =>
Option(activity.getActionBar) foreach (_.setTitle(getString(R.string.analyticsPrefTitle)))
}
addPreferencesFromResource(R.xml.preferences_analytics)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ case object AnimationsPreferences extends NineCardsPreferences {
override val name: String = "animationsKey"
}

case object AnalyticsPreferences extends NineCardsPreferences {
override val name: String = "analyticsKey"
}

case object DeveloperPreferences extends NineCardsPreferences {
override val name: String = "developerKey"
}
Expand Down Expand Up @@ -258,6 +262,16 @@ case object CardPadding extends NineCardsPreferenceValue[IconsSizeValue] {
}
}

// Analytics

case object AnalyticsEnabled extends NineCardsPreferenceValue[Boolean] {
override val name: String = "analyticsEnabled"
override val default: Boolean = true

override def readValueWith(context: Context): Boolean =
getBoolean(context, name, default)
}

// Developer Preferences

case object IsDeveloper extends NineCardsPreferenceValue[Boolean] {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package cards.nine.services.track.impl

import cards.nine.commons.services.TaskService
import cards.nine.commons.services.TaskService._
import cards.nine.models.TrackEvent
import cards.nine.models.types.MomentCategory
import cards.nine.services.track.TrackServices
import monix.eval.Task

class DisableTrackServices extends TrackServices {

override def trackEvent(event: TrackEvent): TaskService[Unit] = TaskService {
val categoryName = event.category match {
case MomentCategory(moment) => s"WIDGET_${moment.name}"
case _ => event.category.name
}

Task(Right(println(s"""Event no tracked
| Action ${event.action.name}
| Category $categoryName
| Label ${event.label.getOrElse("")}
| Screen ${event.screen.name}
| Value ${event.value.map(_.value).getOrElse(0)}""".stripMargin)))
}
}

0 comments on commit 9ba5f88

Please sign in to comment.