Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mirego-base-setup 6 of X: Analytics #41

Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion androidApp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.crashlyticsPlugin)
}

kotlin {
Expand Down Expand Up @@ -77,9 +78,11 @@ dependencies {
implementation(project(":shared"))

implementation(libs.android.splash)
implementation(libs.android.firebase.analytics)
implementation(libs.android.firebase.crashlytics)
implementation(platform(libs.android.firebase.bom))
implementation(libs.androidx.appcompat)
implementation(libs.androidx.activity.compose)

implementation(platform(libs.androidx.compose.bom))
implementation(libs.accompanist.systemuicontroller)
implementation(libs.accompanist.placeholder.material)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.mirego.kmp.boilerplate.app.analytics

import android.content.Context
import android.os.Bundle
import com.google.firebase.analytics.FirebaseAnalytics
import com.mirego.kmp.boilerplate.analytics.SharedAnalyticsService
import com.mirego.trikot.analytics.AnalyticsEvent
import com.mirego.trikot.analytics.AnalyticsPropertiesType

class AndroidSharedAnalyticsService(
context: Context,
private var analyticsEnabled: Boolean = true
) : SharedAnalyticsService {
private var firebaseAnalytics = FirebaseAnalytics.getInstance(context)

override var isEnabled: Boolean
get() = analyticsEnabled
set(value) {
analyticsEnabled = value
firebaseAnalytics.setAnalyticsCollectionEnabled(value)
}

override fun trackEvent(event: AnalyticsEvent, properties: AnalyticsPropertiesType) {
val bundle = Bundle()
properties.forEach {
bundle.putString(it.key, it.value.toString())
}
firebaseAnalytics.logEvent(event.name, bundle)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.mirego.kmp.boilerplate.app.bootstrap

import android.content.Context
import com.mirego.kmp.boilerplate.BuildConfig
import com.mirego.kmp.boilerplate.analytics.SharedAnalyticsConfiguration
import com.mirego.kmp.boilerplate.app.analytics.AndroidSharedAnalyticsService
import com.mirego.kmp.boilerplate.app.resources.AndroidImageProvider
import com.mirego.kmp.boilerplate.bootstrap.AppEnvironment
import com.mirego.kmp.boilerplate.bootstrap.Bootstrap
Expand Down Expand Up @@ -31,5 +33,11 @@ class AndroidBootstrap(context: Context) : Bootstrap {
imageProvider = AndroidImageProvider(),
textStyleProvider = DefaultTextStyleProvider()
)

val analyticsEnabled = !BuildConfig.DEBUG
SharedAnalyticsConfiguration.analyticsManager = AndroidSharedAnalyticsService(
context = context,
analyticsEnabled = analyticsEnabled
)
}
}
10 changes: 10 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ accompanist = "0.32.0"
androidComposeCompiler = "1.5.3"
androidGradlePlugin = "8.1.2"
android-splash = "1.0.1"
android-playServices = "20.7.0"
play-services-measurement-api = "21.5.0"
androidxActivityCompose = "1.8.0"
androidxAppcompat = "1.6.1"
androidxComposeBom = "2023.10.01"
apollo = "3.7.4"
crashlytics-plugin = "2.9.9"
koin = "3.5.0"
koin-android = "3.5.0"
koin-androidx-compose = "3.5.0"
Expand All @@ -18,6 +21,7 @@ kotlinxCoroutines = "1.7.3"
kotlinxSerialization = "1.6.0"
kword-plugin = "4.0.0"
ktlint = "11.6.1"
firebase = "32.5.0"
mockk = "1.12.5"
okio = "3.6.0"
owasp = "8.4.2"
Expand All @@ -34,6 +38,9 @@ androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", versi
androidx-compose-ui = { group = "androidx.compose.ui", name = "ui" }
androidx-compose-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" }
androidx-compose-material = { group = "androidx.compose.material", name = "material" }
android-firebase-bom = { module = "com.google.firebase:firebase-bom", version.ref = "firebase" }
android-firebase-crashlytics = { module = "com.google.firebase:firebase-crashlytics-ktx" }
android-firebase-analytics = { module = "com.google.firebase:firebase-analytics-ktx" }
apollo-runtime = { group = "com.apollographql.apollo3", name = "apollo-runtime" }
koin-core = { module = "io.insert-koin:koin-core", version.ref = "koin" }
koin-annotations = { module = "io.insert-koin:koin-annotations", version.ref = "koin_ksp" }
Expand All @@ -53,6 +60,8 @@ skie = { module = "co.touchlab.skie:configuration-annotations", version.ref = "s
mockk-common = { module = "io.mockk:mockk-common", version.ref = "mockk" }
mockk = { module = "io.mockk:mockk", version.ref = "mockk" }

trikot-analytics = { module = "com.mirego.trikot:analytics", version.ref = "trikot" }
trikot-analytics-firebase = { module = "com.mirego.trikot.analytics:firebase-ktx", version.ref = "trikot" }
trikot-vmd = { module = "com.mirego.trikot:viewmodels-declarative-flow", version.ref = "trikot" }
trikot-kword = { module = "com.mirego.trikot:kword", version.ref = "trikot" }
trikot-datasources = { module = "com.mirego.trikot:datasources-flow", version.ref = "trikot" }
Expand All @@ -70,6 +79,7 @@ kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref
kotlin-native-cocoapods = { id = "org.jetbrains.kotlin.native.cocoapods", version.ref = "kotlin" }
kspPlugin = { id = "com.google.devtools.ksp", version.ref = "ksp" }
ktlint = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "ktlint" }
crashlyticsPlugin = { id = "com.google.firebase.crashlytics", version.ref = "crashlytics-plugin" }
mirego-kwordPlugin = { id = "mirego.kword", version.ref = "kword-plugin" }
owasp-dependencycheck = { id = "org.owasp.dependencycheck", version.ref = "owasp" }
serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
Expand Down
6 changes: 5 additions & 1 deletion ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ inhibit_all_warnings!

target 'iosApp' do
use_frameworks!
platform :ios, $deploymentTarget
platform :ios, $deploymentTarget
# Third-party
pod 'FirebaseCore'
pod 'FirebaseAnalytics'

# Multiplatform
pod 'Shared', :path => '../shared'

Expand Down
94 changes: 93 additions & 1 deletion ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,79 @@
PODS:
- FirebaseAnalytics (10.16.0):
- FirebaseAnalytics/AdIdSupport (= 10.16.0)
- FirebaseCore (~> 10.0)
- FirebaseInstallations (~> 10.0)
- GoogleUtilities/AppDelegateSwizzler (~> 7.11)
- GoogleUtilities/MethodSwizzler (~> 7.11)
- GoogleUtilities/Network (~> 7.11)
- "GoogleUtilities/NSData+zlib (~> 7.11)"
- nanopb (< 2.30910.0, >= 2.30908.0)
- FirebaseAnalytics/AdIdSupport (10.16.0):
- FirebaseCore (~> 10.0)
- FirebaseInstallations (~> 10.0)
- GoogleAppMeasurement (= 10.16.0)
- GoogleUtilities/AppDelegateSwizzler (~> 7.11)
- GoogleUtilities/MethodSwizzler (~> 7.11)
- GoogleUtilities/Network (~> 7.11)
- "GoogleUtilities/NSData+zlib (~> 7.11)"
- nanopb (< 2.30910.0, >= 2.30908.0)
- FirebaseCore (10.16.0):
- FirebaseCoreInternal (~> 10.0)
- GoogleUtilities/Environment (~> 7.8)
- GoogleUtilities/Logger (~> 7.8)
- FirebaseCoreInternal (10.16.0):
- "GoogleUtilities/NSData+zlib (~> 7.8)"
- FirebaseInstallations (10.16.0):
- FirebaseCore (~> 10.0)
- GoogleUtilities/Environment (~> 7.8)
- GoogleUtilities/UserDefaults (~> 7.8)
- PromisesObjC (~> 2.1)
- GoogleAppMeasurement (10.16.0):
- GoogleAppMeasurement/AdIdSupport (= 10.16.0)
- GoogleUtilities/AppDelegateSwizzler (~> 7.11)
- GoogleUtilities/MethodSwizzler (~> 7.11)
- GoogleUtilities/Network (~> 7.11)
- "GoogleUtilities/NSData+zlib (~> 7.11)"
- nanopb (< 2.30910.0, >= 2.30908.0)
- GoogleAppMeasurement/AdIdSupport (10.16.0):
- GoogleAppMeasurement/WithoutAdIdSupport (= 10.16.0)
- GoogleUtilities/AppDelegateSwizzler (~> 7.11)
- GoogleUtilities/MethodSwizzler (~> 7.11)
- GoogleUtilities/Network (~> 7.11)
- "GoogleUtilities/NSData+zlib (~> 7.11)"
- nanopb (< 2.30910.0, >= 2.30908.0)
- GoogleAppMeasurement/WithoutAdIdSupport (10.16.0):
- GoogleUtilities/AppDelegateSwizzler (~> 7.11)
- GoogleUtilities/MethodSwizzler (~> 7.11)
- GoogleUtilities/Network (~> 7.11)
- "GoogleUtilities/NSData+zlib (~> 7.11)"
- nanopb (< 2.30910.0, >= 2.30908.0)
- GoogleUtilities/AppDelegateSwizzler (7.11.5):
- GoogleUtilities/Environment
- GoogleUtilities/Logger
- GoogleUtilities/Network
- GoogleUtilities/Environment (7.11.5):
- PromisesObjC (< 3.0, >= 1.2)
- GoogleUtilities/Logger (7.11.5):
- GoogleUtilities/Environment
- GoogleUtilities/MethodSwizzler (7.11.5):
- GoogleUtilities/Logger
- GoogleUtilities/Network (7.11.5):
- GoogleUtilities/Logger
- "GoogleUtilities/NSData+zlib"
- GoogleUtilities/Reachability
- "GoogleUtilities/NSData+zlib (7.11.5)"
- GoogleUtilities/Reachability (7.11.5):
- GoogleUtilities/Logger
- GoogleUtilities/UserDefaults (7.11.5):
- GoogleUtilities/Logger
- Kingfisher (7.8.1)
- nanopb (2.30909.0):
- nanopb/decode (= 2.30909.0)
- nanopb/encode (= 2.30909.0)
- nanopb/decode (2.30909.0)
- nanopb/encode (2.30909.0)
- PromisesObjC (2.3.1)
- Shared (0.1)
- SwiftLint (0.53.0)
- SwiftUIIntrospect (1.1.0)
Expand All @@ -14,14 +88,24 @@ PODS:
- Trikot/viewmodels.declarative.flow

DEPENDENCIES:
- FirebaseAnalytics
- FirebaseCore
- Shared (from `../shared`)
- SwiftLint
- "Trikot/kword (from `[email protected]:mirego/trikot.git`, tag `5.2.0`)"
- "Trikot/viewmodels.declarative.SwiftUI.flow (from `[email protected]:mirego/trikot.git`, tag `5.2.0`)"

SPEC REPOS:
trunk:
- FirebaseAnalytics
- FirebaseCore
- FirebaseCoreInternal
- FirebaseInstallations
- GoogleAppMeasurement
- GoogleUtilities
- Kingfisher
- nanopb
- PromisesObjC
- SwiftLint
- SwiftUIIntrospect

Expand All @@ -38,12 +122,20 @@ CHECKOUT OPTIONS:
:tag: 5.2.0

SPEC CHECKSUMS:
FirebaseAnalytics: 7b41efc4eba5ff841cc94d5994b5f339361258f4
FirebaseCore: 65a801af84cca84361ef9eac3fd868656968a53b
FirebaseCoreInternal: 26233f705cc4531236818a07ac84d20c333e505a
FirebaseInstallations: b822f91a61f7d1ba763e5ccc9d4f2e6f2ed3b3ee
GoogleAppMeasurement: 079d7632810e9d9704a99932547ba1554acc4342
GoogleUtilities: 13e2c67ede716b8741c7989e26893d151b2b2084
Kingfisher: 63f677311d36a3473f6b978584f8a3845d023dc5
nanopb: b552cce312b6c8484180ef47159bc0f65a1f0431
PromisesObjC: c50d2056b5253dadbd6c2bea79b0674bd5a52fa4
Shared: 185e58fd174d1d4b955d7581bc1bacb9810272fa
SwiftLint: 5ce4d6a8ff83f1b5fd5ad5dbf30965d35af65e44
SwiftUIIntrospect: 53b6a16734c822804ff82c35d9073d8d8edfb085
Trikot: ca201c8ae67ff21f35a60a0bda6c600fbe51b282

PODFILE CHECKSUM: a8e15659553c290a2147c108f4746a4431cf7594
PODFILE CHECKSUM: 8c6a75418b236f7d0081b7844d58c4e6b129cedb

COCOAPODS: 1.13.0
8 changes: 8 additions & 0 deletions ios/iosApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
895BED172AF416F5005B1212 /* VMDColor+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 895BED162AF416F5005B1212 /* VMDColor+Extensions.swift */; };
895BED192AF42C2B005B1212 /* ProjectDetailsContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 895BED182AF42C2B005B1212 /* ProjectDetailsContentView.swift */; };
895BED1B2AF4469C005B1212 /* NavigationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 895BED1A2AF4469C005B1212 /* NavigationView.swift */; };
895BED1D2AF58517005B1212 /* AnalyticsServiceImpl.swift in Sources */ = {isa = PBXBuildFile; fileRef = 895BED1C2AF58517005B1212 /* AnalyticsServiceImpl.swift */; };
895BED1F2AF9780C005B1212 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 895BED1E2AF9780C005B1212 /* GoogleService-Info.plist */; };
9B8ACFDB4E332DFCA8B97CBB /* Pods_iosApp.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4E4E1328B104D05A50A097EE /* Pods_iosApp.framework */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -69,6 +71,8 @@
895BED162AF416F5005B1212 /* VMDColor+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "VMDColor+Extensions.swift"; sourceTree = "<group>"; };
895BED182AF42C2B005B1212 /* ProjectDetailsContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProjectDetailsContentView.swift; sourceTree = "<group>"; };
895BED1A2AF4469C005B1212 /* NavigationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationView.swift; sourceTree = "<group>"; };
895BED1C2AF58517005B1212 /* AnalyticsServiceImpl.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalyticsServiceImpl.swift; sourceTree = "<group>"; };
895BED1E2AF9780C005B1212 /* GoogleService-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
E232C917135C2C1E3BC8748A /* Pods-iosApp.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-iosApp.release.xcconfig"; path = "Target Support Files/Pods-iosApp/Pods-iosApp.release.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -123,6 +127,7 @@
058557BA273AAA24004C7B11 /* Assets.xcassets */,
895BED042AEFFEA2005B1212 /* Colors.xcassets */,
058557D7273AAEEB004C7B11 /* Preview Content */,
895BED1E2AF9780C005B1212 /* GoogleService-Info.plist */,
);
path = iosApp;
sourceTree = "<group>";
Expand All @@ -134,6 +139,7 @@
89011D4C2AE9A4FC0073544B /* AppEnvironment+iOS.swift */,
89011D4A2AE9A4CD0073544B /* BootstrapImpl.swift */,
89011D502AE9A7750073544B /* ImageProvider.swift */,
895BED1C2AF58517005B1212 /* AnalyticsServiceImpl.swift */,
);
path = Domain;
sourceTree = "<group>";
Expand Down Expand Up @@ -305,6 +311,7 @@
buildActionMask = 2147483647;
files = (
895BED052AEFFEA2005B1212 /* Colors.xcassets in Resources */,
895BED1F2AF9780C005B1212 /* GoogleService-Info.plist in Resources */,
058557D9273AAEEB004C7B11 /* Preview Assets.xcassets in Resources */,
058557BB273AAA24004C7B11 /* Assets.xcassets in Resources */,
);
Expand Down Expand Up @@ -413,6 +420,7 @@
895BED192AF42C2B005B1212 /* ProjectDetailsContentView.swift in Sources */,
895BED112AF3FD32005B1212 /* NavigationModifier.swift in Sources */,
89011D512AE9A7750073544B /* ImageProvider.swift in Sources */,
895BED1D2AF58517005B1212 /* AnalyticsServiceImpl.swift in Sources */,
89011D4B2AE9A4CD0073544B /* BootstrapImpl.swift in Sources */,
895BED032AEFF281005B1212 /* TextStyle.swift in Sources */,
895BECFB2AEAB3DC005B1212 /* RootView.swift in Sources */,
Expand Down
17 changes: 16 additions & 1 deletion ios/iosApp/AppInitializer.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
import FirebaseCore
import Foundation
import Kingfisher
import Shared
import Trikot

enum AppInitializer {
static func initializeComponents(environment: AppEnvironment) {
static func initializeComponents(environment _: AppEnvironment) {
initializeFirebase()
initializeCommon()
initializeKingfisher()
}

private static func initializeFirebase() {
FirebaseApp.configure()

let firebaseAnalyticsService = AnalyticsServiceImpl()
#if DEBUG
firebaseAnalyticsService.isEnabled = false
#else
firebaseAnalyticsService.isEnabled = true
#endif

SharedAnalyticsConfiguration().analyticsManager = firebaseAnalyticsService
}

private static func initializeCommon() {
TrikotKword.shared.setCurrentLanguage(Foundation.Locale.isPreferredLanguagesFrench ? "fr" : "en")
TrikotViewModelDeclarative.shared.initialize(
Expand Down
20 changes: 20 additions & 0 deletions ios/iosApp/Domain/AnalyticsServiceImpl.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import FirebaseAnalytics
import Foundation
import Shared

public class AnalyticsServiceImpl: SharedAnalyticsService {

public init(enableAnalytics: Bool = true) {
isEnabled = enableAnalytics
}

public var isEnabled: Bool {
didSet {
Analytics.setAnalyticsCollectionEnabled(isEnabled)
}
}

public func trackEvent(event: AnalyticsEvent, properties: [String: Any]) {
Analytics.logEvent(event.name, parameters: properties)
}
}
32 changes: 32 additions & 0 deletions ios/iosApp/GoogleService-Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ANDROID_CLIENT_ID</key>
<string>123456789012-0cnvm52tlj4cn7rkfujdkuq3iq79v5ig.apps.googleusercontent.com</string>
<key>API_KEY</key>
<string>AIzaSyC3_0lgMdiPr41DjqzSWP2MqGIqIakley0</string>
<key>GCM_SENDER_ID</key>
<string>123456789012</string>
<key>PLIST_VERSION</key>
<string>1</string>
<key>BUNDLE_ID</key>
<string>com.mirego.kmp.boilerplate</string>
<key>PROJECT_ID</key>
<string>boilerplate-1234567890123</string>
<key>STORAGE_BUCKET</key>
<string>boilerplate-1234567890123.appspot.com</string>
<key>IS_ADS_ENABLED</key>
<false></false>
<key>IS_ANALYTICS_ENABLED</key>
<false></false>
<key>IS_APPINVITE_ENABLED</key>
<true></true>
<key>IS_GCM_ENABLED</key>
<true></true>
<key>IS_SIGNIN_ENABLED</key>
<true></true>
<key>GOOGLE_APP_ID</key>
<string>1:123456789012:ios:c930c9194f493843b44d0a</string>
</dict>
</plist>
Loading
Loading