diff --git a/.github/workflows/dokka.yml b/.github/workflows/dokka.yml index da419da5..04484483 100644 --- a/.github/workflows/dokka.yml +++ b/.github/workflows/dokka.yml @@ -34,6 +34,8 @@ jobs: RELEASE_KEY_PASSWORD: ${{ secrets.RELEASE_KEY_PASSWORD }} RELEASE_STORE_FILE: ${{ secrets.RELEASE_STORE_FILE }} RELEASE_STORE_PASSWORD: ${{ secrets.RELEASE_STORE_PASSWORD }} + AMPLITUDE_DEV_KEY: ${{ secrets.AMPLITUDE_DEV_KEY }} + AMPLITUDE_PROD_KEY: ${{ secrets.AMPLITUDE_PROD_KEY }} run: | echo base.url=\"$BASE_URL\" >> local.properties echo test.base.url=\"$TEST_BASE_URL\" >> local.properties @@ -43,6 +45,8 @@ jobs: echo release.keyPassword=\"$RELEASE_KEY_PASSWORD\" >> local.properties echo release.storeFile=\"$RELEASE_STORE_FILE\" >> local.properties echo release.storePassword=\"$RELEASE_STORE_PASSWORD\" >> local.properties + echo amplitudeDevKey=\"$AMPLITUDE_DEV_KEY\" >> local.properties + echo amplitudeProdKey=\"$AMPLITUDE_PROD_KEY\" >> local.properties - name: Build Documentation run: ./gradlew dokkaHtml diff --git a/.github/workflows/pr_checker.yml b/.github/workflows/pr_checker.yml index 985aadf1..f49afbd0 100644 --- a/.github/workflows/pr_checker.yml +++ b/.github/workflows/pr_checker.yml @@ -48,6 +48,8 @@ jobs: RELEASE_KEY_PASSWORD: ${{ secrets.RELEASE_KEY_PASSWORD }} RELEASE_STORE_FILE: ${{ secrets.RELEASE_STORE_FILE }} RELEASE_STORE_PASSWORD: ${{ secrets.RELEASE_STORE_PASSWORD }} + AMPLITUDE_DEV_KEY: ${{ secrets.AMPLITUDE_DEV_KEY }} + AMPLITUDE_PROD_KEY: ${{ secrets.AMPLITUDE_PROD_KEY }} run: | echo base.url=\"$BASE_URL\" >> local.properties echo test.base.url=\"$TEST_BASE_URL\" >> local.properties @@ -57,3 +59,5 @@ jobs: echo release.keyPassword=\"$RELEASE_KEY_PASSWORD\" >> local.properties echo release.storeFile=\"$RELEASE_STORE_FILE\" >> local.properties echo release.storePassword=\"$RELEASE_STORE_PASSWORD\" >> local.properties + echo amplitudeDevKey=\"$AMPLITUDE_DEV_KEY\" >> local.properties + echo amplitudeProdKey=\"$AMPLITUDE_PROD_KEY\" >> local.properties diff --git a/core/build.gradle.kts b/core/build.gradle.kts index 6c71ee66..0eacfbc4 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -1,9 +1,15 @@ +import java.util.Properties + plugins { alias(libs.plugins.android.library) alias(libs.plugins.kotlin.android) alias(libs.plugins.dokka) } +val properties = Properties().apply { + load(rootProject.file("local.properties").inputStream()) +} + android { namespace = "com.terning.core" compileSdk = libs.versions.compileSdk.get().toInt() @@ -16,18 +22,25 @@ android { } buildTypes { + debug { + val devAmplitude = properties["amplitudeDevKey"] as? String ?: "" + buildConfigField("String", "AMPLITUDE_KEY", devAmplitude) + } + release { isMinifyEnabled = false proguardFiles( getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro" ) + val prodAmplitude = properties["amplitudeProdKey"] as? String ?: "" + buildConfigField("String", "AMPLITUDE_KEY", prodAmplitude) } } + compileOptions { sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 - } kotlinOptions { jvmTarget = libs.versions.jvmTarget.get() @@ -80,4 +93,6 @@ dependencies { implementation(libs.compose.coil) implementation(libs.okhttp) implementation(libs.lottie) + implementation(libs.amplitude) + implementation(libs.timber) } \ No newline at end of file diff --git a/core/src/main/java/com/terning/core/analytics/AmplitudeTracker.kt b/core/src/main/java/com/terning/core/analytics/AmplitudeTracker.kt index 78a071fa..c9123c66 100644 --- a/core/src/main/java/com/terning/core/analytics/AmplitudeTracker.kt +++ b/core/src/main/java/com/terning/core/analytics/AmplitudeTracker.kt @@ -1,4 +1,27 @@ package com.terning.core.analytics -class AmplitudeTracker { -} \ No newline at end of file +import android.content.Context +import com.amplitude.android.Amplitude +import com.amplitude.android.Configuration +import com.terning.core.BuildConfig +import dagger.hilt.android.qualifiers.ApplicationContext +import timber.log.Timber +import javax.inject.Inject + +class AmplitudeTracker @Inject constructor( + @ApplicationContext private val context: Context +) { + private val amplitude = Amplitude( + Configuration( + apiKey = BuildConfig.AMPLITUDE_KEY, + context = context + ) + ) + + fun track(type: EventType, name: String, properties: Map = emptyMap()) { + if (BuildConfig.DEBUG) { + Timber.d("Amplitude: ${type.prefix}_$name properties: $properties") + } + amplitude.track(eventType = "${type.prefix}_$name", eventProperties = properties) + } +} diff --git a/core/src/main/java/com/terning/core/analytics/EventType.kt b/core/src/main/java/com/terning/core/analytics/EventType.kt index 6919cefa..ec270bc4 100644 --- a/core/src/main/java/com/terning/core/analytics/EventType.kt +++ b/core/src/main/java/com/terning/core/analytics/EventType.kt @@ -1,4 +1,6 @@ package com.terning.core.analytics -class EventType { -} \ No newline at end of file +enum class EventType(val prefix: String) { + VIEW("view"), + CLICK("click") +}