Commit 6766e4f5 authored by Mygod's avatar Mygod

Migrate to Firebase Analytics

parent ed9acb66
......@@ -70,7 +70,6 @@ dependencies {
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.4'
implementation 'com.futuremind.recyclerfastscroll:fastscroll:0.2.5'
implementation "com.google.android.gms:play-services-ads:15.0.1"
implementation "com.google.android.gms:play-services-analytics:16.0.0"
implementation "com.google.android.gms:play-services-vision:15.0.2"
implementation "com.google.firebase:firebase-config:16.0.0"
implementation 'com.google.firebase:firebase-core:16.0.0'
......
......@@ -48,10 +48,8 @@ import com.github.shadowsocks.preference.BottomSheetPreferenceDialogFragment
import com.github.shadowsocks.preference.DataStore
import com.github.shadowsocks.preference.IconListPreference
import com.github.shadowsocks.utils.*
import com.google.android.gms.analytics.GoogleAnalytics
import com.google.android.gms.analytics.HitBuilders
import com.google.android.gms.analytics.Tracker
import com.google.firebase.FirebaseApp
import com.google.firebase.analytics.FirebaseAnalytics
import com.google.firebase.remoteconfig.FirebaseRemoteConfig
import com.takisoft.fix.support.v7.preference.PreferenceFragmentCompat
import io.fabric.sdk.android.Fabric
......@@ -67,7 +65,7 @@ class App : Application() {
val handler by lazy { Handler(Looper.getMainLooper()) }
val deviceContext: Context by lazy { if (Build.VERSION.SDK_INT < 24) this else DeviceContext(this) }
val remoteConfig: FirebaseRemoteConfig by lazy { FirebaseRemoteConfig.getInstance() }
private val tracker: Tracker by lazy { GoogleAnalytics.getInstance(deviceContext).newTracker(R.xml.tracker) }
val analytics: FirebaseAnalytics by lazy { FirebaseAnalytics.getInstance(deviceContext) }
val info: PackageInfo by lazy { getPackageInfo(packageName) }
val directBootSupported by lazy {
Build.VERSION.SDK_INT >= 24 && getSystemService(DevicePolicyManager::class.java)
......@@ -94,13 +92,6 @@ class App : Application() {
return result
}
// send event
fun track(category: String, action: String) = tracker.send(HitBuilders.EventBuilder()
.setCategory(category)
.setAction(action)
.setLabel(BuildConfig.VERSION_NAME)
.build())
override fun onCreate() {
super.onCreate()
app = this
......
......@@ -359,7 +359,7 @@ class MainActivity : AppCompatActivity(), ShadowsocksConnection.Interface, Drawe
DRAWER_PROFILES -> displayFragment(ProfilesFragment())
DRAWER_GLOBAL_SETTINGS -> displayFragment(GlobalSettingsFragment())
DRAWER_ABOUT -> {
app.track(TAG, "about")
app.analytics.logEvent("about", Bundle())
displayFragment(AboutFragment())
}
DRAWER_FAQ -> launchUrl(getString(R.string.faq_url))
......
......@@ -26,6 +26,7 @@ import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.os.Build
import android.os.Bundle
import android.os.IBinder
import android.os.RemoteCallbackList
import android.support.v4.os.UserManagerCompat
......@@ -45,6 +46,7 @@ import com.github.shadowsocks.plugin.PluginManager
import com.github.shadowsocks.plugin.PluginOptions
import com.github.shadowsocks.preference.DataStore
import com.github.shadowsocks.utils.*
import com.google.firebase.analytics.FirebaseAnalytics
import okhttp3.FormBody
import okhttp3.OkHttpClient
import okhttp3.Request
......@@ -291,7 +293,7 @@ object BaseService {
val data = data
data.changeState(STOPPING)
app.track(tag, "stop")
app.analytics.logEvent("stop", Bundle().put(FirebaseAnalytics.Param.METHOD, tag))
killProcesses()
......@@ -355,7 +357,7 @@ object BaseService {
}
data.notification = createNotification(profile.formattedName)
app.track(tag, "start")
app.analytics.logEvent("start", Bundle().put(FirebaseAnalytics.Param.METHOD, tag))
data.changeState(CONNECTING)
......
......@@ -10,6 +10,7 @@ import android.graphics.BitmapFactory
import android.graphics.ImageDecoder
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.support.annotation.AttrRes
import android.support.v4.content.ContextCompat
import android.support.v7.util.SortedList
......@@ -81,4 +82,8 @@ fun printLog(t: Throwable) {
Crashlytics.logException(t)
t.printStackTrace()
}
fun track(thread: Thread, t: Throwable) = printLog(t)
fun Bundle.put(key: String, value: String): Bundle {
putString(key, value)
return this
}
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Set a session timeout period of 1 week -->
<integer name="ga_sessionTimeout">604800</integer>
<!-- Enable automatic Activity measurement -->
<bool name="ga_autoActivityTracking">true</bool>
<!-- Enable exception reports -->
<bool name="ga_reportUncaughtExceptions">true</bool>
<!-- The screen names that will appear in reports -->
<screenName name="com.google.android.gms.analytics.samples.mobileplayground.ScreenviewFragment">
Shadowsocks ScreenView
</screenName>
<screenName name="com.google.android.gms.analytics.samples.mobileplayground.EcommerceFragment">
Shadowsocks EcommerceView
</screenName>
<!-- The following value should be replaced with correct property id. -->
<string name="ga_trackingId">UA-37082941-1</string>
</resources>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment