├── lib ├── consumer-rules.pro ├── .gitignore ├── src │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── raqun │ │ │ │ └── gadget │ │ │ │ └── lib │ │ │ │ ├── model │ │ │ │ ├── RefundedProduct.kt │ │ │ │ ├── Promotion.kt │ │ │ │ └── Product.kt │ │ │ │ ├── event │ │ │ │ ├── eec │ │ │ │ │ ├── EecEvent.kt │ │ │ │ │ ├── ProductSelectionEvent.kt │ │ │ │ │ ├── PromotionImpressionEvent.kt │ │ │ │ │ ├── ProductImpressionEvent.kt │ │ │ │ │ ├── AddToCartEvent.kt │ │ │ │ │ ├── BeginCheckoutEvent.kt │ │ │ │ │ ├── ProductDetailViewEvent.kt │ │ │ │ │ ├── RemoveFromCartEvent.kt │ │ │ │ │ ├── PromotionSelectionEvent.kt │ │ │ │ │ ├── RefundEvent.kt │ │ │ │ │ └── PurchaseEvent.kt │ │ │ │ ├── click │ │ │ │ │ └── ClickEvent.kt │ │ │ │ ├── input │ │ │ │ │ ├── FocusInEvent.kt │ │ │ │ │ ├── FocusOutEvent.kt │ │ │ │ │ └── InputEvent.kt │ │ │ │ ├── AnalyticsEvent.kt │ │ │ │ ├── switch │ │ │ │ │ └── SwitchEvent.kt │ │ │ │ ├── custom │ │ │ │ │ └── CustomEvent.kt │ │ │ │ ├── tab │ │ │ │ │ └── TabSelectionEvent.kt │ │ │ │ ├── FirebaseEvent.kt │ │ │ │ ├── view │ │ │ │ │ └── ScreenViewEvent.kt │ │ │ │ ├── Event.kt │ │ │ │ └── error │ │ │ │ │ └── ErrorEvent.kt │ │ │ │ ├── tracker │ │ │ │ ├── LifecycleEventTracker.kt │ │ │ │ ├── EventTracker.kt │ │ │ │ ├── AnalyticsTracker.kt │ │ │ │ ├── impl │ │ │ │ │ ├── DefaultEventTracker.kt │ │ │ │ │ ├── FirebaseEventTracker.kt │ │ │ │ │ ├── EecProductImpressionTracker.kt │ │ │ │ │ └── EecPromotionImpressionTracker.kt │ │ │ │ └── ListItemImpressionTracker.kt │ │ │ │ ├── extensions │ │ │ │ ├── promotionExt.kt │ │ │ │ ├── bundleExt.kt │ │ │ │ └── productExt.kt │ │ │ │ ├── Constants.kt │ │ │ │ └── Gadget.kt │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── raqun │ │ │ └── gadget │ │ │ └── lib │ │ │ └── ExampleUnitTest.kt │ └── androidTest │ │ └── java │ │ └── com │ │ └── raqun │ │ └── gadget │ │ └── lib │ │ └── ExampleInstrumentedTest.kt ├── build.gradle └── proguard-rules.pro ├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ └── themes.xml │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── values-night │ │ │ │ └── themes.xml │ │ │ ├── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ │ └── drawable │ │ │ │ └── ic_launcher_background.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── raqun │ │ │ │ └── gadget │ │ │ │ └── MainActivity.kt │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── raqun │ │ │ └── gadget │ │ │ └── ExampleUnitTest.kt │ └── androidTest │ │ └── java │ │ └── com │ │ └── raqun │ │ └── gadget │ │ └── ExampleInstrumentedTest.kt ├── build.gradle └── proguard-rules.pro ├── art └── gadget.jpeg ├── settings.gradle ├── common-android-library.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── test-dependencies.gradle ├── gradle.properties ├── common.gradle ├── gradlew.bat ├── gradlew ├── README.md └── LICENSE /lib/consumer-rules.pro: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | /libs 3 | -------------------------------------------------------------------------------- /lib/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | /libs 3 | -------------------------------------------------------------------------------- /art/gadget.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/savepopulation/gadget/HEAD/art/gadget.jpeg -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':lib' 2 | include ':app' 3 | rootProject.name = "gadget" 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Gadget 3 | -------------------------------------------------------------------------------- /common-android-library.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: Plugins.androidLibrary 2 | apply from: "$rootDir/common.gradle" 3 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/savepopulation/gadget/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/savepopulation/gadget/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/savepopulation/gadget/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/savepopulation/gadget/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/savepopulation/gadget/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/savepopulation/gadget/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/savepopulation/gadget/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/savepopulation/gadget/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/savepopulation/gadget/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/savepopulation/gadget/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/savepopulation/gadget/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea 5 | .DS_Store 6 | /build 7 | /captures 8 | .externalNativeBuild 9 | .cxx 10 | local.properties 11 | -------------------------------------------------------------------------------- /lib/src/main/java/com/raqun/gadget/lib/model/RefundedProduct.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.gadget.lib.model 2 | 3 | /* 4 | * Refunded Product 5 | * Used for Refund EEC Event 6 | */ 7 | data class RefundedProduct(val id: String, val quantity: Long) -------------------------------------------------------------------------------- /lib/src/main/java/com/raqun/gadget/lib/event/eec/EecEvent.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.gadget.lib.event.eec 2 | 3 | /* 4 | * Marker interface for Enhanced e-commerce events 5 | * Ref: https://developers.google.com/tag-manager/android/v5/enhanced-ecommerce 6 | */ 7 | interface EecEvent -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Apr 27 07:42:17 EET 2021 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip 7 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /lib/build.gradle: -------------------------------------------------------------------------------- 1 | apply from: "$rootDir/common-android-library.gradle" 2 | 3 | dependencies { 4 | implementation platform(Libraries.firebaseBom) 5 | api Libraries.firebaseAnalytics 6 | api Libraries.firebaseCrashlytics 7 | implementation Libraries.googleTagManager 8 | implementation Libraries.firebasePerformance 9 | } 10 | -------------------------------------------------------------------------------- /lib/src/main/java/com/raqun/gadget/lib/tracker/LifecycleEventTracker.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.gadget.lib.tracker 2 | 3 | import androidx.lifecycle.Lifecycle 4 | 5 | /* 6 | * Defines a tracker is binds with lifecycle 7 | */ 8 | interface LifecycleEventTracker { 9 | /* 10 | * Lifecycle 11 | */ 12 | val lifeCycle: Lifecycle 13 | } 14 | -------------------------------------------------------------------------------- /lib/src/main/java/com/raqun/gadget/lib/model/Promotion.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.gadget.lib.model 2 | 3 | /* 4 | * Promotion 5 | * Used for to track promotion related EEC events 6 | */ 7 | data class Promotion( 8 | val id: String, 9 | val name: String, 10 | val creativeName: String? = null, 11 | val creativeSlot: String? = null 12 | ) 13 | -------------------------------------------------------------------------------- /lib/src/main/java/com/raqun/gadget/lib/tracker/EventTracker.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.gadget.lib.tracker 2 | 3 | import com.raqun.gadget.lib.event.Event 4 | 5 | /* 6 | * Defines the general event tracker 7 | */ 8 | interface EventTracker { 9 | /* 10 | * Tracking function 11 | * Tracks the given event 12 | */ 13 | fun track(event: Event) 14 | } 15 | -------------------------------------------------------------------------------- /app/src/main/java/com/raqun/gadget/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.gadget 2 | 3 | import androidx.appcompat.app.AppCompatActivity 4 | import android.os.Bundle 5 | 6 | class MainActivity : AppCompatActivity() { 7 | override fun onCreate(savedInstanceState: Bundle?) { 8 | super.onCreate(savedInstanceState) 9 | //setContentView(R.layout.activity_main) 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /lib/src/main/java/com/raqun/gadget/lib/event/click/ClickEvent.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.gadget.lib.event.click 2 | 3 | import com.raqun.gadget.lib.Constants 4 | import com.raqun.gadget.lib.event.AnalyticsEvent 5 | 6 | /* 7 | * Generic click event to track the clicks in the app 8 | */ 9 | data class ClickEvent( 10 | override val name: String = Constants.Event.CLICK 11 | ) : AnalyticsEvent() 12 | -------------------------------------------------------------------------------- /lib/src/main/java/com/raqun/gadget/lib/event/input/FocusInEvent.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.gadget.lib.event.input 2 | 3 | import com.raqun.gadget.lib.Constants 4 | 5 | /* 6 | * Generic input area focus in event 7 | */ 8 | data class FocusInEvent( 9 | private val eventName: String = Constants.Event.FOCUS_IN, 10 | private val isValid: Boolean? = null 11 | ) : InputEvent(eventName, isValid) 12 | 13 | -------------------------------------------------------------------------------- /lib/src/main/java/com/raqun/gadget/lib/event/input/FocusOutEvent.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.gadget.lib.event.input 2 | 3 | import com.raqun.gadget.lib.Constants 4 | 5 | /* 6 | * Generic input area focus out event 7 | */ 8 | data class FocusOutEvent( 9 | private val eventName: String = Constants.Event.FOCUS_OUT, 10 | private val isValid: Boolean? = null 11 | ) : InputEvent(eventName, isValid) 12 | -------------------------------------------------------------------------------- /lib/src/main/java/com/raqun/gadget/lib/event/AnalyticsEvent.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.gadget.lib.event 2 | 3 | /* 4 | * Analytics Event 5 | * Abstraction of general analytics event that can be tracked by the library 6 | * Ideally, an event should be tracked to Firebase by default. 7 | */ 8 | abstract class AnalyticsEvent(final override val params: MutableMap = mutableMapOf()) : 9 | FirebaseEvent 10 | -------------------------------------------------------------------------------- /lib/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FFBB86FC 4 | #FF6200EE 5 | #FF3700B3 6 | #FF03DAC5 7 | #FF018786 8 | #FF000000 9 | #FFFFFFFF 10 | -------------------------------------------------------------------------------- /lib/src/main/java/com/raqun/gadget/lib/model/Product.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.gadget.lib.model 2 | 3 | /* 4 | * Product data class that will be tracked wit EEC Events 5 | */ 6 | data class Product( 7 | val id: String, 8 | val name: String, 9 | val category: String?, 10 | val variant: String?, 11 | val brand: String?, 12 | val price: Double?, 13 | val currency: String?, 14 | val quantity: Long? = null 15 | ) 16 | -------------------------------------------------------------------------------- /app/src/test/java/com/raqun/gadget/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.gadget 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } -------------------------------------------------------------------------------- /lib/src/test/java/com/raqun/gadget/lib/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.gadget.lib 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } -------------------------------------------------------------------------------- /lib/src/main/java/com/raqun/gadget/lib/event/input/InputEvent.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.gadget.lib.event.input 2 | 3 | import com.raqun.gadget.lib.Constants 4 | import com.raqun.gadget.lib.event.AnalyticsEvent 5 | 6 | /* 7 | * Generic Input event 8 | */ 9 | open class InputEvent( 10 | override val name: String, 11 | isValid: Boolean? = null 12 | ) : AnalyticsEvent() { 13 | 14 | init { 15 | params[Constants.Param.IS_VALID] = isValid 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /lib/src/main/java/com/raqun/gadget/lib/event/switch/SwitchEvent.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.gadget.lib.event.switch 2 | 3 | import com.raqun.gadget.lib.Constants 4 | import com.raqun.gadget.lib.event.AnalyticsEvent 5 | 6 | /* 7 | * Generic switch event to track switch status changes in the app 8 | */ 9 | data class SwitchEvent( 10 | override val name: String = Constants.Event.SWITCH, 11 | private val status: Boolean 12 | ) : AnalyticsEvent() { 13 | 14 | init { 15 | params[Constants.Param.STATUS] = status 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /lib/src/main/java/com/raqun/gadget/lib/tracker/AnalyticsTracker.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.gadget.lib.tracker 2 | 3 | import android.content.Context 4 | import com.raqun.gadget.lib.event.Event 5 | 6 | /* 7 | * Defines Gadget's general tracking methods 8 | */ 9 | interface AnalyticsTracker { 10 | /* 11 | * Setup tracker 12 | */ 13 | fun setup(context: Context, customEventTracker: EventTracker? = null) 14 | 15 | /* 16 | * Event tracking method 17 | */ 18 | fun track(event: Event, eventTracker: EventTracker? = null) 19 | } 20 | -------------------------------------------------------------------------------- /lib/src/main/java/com/raqun/gadget/lib/event/custom/CustomEvent.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.gadget.lib.event.custom 2 | 3 | import com.raqun.gadget.lib.event.AnalyticsEvent 4 | 5 | /* 6 | * Custom Event can be used to track custom events with initial params 7 | */ 8 | data class CustomEvent( 9 | override val name: String, 10 | private val initialParams: MutableMap = mutableMapOf() 11 | ) : AnalyticsEvent() { 12 | 13 | init { 14 | if (!initialParams.isNullOrEmpty()) { 15 | params.putAll(initialParams) 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /lib/src/main/java/com/raqun/gadget/lib/event/tab/TabSelectionEvent.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.gadget.lib.event.tab 2 | 3 | import com.raqun.gadget.lib.Constants 4 | import com.raqun.gadget.lib.event.AnalyticsEvent 5 | 6 | /* 7 | * Generic tab selection event to track tab selections in the app 8 | */ 9 | data class TabSelectionEvent( 10 | override val name: String = Constants.Event.TAB_SELECTION, 11 | private val tabName: String, 12 | private val tabPosition: Int 13 | ) : AnalyticsEvent() { 14 | 15 | init { 16 | params[Constants.Param.NAME] = tabName 17 | params[Constants.Param.POSITION] = tabPosition 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /lib/src/main/java/com/raqun/gadget/lib/tracker/impl/DefaultEventTracker.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.gadget.lib.tracker.impl 2 | 3 | import com.raqun.gadget.lib.event.Event 4 | import com.raqun.gadget.lib.tracker.EventTracker 5 | 6 | /* 7 | * Default Event Tracker 8 | * Used default while tracking events by Gadget. 9 | * By default all events are going to be tracked to Firebase 10 | */ 11 | open class DefaultEventTracker(private val firebaseEventTracker: EventTracker) : EventTracker { 12 | /* 13 | * Default event tracking method 14 | */ 15 | override fun track(event: Event) { 16 | firebaseEventTracker.track(event) 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /lib/src/main/java/com/raqun/gadget/lib/event/FirebaseEvent.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.gadget.lib.event 2 | 3 | import android.os.Bundle 4 | import com.raqun.gadget.lib.extensions.put 5 | 6 | /* 7 | * Firebase Event 8 | * Defines the events that will be tracked to Firebase Analytics 9 | */ 10 | interface FirebaseEvent : Event { 11 | /* 12 | * Converts the event to bundle to track Firebase Analytics 13 | */ 14 | fun toBundle(): Bundle { 15 | val bundle = Bundle() 16 | if (params.isNotEmpty()) { 17 | for (param in this.params) { 18 | bundle.put(param.key, param.value) 19 | } 20 | } 21 | 22 | return bundle 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /test-dependencies.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | testImplementation TestLibraries.jUnit 3 | androidTestImplementation TestLibraries.runnner 4 | androidTestImplementation TestLibraries.espressoCore 5 | debugImplementation TestLibraries.fragmentTesting 6 | androidTestImplementation TestLibraries.testRules 7 | androidTestImplementation TestLibraries.testCore 8 | androidTestImplementation TestLibraries.jUnitKtx 9 | androidTestImplementation TestLibraries.mockK 10 | testImplementation TestLibraries.truthExt 11 | testImplementation TestLibraries.truth 12 | testImplementation TestLibraries.mockK 13 | testImplementation TestLibraries.coreTesting 14 | testImplementation TestLibraries.robolectric 15 | } 16 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: Plugins.androidApplication 2 | apply from: "$rootDir/common.gradle" 3 | 4 | android { 5 | 6 | defaultConfig { 7 | applicationId Config.applicationId 8 | multiDexEnabled true 9 | vectorDrawables.useSupportLibrary = true 10 | } 11 | 12 | kotlinOptions { 13 | jvmTarget = Versions.jvmTargetVersion 14 | } 15 | 16 | androidExtensions { 17 | experimental = true 18 | } 19 | 20 | packagingOptions { 21 | exclude 'META-INF/lib_release.kotlin_module' 22 | } 23 | } 24 | 25 | dependencies { 26 | 27 | // Core 28 | implementation CoreLibraries.kotlin 29 | 30 | // Support Libraries 31 | implementation SupportLibraries.multidex 32 | implementation SupportLibraries.design 33 | } 34 | -------------------------------------------------------------------------------- /lib/src/main/java/com/raqun/gadget/lib/tracker/impl/FirebaseEventTracker.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.gadget.lib.tracker.impl 2 | 3 | import com.google.firebase.analytics.FirebaseAnalytics 4 | import com.raqun.gadget.lib.event.Event 5 | import com.raqun.gadget.lib.event.FirebaseEvent 6 | import com.raqun.gadget.lib.tracker.EventTracker 7 | 8 | /* 9 | * Firebase Event Tracker 10 | * If the given event is a Firebase event, event will be tracked to Firebase with 11 | * it's bundle implementation. 12 | */ 13 | open class FirebaseEventTracker(private val firebaseAnalytics: FirebaseAnalytics) : EventTracker { 14 | 15 | override fun track(event: Event) { 16 | if (event is FirebaseEvent) { 17 | firebaseAnalytics.logEvent(event.name, event.toBundle()) 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /lib/src/main/java/com/raqun/gadget/lib/event/view/ScreenViewEvent.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.gadget.lib.event.view 2 | 3 | import com.google.firebase.analytics.FirebaseAnalytics 4 | import com.raqun.gadget.lib.event.AnalyticsEvent 5 | 6 | /* 7 | * Firebase ScreenView Event 8 | * Screen Name is the name of the screen that is going to be tracked 9 | * Class Name is the name of the class that is going to be tracked 10 | */ 11 | data class ScreenViewEvent( 12 | val screenName: String, 13 | val className: String 14 | ) : AnalyticsEvent() { 15 | 16 | override val name: String = FirebaseAnalytics.Event.SCREEN_VIEW 17 | 18 | init { 19 | params[FirebaseAnalytics.Param.SCREEN_NAME] = this.screenName 20 | params[FirebaseAnalytics.Param.SCREEN_CLASS] = this.className 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/raqun/gadget/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.gadget 2 | 3 | import androidx.test.platform.app.InstrumentationRegistry 4 | import androidx.test.ext.junit.runners.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 22 | assertEquals("com.raqun.gadget", appContext.packageName) 23 | } 24 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /lib/src/main/java/com/raqun/gadget/lib/event/Event.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.gadget.lib.event 2 | 3 | /* 4 | * Event 5 | * Generic Event interface 6 | * Every event has a name and params 7 | */ 8 | interface Event { 9 | /* 10 | * Event name 11 | */ 12 | val name: String 13 | 14 | /* 15 | * Event parameters 16 | */ 17 | val params: MutableMap 18 | 19 | /* 20 | * Puts the parameter with the given key and value 21 | */ 22 | fun putParam(key: String, value: Any?) { 23 | params[key] = value 24 | } 25 | 26 | /* 27 | * Puts all the params git the given key and value 28 | */ 29 | fun putParams(params: Map) { 30 | if (!params.isNullOrEmpty()) { 31 | this.params.putAll(params) 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /lib/src/androidTest/java/com/raqun/gadget/lib/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.gadget.lib 2 | 3 | import androidx.test.platform.app.InstrumentationRegistry 4 | import androidx.test.ext.junit.runners.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 22 | assertEquals("com.raqun.gadget.lib.test", appContext.packageName) 23 | } 24 | } -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile -------------------------------------------------------------------------------- /lib/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile -------------------------------------------------------------------------------- /lib/src/main/java/com/raqun/gadget/lib/event/eec/ProductSelectionEvent.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.gadget.lib.event.eec 2 | 3 | import android.os.Bundle 4 | import com.google.firebase.analytics.FirebaseAnalytics 5 | import com.raqun.gadget.lib.model.Product 6 | import com.raqun.gadget.lib.event.AnalyticsEvent 7 | import com.raqun.gadget.lib.extensions.put 8 | import com.raqun.gadget.lib.extensions.toBundle 9 | import com.raqun.gadget.lib.extensions.toBundleList 10 | 11 | data class ProductSelectionEvent( 12 | override val name: String = FirebaseAnalytics.Event.SELECT_CONTENT, 13 | private val product: Product, 14 | private val itemListName: String 15 | ) : AnalyticsEvent(), EecEvent { 16 | 17 | override fun toBundle(): Bundle { 18 | return Bundle().apply { 19 | put(FirebaseAnalytics.Param.ITEMS, product.toBundle()) 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /app/src/main/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16 | -------------------------------------------------------------------------------- /app/src/main/res/values-night/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16 | -------------------------------------------------------------------------------- /lib/src/main/java/com/raqun/gadget/lib/event/eec/PromotionImpressionEvent.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.gadget.lib.event.eec 2 | 3 | import android.os.Bundle 4 | import com.raqun.gadget.lib.Constants 5 | import com.raqun.gadget.lib.model.Promotion 6 | import com.raqun.gadget.lib.event.AnalyticsEvent 7 | import com.raqun.gadget.lib.extensions.toBundleList 8 | 9 | /* 10 | * Promotion Impression Event 11 | * Measure promotion impressions by logging a VIEW_ITEM, VIEW_ITEM_LIST, 12 | * or VIEW_SEARCH_RESULTS event with a promotion item defined with the relevant fields: 13 | */ 14 | data class PromotionImpressionEvent( 15 | override val name: String, 16 | private val promotions: List 17 | ) : AnalyticsEvent(), EecEvent { 18 | 19 | override fun toBundle(): Bundle { 20 | return Bundle().apply { 21 | putParcelableArrayList(Constants.Param.POSITION, promotions.toBundleList()) 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /lib/src/main/java/com/raqun/gadget/lib/extensions/promotionExt.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.gadget.lib.extensions 2 | 3 | import android.os.Bundle 4 | import com.google.firebase.analytics.FirebaseAnalytics 5 | import com.raqun.gadget.lib.model.Promotion 6 | 7 | /* 8 | * Maps Promotion to Bundle 9 | */ 10 | fun Promotion.toBundleList(): Bundle { 11 | return Bundle().apply { 12 | put(FirebaseAnalytics.Param.ITEM_ID, id) 13 | put(FirebaseAnalytics.Param.ITEM_NAME, name) 14 | put(FirebaseAnalytics.Param.CREATIVE_NAME, creativeName) 15 | put(FirebaseAnalytics.Param.CREATIVE_SLOT, creativeSlot) 16 | } 17 | } 18 | 19 | /* 20 | * Maps the promotion list to bundle list 21 | */ 22 | fun List.toBundleList(): ArrayList { 23 | val promotionsBundle = ArrayList() 24 | this.forEach { 25 | promotionsBundle.add(it.toBundleList()) 26 | } 27 | 28 | return promotionsBundle 29 | } 30 | -------------------------------------------------------------------------------- /lib/src/main/java/com/raqun/gadget/lib/event/eec/ProductImpressionEvent.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.gadget.lib.event.eec 2 | 3 | import android.os.Bundle 4 | import com.google.firebase.analytics.FirebaseAnalytics 5 | import com.raqun.gadget.lib.model.Product 6 | import com.raqun.gadget.lib.event.AnalyticsEvent 7 | import com.raqun.gadget.lib.extensions.put 8 | import com.raqun.gadget.lib.extensions.toBundleList 9 | 10 | data class ProductImpressionEvent( 11 | override val name: String = FirebaseAnalytics.Event.VIEW_ITEM_LIST, 12 | private val products: List, 13 | private val itemListName: String 14 | ) : AnalyticsEvent(), EecEvent { 15 | 16 | override fun toBundle(): Bundle { 17 | return Bundle().apply { 18 | putParcelableArrayList( 19 | FirebaseAnalytics.Param.ITEMS, 20 | products.toBundleList(putIndex = true) 21 | ) 22 | put(FirebaseAnalytics.Param.ITEM_LIST_NAME, itemListName) 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /lib/src/main/java/com/raqun/gadget/lib/event/eec/AddToCartEvent.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.gadget.lib.event.eec 2 | 3 | import android.os.Bundle 4 | import com.google.firebase.analytics.FirebaseAnalytics 5 | import com.raqun.gadget.lib.model.Product 6 | import com.raqun.gadget.lib.event.AnalyticsEvent 7 | import com.raqun.gadget.lib.extensions.put 8 | import com.raqun.gadget.lib.extensions.toBundle 9 | 10 | /* 11 | * Add to Cart Event 12 | * Measure a product being added to a shopping cart by logging an ADD_TO_CART event 13 | * with an item (i.e. product) defined with the relevant fields. 14 | */ 15 | data class AddToCartEvent( 16 | override val name: String = FirebaseAnalytics.Event.ADD_TO_CART, 17 | private val product: Product, 18 | private val quantity: Long = 1 19 | ) : AnalyticsEvent(), EecEvent { 20 | 21 | override fun toBundle(): Bundle { 22 | return Bundle().apply { 23 | put(FirebaseAnalytics.Param.ITEMS, product.toBundle(quantity)) 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /lib/src/main/java/com/raqun/gadget/lib/event/eec/BeginCheckoutEvent.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.gadget.lib.event.eec 2 | 3 | import android.os.Bundle 4 | import com.google.firebase.analytics.FirebaseAnalytics 5 | import com.raqun.gadget.lib.model.Product 6 | import com.raqun.gadget.lib.event.AnalyticsEvent 7 | import com.raqun.gadget.lib.extensions.put 8 | import com.raqun.gadget.lib.extensions.toBundleList 9 | 10 | /* 11 | * Begin checkout 12 | * Measure the first step in a checkout process by logging a BEGIN_CHECKOUT event 13 | * with one or more items (i.e. products) defined with the relevant fields. 14 | */ 15 | data class BeginCheckoutEvent( 16 | override val name: String = FirebaseAnalytics.Event.BEGIN_CHECKOUT, 17 | private val products: List 18 | ) : AnalyticsEvent(), EecEvent { 19 | 20 | override fun toBundle(): Bundle { 21 | return Bundle().apply { 22 | putParcelableArrayList(FirebaseAnalytics.Param.ITEMS, products.toBundleList()) 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /lib/src/main/java/com/raqun/gadget/lib/event/eec/ProductDetailViewEvent.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.gadget.lib.event.eec 2 | 3 | import android.os.Bundle 4 | import com.google.firebase.analytics.FirebaseAnalytics 5 | import com.raqun.gadget.lib.model.Product 6 | import com.raqun.gadget.lib.event.AnalyticsEvent 7 | import com.raqun.gadget.lib.extensions.put 8 | import com.raqun.gadget.lib.extensions.toBundle 9 | import com.raqun.gadget.lib.extensions.toBundleList 10 | 11 | /* 12 | * Product Detail View Event 13 | * Measure product detail views by logging a VIEW_ITEM event 14 | * with an item (i.e. product) defined with the relevant fields: 15 | */ 16 | data class ProductDetailViewEvent( 17 | override val name: String = FirebaseAnalytics.Event.VIEW_ITEM, 18 | private val product: Product 19 | ) : AnalyticsEvent(), EecEvent { 20 | 21 | override fun toBundle(): Bundle { 22 | return Bundle().apply { 23 | put(FirebaseAnalytics.Param.ITEMS, product.toBundle()) 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /lib/src/main/java/com/raqun/gadget/lib/event/eec/RemoveFromCartEvent.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.gadget.lib.event.eec 2 | 3 | import android.os.Bundle 4 | import com.google.firebase.analytics.FirebaseAnalytics 5 | import com.raqun.gadget.lib.event.AnalyticsEvent 6 | import com.raqun.gadget.lib.extensions.put 7 | import com.raqun.gadget.lib.extensions.toBundle 8 | import com.raqun.gadget.lib.extensions.toBundleList 9 | import com.raqun.gadget.lib.model.Product 10 | 11 | /* 12 | * Remove from Cart Event 13 | * Measure a product being removed from a shopping cart by logging a REMOVE_FROM_CART event 14 | * with an item (i.e. product) defined with the relevant fields: 15 | */ 16 | data class RemoveFromCartEvent( 17 | override val name: String = FirebaseAnalytics.Event.REMOVE_FROM_CART, 18 | private val product: Product, 19 | private val quantity: Long = 1 20 | ) : AnalyticsEvent(), EecEvent { 21 | 22 | override fun toBundle(): Bundle { 23 | return Bundle().apply { 24 | put(FirebaseAnalytics.Param.ITEMS, product.toBundle(quantity)) 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /lib/src/main/java/com/raqun/gadget/lib/Constants.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.gadget.lib 2 | 3 | /* 4 | * Contains the Gadget Library Constants 5 | */ 6 | class Constants private constructor() { 7 | /* 8 | * Contains generic event names 9 | */ 10 | object Event { 11 | const val CLICK = "click" 12 | const val FOCUS_IN = "focus_in" 13 | const val FOCUS_OUT = "focus_out" 14 | const val SWITCH = "switch" 15 | const val TAB_SELECTION = "tab_selection" 16 | 17 | object Error { 18 | const val API_ERROR = "api_error" 19 | const val BUSINESS_ERROR = "business_error" 20 | } 21 | } 22 | 23 | /* 24 | * Contains parameter names 25 | */ 26 | object Param { 27 | const val NAME = "name" 28 | const val POSITION = "position" 29 | const val CODE = "code" 30 | const val MESSAGE = "message" 31 | const val TYPE = "type" 32 | const val SCREEN_NAME = "screen_name" 33 | const val ENDPOINT = "endpoint" 34 | const val CLASS_NAME = "class_name" 35 | const val IS_VALID = "is_Valid" 36 | const val STATUS = "status" 37 | const val PROMOTIONS = "promotions" 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /lib/src/main/java/com/raqun/gadget/lib/event/eec/PromotionSelectionEvent.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.gadget.lib.event.eec 2 | 3 | import android.os.Bundle 4 | import com.google.firebase.analytics.FirebaseAnalytics 5 | import com.raqun.gadget.lib.Constants 6 | import com.raqun.gadget.lib.event.AnalyticsEvent 7 | import com.raqun.gadget.lib.extensions.put 8 | import com.raqun.gadget.lib.extensions.toBundleList 9 | import com.raqun.gadget.lib.model.Promotion 10 | 11 | /* 12 | * Promotion clicks/selections 13 | * Measure promotion clicks by logging a SELECT_CONTENT event 14 | * with a promotion defined with the relevant fields: 15 | */ 16 | data class PromotionSelectionEvent( 17 | override val name: String = FirebaseAnalytics.Event.SELECT_CONTENT, 18 | private val promotions: List, 19 | private val promotionId: String, 20 | private val contentType: String 21 | ) : AnalyticsEvent(), EecEvent { 22 | 23 | override fun toBundle(): Bundle { 24 | return Bundle().apply { 25 | putParcelableArrayList(Constants.Param.PROMOTIONS, promotions.toBundleList()) 26 | put(FirebaseAnalytics.Param.ITEM_ID, promotionId) 27 | put(FirebaseAnalytics.Param.CONTENT_TYPE, contentType) 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app"s APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Automatically convert third-party libraries to use AndroidX 19 | android.enableJetifier=true 20 | # Kotlin code style for this project: "official" or "obsolete": 21 | kotlin.code.style=official -------------------------------------------------------------------------------- /lib/src/main/java/com/raqun/gadget/lib/event/eec/RefundEvent.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.gadget.lib.event.eec 2 | 3 | import android.os.Bundle 4 | import com.google.firebase.analytics.FirebaseAnalytics 5 | import com.raqun.gadget.lib.event.AnalyticsEvent 6 | import com.raqun.gadget.lib.extensions.put 7 | import com.raqun.gadget.lib.extensions.toBundleList 8 | import com.raqun.gadget.lib.model.RefundedProduct 9 | 10 | /* 11 | * Refunds 12 | * Measure refunds by logging a PURCHASE_REFUND event with the relevant transaction ID specified, 13 | * and optionally (for partial refunds) one or more items 14 | * (i.e. products) defined with item IDs and quantities. 15 | */ 16 | data class RefundEvent( 17 | override val name: String = FirebaseAnalytics.Event.REFUND, 18 | private val products: List? = null, 19 | private val transactionId: String, 20 | private val value: Double 21 | ) : AnalyticsEvent(), EecEvent { 22 | 23 | override fun toBundle(): Bundle { 24 | return Bundle().apply { 25 | products?.let { refundedProducts -> 26 | putParcelableArrayList( 27 | FirebaseAnalytics.Param.ITEMS, 28 | refundedProducts.toBundleList() 29 | ) 30 | } 31 | put(FirebaseAnalytics.Param.TRANSACTION_ID, transactionId) 32 | put(FirebaseAnalytics.Param.VALUE, value) 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /lib/src/main/java/com/raqun/gadget/lib/tracker/ListItemImpressionTracker.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.gadget.lib.tracker 2 | 3 | import androidx.arch.core.util.Function 4 | 5 | /* 6 | * List Item Impression Tracker 7 | * Used for tracking impression or selection of items in a list 8 | * Measure product impressions by logging event with an ITEM_LIST parameter 9 | * and one or more items (i.e. products) defined with the relevant fields. 10 | */ 11 | interface ListItemImpressionTracker { 12 | /* 13 | * Tracker 14 | */ 15 | val analyticsTracker: AnalyticsTracker 16 | 17 | /* 18 | * Contains viewed items 19 | */ 20 | val viewedItems: MutableSet 21 | 22 | /* 23 | * Function to track item impression 24 | * Call when item is viewed 25 | */ 26 | fun addImpression(item: T) { 27 | viewedItems.add(item) 28 | } 29 | 30 | /* 31 | * Function to track item impression with a mapper 32 | * Call when item is viewed 33 | */ 34 | fun addImpression(item: Any?, mapper: Function) { 35 | item?.let { 36 | viewedItems.add(mapper.apply(it)) 37 | } 38 | } 39 | 40 | /* 41 | * Tracks selection of an item in a list 42 | * Measure product clicks by logging a SELECT_CONTENT event 43 | * with an item (i.e. product) defined with the relevant fields: 44 | */ 45 | fun trackItemSelection(item: T) 46 | 47 | /* 48 | * Tracks the item impression 49 | */ 50 | fun trackImpression() 51 | } 52 | -------------------------------------------------------------------------------- /lib/src/main/java/com/raqun/gadget/lib/event/eec/PurchaseEvent.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.gadget.lib.event.eec 2 | 3 | import android.os.Bundle 4 | import com.google.firebase.analytics.FirebaseAnalytics 5 | import com.raqun.gadget.lib.event.AnalyticsEvent 6 | import com.raqun.gadget.lib.extensions.put 7 | import com.raqun.gadget.lib.extensions.toBundleList 8 | import com.raqun.gadget.lib.model.Product 9 | 10 | /* 11 | * Purchases 12 | * Measure purchases by logging an ECOMMERCE_PURCHASE event 13 | * with one or more items (i.e. products) defined with the relevant fields. 14 | */ 15 | data class PurchaseEvent( 16 | override val name: String = FirebaseAnalytics.Event.PURCHASE, 17 | private val products: List, 18 | private val transactionId: String, 19 | private val affiliation: String, 20 | private val value: Double, 21 | private val tax: Double, 22 | private val shipping: Double, 23 | private val currency: String, 24 | private val coupon: String 25 | ) : AnalyticsEvent(), EecEvent { 26 | 27 | override fun toBundle(): Bundle { 28 | return Bundle().apply { 29 | putParcelableArrayList(FirebaseAnalytics.Param.ITEMS, products.toBundleList()) 30 | put(FirebaseAnalytics.Param.TRANSACTION_ID, transactionId) 31 | put(FirebaseAnalytics.Param.AFFILIATION, affiliation) 32 | put(FirebaseAnalytics.Param.VALUE, value) 33 | put(FirebaseAnalytics.Param.TAX, tax) 34 | put(FirebaseAnalytics.Param.SHIPPING, shipping) 35 | put(FirebaseAnalytics.Param.CURRENCY, currency) 36 | put(FirebaseAnalytics.Param.COUPON, coupon) 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /lib/src/main/java/com/raqun/gadget/lib/extensions/bundleExt.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Contains extensions about Bundle operations 3 | */ 4 | package com.raqun.gadget.lib.extensions 5 | 6 | import android.os.Bundle 7 | import android.os.Parcelable 8 | import com.google.firebase.analytics.FirebaseAnalytics 9 | import java.io.Serializable 10 | import java.util.Date 11 | 12 | /* 13 | * Puts the value with the given key to a Budnle 14 | */ 15 | fun Bundle.put(key: String, value: T?) { 16 | 17 | // by default null values is not sending to Firebase 18 | if (value == null) return 19 | 20 | when (value) { 21 | is Boolean -> putBoolean(key, value) 22 | is String -> putString(key, value) 23 | is Int -> putInt(key, value) 24 | is Short -> putShort(key, value) 25 | is Long -> putLong(key, value) 26 | is Byte -> putByte(key, value) 27 | is ByteArray -> putByteArray(key, value) 28 | is Char -> putChar(key, value) 29 | is CharArray -> putCharArray(key, value) 30 | is CharSequence -> putCharSequence(key, value) 31 | is Float -> putFloat(key, value) 32 | is Bundle -> putBundle(key, value) 33 | is Parcelable -> putParcelable(key, value) 34 | is Serializable -> putSerializable(key, value) 35 | is Date -> putSerializable(key, value) 36 | is Enum<*> -> putString(key, value.name) 37 | else -> throw IllegalStateException("Type of property with the given $key is not supported!") 38 | } 39 | } 40 | 41 | /* 42 | * Puts Index to the bundle 43 | */ 44 | fun Bundle.putIndex(index: Long): Bundle { 45 | put(FirebaseAnalytics.Param.INDEX, index) 46 | return this 47 | } 48 | -------------------------------------------------------------------------------- /lib/src/main/java/com/raqun/gadget/lib/Gadget.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.gadget.lib 2 | 3 | import android.content.Context 4 | import com.google.firebase.analytics.FirebaseAnalytics 5 | import com.raqun.gadget.lib.event.Event 6 | import com.raqun.gadget.lib.tracker.AnalyticsTracker 7 | import com.raqun.gadget.lib.tracker.impl.DefaultEventTracker 8 | import com.raqun.gadget.lib.tracker.EventTracker 9 | import com.raqun.gadget.lib.tracker.impl.FirebaseEventTracker 10 | 11 | /* 12 | * Gadget is a customizable analytics tracking tool 13 | */ 14 | object Gadget : AnalyticsTracker { 15 | /* 16 | * Default Event Tracker 17 | * Will be used by default while tracking events 18 | */ 19 | private lateinit var defaultEventTracker: EventTracker 20 | 21 | /* 22 | * Call once in your application class to setup Gadget 23 | */ 24 | @Synchronized 25 | override fun setup(context: Context, customEventTracker: EventTracker?) { 26 | defaultEventTracker = if (customEventTracker != null) { 27 | customEventTracker 28 | } else { 29 | val firebaseEventTracker: EventTracker = 30 | FirebaseEventTracker(FirebaseAnalytics.getInstance(context.applicationContext)) 31 | DefaultEventTracker(firebaseEventTracker) 32 | } 33 | } 34 | 35 | /* 36 | * Track method to track events 37 | * Event tracker parameter is null by default. 38 | * If event tracker parameter is null the default event tracker will be used 39 | * for tracking events. 40 | */ 41 | override fun track(event: Event, eventTracker: EventTracker?) { 42 | eventTracker?.track(event) ?: defaultEventTracker.track(event) 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | -------------------------------------------------------------------------------- /lib/src/main/java/com/raqun/gadget/lib/event/error/ErrorEvent.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.gadget.lib.event.error 2 | 3 | import com.raqun.gadget.lib.Constants 4 | import com.raqun.gadget.lib.event.AnalyticsEvent 5 | 6 | /* 7 | * Generic Error Event to catch and log the errors in the app 8 | */ 9 | sealed class ErrorEvent( 10 | private val code: String, 11 | private val message: String, 12 | private val type: String?, 13 | ) : AnalyticsEvent() { 14 | 15 | init { 16 | params[Constants.Param.CODE] = code 17 | params[Constants.Param.MESSAGE] = message 18 | params[Constants.Param.TYPE] = type 19 | } 20 | 21 | /* 22 | * Generic Api Error event to log api errors in the app 23 | */ 24 | data class ApiErrorEvent( 25 | override val name: String = Constants.Event.Error.API_ERROR, 26 | private val code: String, 27 | private val message: String, 28 | private val screenName: String? = null, 29 | private val type: String? = ApiErrorEvent::class.simpleName, 30 | private val endpoint: String? = null 31 | ) : ErrorEvent( 32 | code = code, 33 | message = message, 34 | type = type 35 | ) { 36 | init { 37 | params[Constants.Param.ENDPOINT] = endpoint 38 | params[Constants.Param.SCREEN_NAME] = screenName 39 | } 40 | } 41 | 42 | /* 43 | * Generic Business Error event to track errors in business layer 44 | */ 45 | data class BusinessErrorEvent( 46 | override val name: String = Constants.Event.Error.BUSINESS_ERROR, 47 | private val code: String, 48 | private val message: String, 49 | private val type: String? = BusinessErrorEvent::class.simpleName, 50 | ) : ErrorEvent( 51 | code = code, 52 | message = message, 53 | type = type 54 | ) 55 | } 56 | -------------------------------------------------------------------------------- /common.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: Plugins.kotlinAndroid 2 | apply plugin: Plugins.kotlinAndroidExtensions 3 | apply plugin: Plugins.kotlinKapt 4 | apply from: "$rootDir/test-dependencies.gradle" 5 | 6 | android { 7 | compileSdkVersion Config.compileSdkVersion 8 | buildToolsVersion Config.buildToolsVersion 9 | 10 | defaultConfig { 11 | versionName Config.versionName 12 | versionCode Config.versionCode 13 | minSdkVersion Config.minSdkVersion 14 | targetSdkVersion Config.targetSdkVersion 15 | minSdkVersion Config.minSdkVersion 16 | targetSdkVersion Config.targetSdkVersion 17 | testInstrumentationRunner Config.testInstrumentationRunner 18 | } 19 | 20 | compileOptions { 21 | sourceCompatibility Versions.sourceCompatibilityVersion 22 | targetCompatibility Versions.targetCompatibilityVersion 23 | } 24 | 25 | buildTypes { 26 | release { 27 | minifyEnabled false 28 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 29 | } 30 | 31 | debug { 32 | // no-op 33 | } 34 | } 35 | 36 | lintOptions { 37 | abortOnError false 38 | } 39 | 40 | testOptions { 41 | unitTests { 42 | includeAndroidResources = true 43 | } 44 | } 45 | } 46 | 47 | dependencies { 48 | implementation CoreLibraries.kotlin 49 | compileOnly Libraries.javaxAnnotation 50 | } 51 | 52 | configurations.all { 53 | resolutionStrategy.eachDependency { DependencyResolveDetails details -> 54 | def requested = details.requested 55 | if (requested.group == 'org.jetbrains.kotlin') { 56 | details.useVersion Versions.kotlinVersion 57 | } else if (requested.group == 'com.android.support') { 58 | details.useVersion Versions.appCompatVersion 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /lib/src/main/java/com/raqun/gadget/lib/extensions/productExt.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.gadget.lib.extensions 2 | 3 | import android.os.Bundle 4 | import com.google.firebase.analytics.FirebaseAnalytics 5 | import com.raqun.gadget.lib.model.Product 6 | import com.raqun.gadget.lib.model.RefundedProduct 7 | 8 | /* 9 | * Puts product to a bundle for logging to Firebase 10 | */ 11 | fun Product.toBundle(q: Long? = null): Bundle { 12 | return Bundle().apply { 13 | put(FirebaseAnalytics.Param.ITEM_ID, id) 14 | put(FirebaseAnalytics.Param.ITEM_NAME, name) 15 | put(FirebaseAnalytics.Param.ITEM_CATEGORY, category) 16 | put(FirebaseAnalytics.Param.ITEM_BRAND, brand) 17 | put(FirebaseAnalytics.Param.PRICE, price) 18 | put(FirebaseAnalytics.Param.CURRENCY, currency) 19 | put(FirebaseAnalytics.Param.ITEM_VARIANT, variant) 20 | put(FirebaseAnalytics.Param.QUANTITY, quantity ?: q) 21 | } 22 | } 23 | 24 | /* 25 | * Puts list of products to a bundle 26 | */ 27 | fun List.toBundleList(putIndex: Boolean = false): ArrayList { 28 | val productBundleList = ArrayList() 29 | this.forEachIndexed { index, product -> 30 | val productBundle = product.toBundle() 31 | if (putIndex) { 32 | productBundle.putIndex(index.toLong()) 33 | } 34 | productBundleList.add(productBundle) 35 | } 36 | return productBundleList 37 | } 38 | 39 | /* 40 | * Puts refunded product to bundle 41 | */ 42 | fun RefundedProduct.toBundle(): Bundle { 43 | return Bundle().apply { 44 | put(FirebaseAnalytics.Param.ITEM_ID, id) 45 | put(FirebaseAnalytics.Param.QUANTITY, quantity) 46 | } 47 | } 48 | 49 | /* 50 | * Puts list of refunded products into bundle 51 | */ 52 | fun List.toBundleList(): ArrayList { 53 | val refundedProductBundleList = ArrayList() 54 | this.forEach { 55 | refundedProductBundleList.add(it.toBundle()) 56 | } 57 | return refundedProductBundleList 58 | } -------------------------------------------------------------------------------- /lib/src/main/java/com/raqun/gadget/lib/tracker/impl/EecProductImpressionTracker.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.gadget.lib.tracker.impl 2 | 3 | import androidx.lifecycle.Lifecycle 4 | import androidx.lifecycle.LifecycleObserver 5 | import androidx.lifecycle.OnLifecycleEvent 6 | import com.google.firebase.analytics.FirebaseAnalytics 7 | import com.raqun.gadget.lib.Gadget 8 | import com.raqun.gadget.lib.event.eec.ProductImpressionEvent 9 | import com.raqun.gadget.lib.event.eec.ProductSelectionEvent 10 | import com.raqun.gadget.lib.model.Product 11 | import com.raqun.gadget.lib.tracker.AnalyticsTracker 12 | import com.raqun.gadget.lib.tracker.ListItemImpressionTracker 13 | import com.raqun.gadget.lib.tracker.LifecycleEventTracker 14 | 15 | /* 16 | * EEC Product Impression Tracker 17 | * Can be used to track product impressions and selections for EEC 18 | */ 19 | class EecProductImpressionTracker( 20 | override val lifeCycle: Lifecycle, 21 | override val viewedItems: LinkedHashSet = linkedSetOf(), 22 | override val analyticsTracker: AnalyticsTracker = Gadget, 23 | private val eventName: String = FirebaseAnalytics.Event.VIEW_ITEM_LIST, 24 | private val listName: String 25 | ) : ListItemImpressionTracker, 26 | LifecycleObserver, 27 | LifecycleEventTracker { 28 | 29 | init { 30 | lifeCycle.addObserver(this) 31 | } 32 | 33 | override fun trackItemSelection(item: Product) { 34 | val selectionEvent = ProductSelectionEvent( 35 | product = item, 36 | itemListName = listName 37 | ) 38 | analyticsTracker.track(selectionEvent) 39 | } 40 | 41 | @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE) 42 | override fun trackImpression() { 43 | if (viewedItems.isNullOrEmpty()) return 44 | val productImpressionEvent = ProductImpressionEvent( 45 | name = eventName, 46 | itemListName = listName, 47 | products = viewedItems.toList() 48 | ) 49 | analyticsTracker.track(productImpressionEvent) 50 | viewedItems.clear() 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /lib/src/main/java/com/raqun/gadget/lib/tracker/impl/EecPromotionImpressionTracker.kt: -------------------------------------------------------------------------------- 1 | package com.raqun.gadget.lib.tracker.impl 2 | 3 | import androidx.lifecycle.Lifecycle 4 | import androidx.lifecycle.LifecycleObserver 5 | import androidx.lifecycle.OnLifecycleEvent 6 | import com.raqun.gadget.lib.Gadget 7 | import com.raqun.gadget.lib.event.eec.PromotionImpressionEvent 8 | import com.raqun.gadget.lib.event.eec.PromotionSelectionEvent 9 | import com.raqun.gadget.lib.model.Promotion 10 | import com.raqun.gadget.lib.tracker.AnalyticsTracker 11 | import com.raqun.gadget.lib.tracker.LifecycleEventTracker 12 | import com.raqun.gadget.lib.tracker.ListItemImpressionTracker 13 | 14 | /* 15 | * EEC Promotion Impression Tracker 16 | * Can be used to track promotion impressions and selections for EEC 17 | */ 18 | class EecPromotionImpressionTracker( 19 | override val lifeCycle: Lifecycle, 20 | override val analyticsTracker: AnalyticsTracker = Gadget, 21 | override val viewedItems: LinkedHashSet = linkedSetOf(), 22 | private val eventName: String, 23 | private val contentType: String, 24 | ) : ListItemImpressionTracker, 25 | LifecycleObserver, 26 | LifecycleEventTracker { 27 | 28 | init { 29 | lifeCycle.addObserver(this) 30 | } 31 | 32 | override fun trackItemSelection(item: Promotion) { 33 | val promotions = ArrayList() 34 | promotions.add(item) 35 | 36 | val promotionSelectionEvent = PromotionSelectionEvent( 37 | promotions = promotions, 38 | promotionId = item.id, 39 | contentType = contentType 40 | ) 41 | 42 | analyticsTracker.track(promotionSelectionEvent) 43 | } 44 | 45 | @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE) 46 | override fun trackImpression() { 47 | if (viewedItems.isNullOrEmpty()) return 48 | val promotionImpressionEvent = PromotionImpressionEvent( 49 | name = eventName, 50 | promotions = viewedItems.toList() 51 | ) 52 | analyticsTracker.track(promotionImpressionEvent) 53 | viewedItems.clear() 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Gadget 2 | **Gadget** is a library that aims to _make analytics event tracking_ **more reliable** and **configurable**.
3 | 4 | ### Problems to solve 5 | Here're a few problems that **Gadget** tries to solve. 6 | 7 | 1. Managing the tracking of the events to n platforms from a single point. 8 | 2. Adding or removing an analytics plafrom easily 9 | 3. Configuring of event tracking for different screens or conditions. 10 | 4. Google Enhanced Ecommerce implementation easier. 11 | 12 | ### How to use? 13 | First you need to setup **Gadget** in your **application**. 14 | ```KOTLIN 15 | class MyAwesomeApp : Application() { 16 | 17 | override fun onCreate() { 18 | super.onCreate() 19 | Gadget.setup(this) 20 | // .. other stuff 21 | } 22 | } 23 | ``` 24 | By default **Gadget** uses it's own tracker which is called ```DefaultEventTracker``` and tracks to **Firebase Analytics** by default. 25 | ```KOTLIN 26 | open class DefaultEventTracker(private val firebaseEventTracker: EventTracker) : EventTracker { 27 | ``` 28 | To customize the event tracking in your app, you can define your own tracker by implementing **EventTracker** 29 | ```KOTLIN 30 | interface EventTracker { 31 | /* 32 | * Tracking function 33 | * Tracks the given event 34 | */ 35 | fun track(event: Event) 36 | } 37 | ``` 38 | 39 | After creating your custom event tracker, you can pass it to Gadget and use **your own tracker**. 40 | ```KOTLIN 41 | Gadget.setup(this,myAwesomeCustomEventTracker) 42 | ``` 43 | 44 | Secondly, you should create **your own events** or you can use directly **Gadget's pre-defined events**. Your own events should impement Gadget's ```Event``` interface. 45 | ```KOTLIN 46 | /* 47 | * Event 48 | * Generic Event interface 49 | * Every event has a name and params 50 | */ 51 | interface Event 52 | ``` 53 | If this event will be tracked to Firebase Analytics as well, you should implementd Gadget's ```FirebaseEvent``` interface. This interface has a default ```bundle``` implementation and you can override this bundle conversion anytime you want in your own event. (You can notice that some predefined **EEC events** has different ```bundle``` conversions.) 54 | ```KOTLIN 55 | /* 56 | * Firebase Event 57 | * Defines the events that will be tracked to Firebase Analytics 58 | */ 59 | interface FirebaseEvent : Event { 60 | /* 61 | * Converts the event to bundle to track Firebase Analytics 62 | */ 63 | fun toBundle(): Bundle { 64 | val bundle = Bundle() 65 | if (params.isNotEmpty()) { 66 | for (param in this.params) { 67 | bundle.put(param.key, param.value) 68 | } 69 | } 70 | 71 | return bundle 72 | } 73 | } 74 | ``` 75 | 76 | Instead of implementing your own events, you can directly use **Gadget's** ```CustomEvent``` for event tracking. 77 | ```KOTLIN 78 | val addEvent = CustomEvent("content_add") 79 | addEvent.putParam("type", "message") 80 | ``` 81 | 82 | And finally, you can track your event with ```Gadget``` 83 | ```KOTLIN 84 | Gadget.track(addEvent) 85 | ``` 86 | 87 | IF you want to change the event tracking strategy for a single event specifically **Gadget's track method** takes ```EventTracker``` as parameter and if you pass a different event tracker, your event will be tracked with that implementation. 88 | 89 | ### Gadget's Google Analytics Enhanced Ecommerce Support 90 | Google Analytics Enhanced Ecommerce reporting allows you to collect data related to ecommerce transactions: item data, impression data, product data, promotion data, and action data. This information gives you a snapshot of your company’s health by providing an overarching view of how visitors interact with your ecommerce website. [Source and more information here](https://thegood.com/insights/google-analytics-enhanced-ecommerce/) 91 | 92 | Gadget has it's own impression trackers can be used for EEC impression tracking. You can use ```EecProductImpressionTracker``` for product impression tracking and 93 | ```EecPromotionImpressionTracker``` for tracking your promotions. These trackers both implements **Gadget's** ```ListItemImpressionTracker``` and ```LifecycleEventTracker``` implements to handle impression tracking in a with **lifecycle events**. 94 | 95 | To collect the impressions, you can use ```addImpression``` method of ```ListItemImpressionTracker``` 96 | ```KOTLIN 97 | /* 98 | * Function to track item impression 99 | * Call when item is viewed 100 | */ 101 | fun addImpression(item: T) { 102 | viewedItems.add(item) 103 | } 104 | 105 | /* 106 | * Function to track item impression with a mapper 107 | * Call when item is viewed 108 | */ 109 | fun addImpression(item: Any?, mapper: Function) { 110 | item?.let { 111 | viewedItems.add(mapper.apply(it)) 112 | } 113 | } 114 | ``` 115 | 116 | To track an item selection, you can use ```trackItemSelection``` method of ```ListItemImpressionTracker``` 117 | ```KOTLIN 118 | /* 119 | * Tracks selection of an item in a list 120 | * Measure product clicks by logging a SELECT_CONTENT event 121 | * with an item (i.e. product) defined with the relevant fields: 122 | */ 123 | fun trackItemSelection(item: T) 124 | ``` 125 | 126 | And finally, **Gadget's** ```EecProductImpressionTracker``` will track the collected impressions ```@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)``` 127 | 128 | **Note:** You can notice that there're some out dated classes and implementations for **EEC support**. **Google Analytics 4 migration** is still on going and i'm trying to understand and replace these deprecated classes with the GA 4 implementations. 129 | 130 | ### Dependency
131 | ``` 132 | allprojects { 133 | repositories { 134 | ... 135 | maven { url 'https://jitpack.io' } 136 | } 137 | } 138 | ``` 139 | ``` 140 | dependencies { 141 | implementation 'com.github.savepopulation:gadget:1.0.2' 142 | } 143 | ``` 144 | 145 | ### Apps Using Gadget on Production 146 | [Phone Box](https://play.google.com/store/apps/details?id=com.raqun.phonebox)
147 | 148 | * __Please send me an email if you're using Gaget on production and want to be in the list.__ 149 | 150 | ### WHere Gadget comes from? 151 | ![alt text](/art/gadget.jpeg)

152 | [Inspector Gadget](https://en.wikipedia.org/wiki/Inspector_Gadget)
153 | [Watch this](https://www.youtube.com/watch?v=rIc13VjeAw8) 154 | 155 | ### License 156 | ``` 157 | Copyright 2021 Taylan SABIRCAN 158 | 159 | Licensed under the Apache License, Version 2.0 (the "License"); 160 | you may not use this file except in compliance with the License. 161 | You may obtain a copy of the License at 162 | 163 | http://www.apache.org/licenses/LICENSE-2.0 164 | 165 | Unless required by applicable law or agreed to in writing, software 166 | distributed under the License is distributed on an "AS IS" BASIS, 167 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 168 | See the License for the specific language governing permissions and 169 | limitations under the License. 170 | ``` 171 | 172 | 173 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2021 Taylan SABIRCAN 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------