Skip to content

Commit

Permalink
[ADD/#288] add amplitude tracker
Browse files Browse the repository at this point in the history
  • Loading branch information
leeeyubin committed Oct 19, 2024
1 parent 241ad42 commit 04522aa
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 5 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/dokka.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/pr_checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
17 changes: 16 additions & 1 deletion core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -80,4 +93,6 @@ dependencies {
implementation(libs.compose.coil)
implementation(libs.okhttp)
implementation(libs.lottie)
implementation(libs.amplitude)
implementation(libs.timber)
}
27 changes: 25 additions & 2 deletions core/src/main/java/com/terning/core/analytics/AmplitudeTracker.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
package com.terning.core.analytics

class AmplitudeTracker {
}
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<String, Any?> = emptyMap()) {
if (BuildConfig.DEBUG) {
Timber.d("Amplitude: ${type.prefix}_$name properties: $properties")
}
amplitude.track(eventType = "${type.prefix}_$name", eventProperties = properties)
}
}
6 changes: 4 additions & 2 deletions core/src/main/java/com/terning/core/analytics/EventType.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package com.terning.core.analytics

class EventType {
}
enum class EventType(val prefix: String) {
VIEW("view"),
CLICK("click")
}

0 comments on commit 04522aa

Please sign in to comment.