Skip to content

Commit

Permalink
Merge pull request #165 from appunite/feature/analytics
Browse files Browse the repository at this point in the history
[LD-136] Firebase analytics
  • Loading branch information
nowakweronika authored Nov 21, 2023
2 parents 28846e2 + 71d40c6 commit 3df5b95
Show file tree
Hide file tree
Showing 16 changed files with 530 additions and 12 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/run-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ jobs:
with:
lfs: true

- name: create-json
id: create-json
uses: jsdaniell/[email protected]
with:
name: "app/google-services.json"
json: ${{ secrets.GOOGLE_SERVICES_JSON }}

- name: Add google-services.json
env:
GOOGLE_SERVICES_JSON: ${{ secrets.GOOGLE_SERVICES_JSON }}
run: echo "$GOOGLE_SERVICES_JSON" | base64 --decode > app/google-services.json

- name: Prepare Android Environment
uses: ./.github/actions/prepare-android-env

Expand Down Expand Up @@ -81,6 +93,11 @@ jobs:
with:
lfs: true

- name: Add google-services.json
env:
GOOGLE_SERVICES_JSON: ${{ secrets.GOOGLE_SERVICES_JSON }}
run: echo "$GOOGLE_SERVICES_JSON" | base64 --decode > app/google-services.json

- name: LFS-warning - Prevent large files that are not LFS tracked
uses: ppremk/[email protected]

Expand Down
10 changes: 10 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ plugins {
id 'org.jetbrains.kotlin.plugin.serialization' version '1.9.0'
}

def fileName = "../app/google-services.json"

if (project.file(fileName).exists()) {
apply plugin: 'com.google.gms.google-services'
}

java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
Expand Down Expand Up @@ -206,6 +212,10 @@ dependencies {

// ktlint
ktlintRuleset project(":custom-ktlint-rules")

// Firebase
implementation(platform("com.google.firebase:firebase-bom:32.4.0"))
implementation("com.google.firebase:firebase-analytics-ktx")
}

tasks.withType(Test) {
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/com/appunite/loudius/LoudiusApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.appunite.loudius

import android.app.Application
import com.appunite.loudius.di.analyticsModule
import com.appunite.loudius.di.dataSourceModule
import com.appunite.loudius.di.dispatcherModule
import com.appunite.loudius.di.githubHelperModule
Expand All @@ -36,7 +37,8 @@ val appModule = module {
serviceModule,
repositoryModule,
githubHelperModule,
dispatcherModule
dispatcherModule,
analyticsModule
)
}

Expand Down
22 changes: 22 additions & 0 deletions app/src/main/java/com/appunite/loudius/analytics/Event.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright 2023 AppUnite S.A.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.appunite.loudius.analytics

interface Event {
val name: String
val parameters: List<EventParameter>
}
24 changes: 24 additions & 0 deletions app/src/main/java/com/appunite/loudius/analytics/EventParameter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright 2023 AppUnite S.A.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.appunite.loudius.analytics

sealed class EventParameter {
abstract val name: kotlin.String

data class String(override val name: kotlin.String, val value: kotlin.String) : EventParameter()
data class Boolean(override val name: kotlin.String, val value: kotlin.Boolean) : EventParameter()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2023 AppUnite S.A.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.appunite.loudius.analytics

import android.os.Bundle

class EventParametersConverter {

fun convert(parameters: List<EventParameter>): Bundle {
val bundle = Bundle()
for (parameter in parameters) {
when (parameter) {
is EventParameter.String -> bundle.putString(parameter.name, parameter.value)
is EventParameter.Boolean -> bundle.putBoolean(parameter.name, parameter.value)
}
}
return bundle
}
}
34 changes: 34 additions & 0 deletions app/src/main/java/com/appunite/loudius/analytics/EventTracker.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2023 AppUnite S.A.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.appunite.loudius.analytics

import com.google.firebase.analytics.FirebaseAnalytics

interface EventTracker {

fun trackEvent(event: Event)
}

class FirebaseAnalyticsEventTracker(
private val firebaseAnalytics: FirebaseAnalytics,
private val converter: EventParametersConverter
) : EventTracker {

override fun trackEvent(event: Event) {
firebaseAnalytics.logEvent(event.name, converter.convert(event.parameters))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Copyright 2023 AppUnite S.A.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.appunite.loudius.analytics.events

import com.appunite.loudius.analytics.Event
import com.appunite.loudius.analytics.EventParameter

interface ReviewersEvent : Event

object ClickNotifyEvent : ReviewersEvent {
override val name: String = "button_click"
override val parameters: List<EventParameter> = listOf(
EventParameter.String("item_name", "notify")
)
}

object NotifySuccessEvent : ReviewersEvent {
override val name: String = "action_finished"
override val parameters: List<EventParameter> = listOf(
EventParameter.String("item_name", "notify"),
EventParameter.Boolean("success", true)
)
}

object NotifyFailureEvent : ReviewersEvent {
override val name: String = "action_finished"
override val parameters: List<EventParameter> = listOf(
EventParameter.String("item_name", "notify"),
EventParameter.Boolean("success", false)
)
}

object RefreshDataEvent : ReviewersEvent {
override val name: String = "action_start"
override val parameters: List<EventParameter> = listOf(
EventParameter.String("item_name", "refresh_reviewers_data")
)
}

object RefreshDataSuccessEvent : ReviewersEvent {
override val name: String = "action_finished"
override val parameters: List<EventParameter> = listOf(
EventParameter.String("item_name", "refresh_reviewers_data"),
EventParameter.Boolean("success", true)
)
}

object RefreshDataFailureEvent : ReviewersEvent {
override val name: String = "action_finished"
override val parameters: List<EventParameter> = listOf(
EventParameter.String("item_name", "refresh_reviewers_data"),
EventParameter.Boolean("success", false)
)
}

object FetchDataEvent : ReviewersEvent {
override val name: String = "action_start"
override val parameters: List<EventParameter> = listOf(
EventParameter.String("item_name", "fetch_reviewers_data")
)
}

object FetchDataSuccessEvent : ReviewersEvent {
override val name: String = "action_finished"
override val parameters: List<EventParameter> = listOf(
EventParameter.String("item_name", "fetch_reviewers_data"),
EventParameter.Boolean("success", true)
)
}

object FetchDataFailureEvent : ReviewersEvent {
override val name: String = "action_finished"
override val parameters: List<EventParameter> = listOf(
EventParameter.String("item_name", "fetch_reviewers_data"),
EventParameter.Boolean("success", false)
)
}
33 changes: 33 additions & 0 deletions app/src/main/java/com/appunite/loudius/di/AnalyticsModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2023 AppUnite S.A.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.appunite.loudius.di

import com.appunite.loudius.analytics.EventParametersConverter
import com.appunite.loudius.analytics.EventTracker
import com.appunite.loudius.analytics.FirebaseAnalyticsEventTracker
import com.google.firebase.analytics.FirebaseAnalytics
import org.koin.android.ext.koin.androidContext
import org.koin.dsl.module

val analyticsModule = module {
single<FirebaseAnalytics> {
FirebaseAnalytics.getInstance(androidContext())
}
single<EventTracker> {
FirebaseAnalyticsEventTracker(get(), EventParametersConverter())
}
}
Loading

0 comments on commit 3df5b95

Please sign in to comment.