Added Amplitude and AnalyticsManager

This commit is contained in:
Moez Bhatti
2017-12-14 20:52:36 -05:00
parent 5213998c9c
commit 941d3bb6ef
6 changed files with 49 additions and 10 deletions
+7
View File
@@ -17,10 +17,16 @@ android {
} }
buildTypes { buildTypes {
release { release {
buildConfigField "String", "BUGSNAG_API_KEY", '""'
buildConfigField "String", "AMPLITUDE_API_KEY", '""'
buildConfigField "String", "MIXPANEL_API_KEY", '""'
minifyEnabled false minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
} }
debug { debug {
buildConfigField "String", "BUGSNAG_API_KEY", '""'
buildConfigField "String", "AMPLITUDE_API_KEY", '""'
buildConfigField "String", "MIXPANEL_API_KEY", '""'
applicationIdSuffix ".debug" applicationIdSuffix ".debug"
} }
} }
@@ -36,6 +42,7 @@ dependencies {
}) })
compile "android.arch.lifecycle:extensions:1.0.0" compile "android.arch.lifecycle:extensions:1.0.0"
compile "android.arch.lifecycle:runtime:1.0.3" compile "android.arch.lifecycle:runtime:1.0.3"
compile 'com.amplitude:android-sdk:2.16.0'
compile 'com.android.support:appcompat-v7:27.0.2' compile 'com.android.support:appcompat-v7:27.0.2'
compile 'com.android.support.constraint:constraint-layout:1.0.2' compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:design:27.0.2' compile 'com.android.support:design:27.0.2'
-4
View File
@@ -88,10 +88,6 @@
</intent-filter> </intent-filter>
</service> </service>
<meta-data
android:name="com.bugsnag.android.API_KEY"
android:value="d87e83a633f143665e6466f524449791" />
</application> </application>
</manifest> </manifest>
@@ -2,21 +2,31 @@ package com.moez.QKSMS.common
import android.app.Application import android.app.Application
import com.bugsnag.android.Bugsnag import com.bugsnag.android.Bugsnag
import com.mixpanel.android.mpmetrics.MixpanelAPI import com.moez.QKSMS.BuildConfig
import com.moez.QKSMS.common.di.AppComponentManager import com.moez.QKSMS.common.di.AppComponentManager
import com.moez.QKSMS.common.di.appComponent
import com.moez.QKSMS.common.util.Analytics
import io.realm.Realm import io.realm.Realm
import io.realm.RealmConfiguration import io.realm.RealmConfiguration
import timber.log.Timber import timber.log.Timber
import javax.inject.Inject
class QKApplication : Application() { class QKApplication : Application() {
/**
* Inject this so that it is forced to initialize
*/
@Suppress("unused")
@Inject lateinit var analytics: Analytics
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
Bugsnag.init(this) Bugsnag.init(this, BuildConfig.BUGSNAG_API_KEY)
MixpanelAPI.getInstance(this, "") AppComponentManager.init(this)
appComponent.inject(this)
Realm.init(this) Realm.init(this)
Realm.setDefaultConfiguration(RealmConfiguration.Builder() Realm.setDefaultConfiguration(RealmConfiguration.Builder()
@@ -24,8 +34,6 @@ class QKApplication : Application() {
.deleteRealmIfMigrationNeeded() .deleteRealmIfMigrationNeeded()
.build()) .build())
AppComponentManager.init(this)
Timber.plant(Timber.DebugTree()) Timber.plant(Timber.DebugTree())
} }
@@ -1,5 +1,6 @@
package com.moez.QKSMS.common.di package com.moez.QKSMS.common.di
import com.moez.QKSMS.common.QKApplication
import com.moez.QKSMS.common.util.ContactImageLoader import com.moez.QKSMS.common.util.ContactImageLoader
import com.moez.QKSMS.presentation.common.widget.* import com.moez.QKSMS.presentation.common.widget.*
import com.moez.QKSMS.presentation.compose.ComposeActivity import com.moez.QKSMS.presentation.compose.ComposeActivity
@@ -17,6 +18,8 @@ import javax.inject.Singleton
@Component(modules = [(AppModule::class)]) @Component(modules = [(AppModule::class)])
interface AppComponent { interface AppComponent {
fun inject(application: QKApplication)
fun inject(activity: MainActivity) fun inject(activity: MainActivity)
fun inject(activity: ComposeActivity) fun inject(activity: ComposeActivity)
fun inject(activity: SettingsActivity) fun inject(activity: SettingsActivity)
@@ -19,7 +19,7 @@ class AppModule(private var application: Application) {
@Provides @Provides
@Singleton @Singleton
fun provideRxPreferences(context: Context) : RxSharedPreferences { fun provideRxPreferences(context: Context): RxSharedPreferences {
val preferences = PreferenceManager.getDefaultSharedPreferences(context) val preferences = PreferenceManager.getDefaultSharedPreferences(context)
return RxSharedPreferences.create(preferences) return RxSharedPreferences.create(preferences)
} }
@@ -0,0 +1,25 @@
package com.moez.QKSMS.common.util
import android.content.Context
import com.amplitude.api.Amplitude
import com.amplitude.api.AmplitudeClient
import com.mixpanel.android.mpmetrics.MixpanelAPI
import com.moez.QKSMS.BuildConfig
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class Analytics @Inject constructor(context: Context) {
private val amplitude: AmplitudeClient = Amplitude.getInstance().initialize(context, BuildConfig.AMPLITUDE_API_KEY)
private val mixpanel: MixpanelAPI = MixpanelAPI.getInstance(context, BuildConfig.MIXPANEL_API_KEY)
fun track(event: String) {
amplitude.logEvent(event)
synchronized(mixpanel, {
mixpanel.track(event)
})
}
}