From d3c9a4796e25d96922dc4372c45642c97a527bb2 Mon Sep 17 00:00:00 2001 From: LEE YOU BIN Date: Sat, 19 Oct 2024 13:14:59 +0900 Subject: [PATCH 1/5] =?UTF-8?q?[FEAT/#288]=20=EB=9D=BC=EC=9D=B4=EB=B8=8C?= =?UTF-8?q?=EB=9F=AC=EB=A6=AC=20=EB=B0=8F=20=EA=B6=8C=ED=95=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 1 + .../filtering/filteringthree/component/YearMonthPicker.kt | 2 ++ gradle/libs.versions.toml | 8 +++++--- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d3be9d435..5b58c1dfe 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -4,6 +4,7 @@ + Date: Sat, 19 Oct 2024 13:16:14 +0900 Subject: [PATCH 2/5] =?UTF-8?q?[FEAT/#288]=20=EC=95=88=20=EC=93=B0?= =?UTF-8?q?=EB=8A=94=20import=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../filtering/filteringthree/component/YearMonthPicker.kt | 2 -- 1 file changed, 2 deletions(-) diff --git a/feature/src/main/java/com/terning/feature/filtering/filteringthree/component/YearMonthPicker.kt b/feature/src/main/java/com/terning/feature/filtering/filteringthree/component/YearMonthPicker.kt index 56dc269c9..d61c06c98 100644 --- a/feature/src/main/java/com/terning/feature/filtering/filteringthree/component/YearMonthPicker.kt +++ b/feature/src/main/java/com/terning/feature/filtering/filteringthree/component/YearMonthPicker.kt @@ -3,7 +3,6 @@ package com.terning.feature.filtering.filteringthree.component import androidx.compose.foundation.gestures.snapping.rememberSnapFlingBehavior import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.IntrinsicSize import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth @@ -11,7 +10,6 @@ import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.offset import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.width -import androidx.compose.foundation.layout.wrapContentWidth import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.material3.HorizontalDivider From 241ad42a3246243282b817e6ae03b9a690155a64 Mon Sep 17 00:00:00 2001 From: LEE YOU BIN Date: Sat, 19 Oct 2024 13:21:10 +0900 Subject: [PATCH 3/5] [ADD/#288] add files --- README.md | 1 + .../main/java/com/terning/core/analytics/AmplitudeTracker.kt | 4 ++++ core/src/main/java/com/terning/core/analytics/EventType.kt | 4 ++++ 3 files changed, 9 insertions(+) create mode 100644 core/src/main/java/com/terning/core/analytics/AmplitudeTracker.kt create mode 100644 core/src/main/java/com/terning/core/analytics/EventType.kt diff --git a/README.md b/README.md index dff4a2250..78d48c139 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ ┗ 📂di 🗃️core + ┣ 📂analytics ┣ 📂designsystem ┃ ┣ 📂component ┃ ┣ 📂theme diff --git a/core/src/main/java/com/terning/core/analytics/AmplitudeTracker.kt b/core/src/main/java/com/terning/core/analytics/AmplitudeTracker.kt new file mode 100644 index 000000000..78a071faa --- /dev/null +++ b/core/src/main/java/com/terning/core/analytics/AmplitudeTracker.kt @@ -0,0 +1,4 @@ +package com.terning.core.analytics + +class AmplitudeTracker { +} \ No newline at end of file diff --git a/core/src/main/java/com/terning/core/analytics/EventType.kt b/core/src/main/java/com/terning/core/analytics/EventType.kt new file mode 100644 index 000000000..6919cefaa --- /dev/null +++ b/core/src/main/java/com/terning/core/analytics/EventType.kt @@ -0,0 +1,4 @@ +package com.terning.core.analytics + +class EventType { +} \ No newline at end of file From 04522aaf1d00e31c6900cc604fc8a22a0bcc7649 Mon Sep 17 00:00:00 2001 From: LEE YOU BIN Date: Sat, 19 Oct 2024 14:28:37 +0900 Subject: [PATCH 4/5] [ADD/#288] add amplitude tracker --- .github/workflows/dokka.yml | 4 +++ .github/workflows/pr_checker.yml | 4 +++ core/build.gradle.kts | 17 +++++++++++- .../core/analytics/AmplitudeTracker.kt | 27 +++++++++++++++++-- .../com/terning/core/analytics/EventType.kt | 6 +++-- 5 files changed, 53 insertions(+), 5 deletions(-) diff --git a/.github/workflows/dokka.yml b/.github/workflows/dokka.yml index da419da56..044844837 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 985aadf11..f49afbd0b 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 6c71ee666..0eacfbc4e 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 78a071faa..c9123c664 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 6919cefaa..ec270bc4b 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") +} From 04ff873d7add7f34adddc7027ff16a76111ba250 Mon Sep 17 00:00:00 2001 From: LEE YOU BIN Date: Sat, 19 Oct 2024 14:37:23 +0900 Subject: [PATCH 5/5] [FEAT/#288] put amplitude tracker in activity --- .../com/terning/core/analytics/AmplitudeTracker.kt | 5 +++++ .../java/com/terning/feature/main/MainActivity.kt | 12 +++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) 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 c9123c664..3340bcc90 100644 --- a/core/src/main/java/com/terning/core/analytics/AmplitudeTracker.kt +++ b/core/src/main/java/com/terning/core/analytics/AmplitudeTracker.kt @@ -1,6 +1,7 @@ package com.terning.core.analytics import android.content.Context +import androidx.compose.runtime.staticCompositionLocalOf import com.amplitude.android.Amplitude import com.amplitude.android.Configuration import com.terning.core.BuildConfig @@ -8,6 +9,10 @@ import dagger.hilt.android.qualifiers.ApplicationContext import timber.log.Timber import javax.inject.Inject +val LocalTracker = staticCompositionLocalOf { + error("No AmplitudeTracker provided") +} + class AmplitudeTracker @Inject constructor( @ApplicationContext private val context: Context ) { diff --git a/feature/src/main/java/com/terning/feature/main/MainActivity.kt b/feature/src/main/java/com/terning/feature/main/MainActivity.kt index 58b15268d..7e6e44656 100644 --- a/feature/src/main/java/com/terning/feature/main/MainActivity.kt +++ b/feature/src/main/java/com/terning/feature/main/MainActivity.kt @@ -4,18 +4,28 @@ import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.activity.enableEdgeToEdge +import androidx.compose.runtime.CompositionLocalProvider +import com.terning.core.analytics.AmplitudeTracker +import com.terning.core.analytics.LocalTracker import com.terning.core.designsystem.theme.TerningPointTheme import dagger.hilt.android.AndroidEntryPoint +import javax.inject.Inject @AndroidEntryPoint class MainActivity : ComponentActivity() { + + @Inject + lateinit var tracker: AmplitudeTracker + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) enableEdgeToEdge() setContent { val navigator: MainNavigator = rememberMainNavigator() TerningPointTheme { - MainScreen(navigator) + CompositionLocalProvider(LocalTracker provides tracker) { + MainScreen(navigator) + } } } }