This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class App : Application() { | |
override fun onCreate() { | |
super.onCreate() | |
StrictMode.setThreadPolicy( | |
StrictMode.ThreadPolicy.Builder() | |
.detectAll() | |
.penaltyLog() | |
.penaltyDialog() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cclass AndroidLogTracker(private val context: Context) : Tracker { | |
private val TAG = this::class.java.simpleName | |
private fun tag(): String = | |
"${context.applicationInfo.name}:${context.applicationInfo.packageName}:$TAG" | |
override fun isAnalyticsEnabled(): Boolean { | |
Log.d( | |
TAG, | |
"${tag()} is enable ${BuildConfig.DEBUG}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const val TRACKER_SAMPLE = "sample_tracker" | |
val analyticsModule = module { | |
single<Tracker>(named(TRACKER_SAMPLE)) { SampleTracker(androidApplication()) } | |
single<Analytics> { AnalyticsImpl(androidApplication(), mutableListOf(get(named(TRACKER_SAMPLE)))) } | |
} | |
// Code on your base fragment or base activity | |
val analytics: Analytics by inject() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface CrashReporter : Tracker { | |
fun simulateCrash() | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
annotation class DslAnalytics | |
@DslAnalytics | |
open class EventBuilder(var name: String? = null) { | |
val data: MutableMap<String, String>? by lazy { | |
mutableMapOf<String, String>() | |
} | |
inline fun String.to(value: String) { | |
data?.let { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Trackable { | |
@EventName | |
val eventName: String | |
val properties: Map<String, String>? | |
} | |
sealed class Event : Trackable { | |
data class EventTrack( | |
@EventName override val eventName: String, | |
override val properties: Map<String, String>? = null |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Tracker { | |
fun isAnalyticsEnabled(): Boolean | |
fun enableAnalytics(enabled: Boolean) | |
fun logLevel(logLevel: Int) | |
fun start() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Analytics { | |
fun track(setup: EventBuilder.() -> Unit = {}) | |
} | |
class AnalyticsImpl(private val trackers: MutableList<Tracker>) : Analytics { | |
init { | |
trackers.forEach { | |
if(it.isAnalyticsEnable()){ | |
it.start() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Analytics { | |
fun track(setup: EventBuilder.() -> Unit = {}) | |
} | |
class AnalyticsImpl(private val trackers: MutableList<Tracker>) : Analytics { | |
init { | |
trackers.forEach { | |
if(it.isAnalyticsEnable()){ | |
it.start() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.actinarium.materialcue.analytics; | |
import android.app.Application; | |
import android.support.annotation.NonNull; | |
import android.util.Log; | |
import com.actinarium.materialcue.dto.Overlay; | |
import com.actinarium.materialcue.iab.PremiumStatus; | |
import com.actinarium.materialcue.iab.PremiumStatusChangeListener; | |
import com.google.android.gms.analytics.HitBuilders; | |
import com.google.android.gms.analytics.Tracker; |