Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,16 @@ jobs:
PROD_BASE_URL: ${{ secrets.PROD_BASE_URL }}
KAKAO_APP_KEY: ${{ secrets.KAKAO_NATIVE_APP_KEY }}
NAVER_MAPS_CLIENT_ID: ${{ secrets.NAVER_MAPS_CLIENT_ID }}
POSTHOG_API_KEY: ${{ secrets.POSTHOG_API_KEY }}
POSTHOG_HOST: ${{ secrets.POSTHOG_HOST }}

run: |
echo DEV_BASE_URL=\"$DEV_BASE_URL\" >> local.properties
echo PROD_BASE_URL=\"$PROD_BASE_URL\" >> local.properties
echo KAKAO_NATIVE_APP_KEY=$KAKAO_NATIVE_APP_KEY >> local.properties
echo NAVER_MAPS_CLIENT_ID=$NAVER_MAPS_CLIENT_ID >> local.properties
echo POSTHOG_API_KEY=$POSTHOG_API_KEY >> local.properties
echo POSTHOG_HOST=$POSTHOG_HOST >> local.properties

- name: Generate google-services.json
run: |
Expand Down
15 changes: 15 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ android {
buildConfigField("String", "NAVER_MAPS_CLIENT_ID", "\"$naverMapsClientID\"")
manifestPlaceholders["NAVER_MAPS_CLIENT_ID"] = naverMapsClientID

val postHogApiKey: String = p.getProperty("POSTHOG_API_KEY")
buildConfigField("String", "POSTHOG_API_KEY", "\"$postHogApiKey\"")

val postHogHost: String = p.getProperty("POSTHOG_HOST")
buildConfigField("String", "POSTHOG_HOST", "\"$postHogHost\"")
Comment on lines +62 to +66
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

releasedebug 빌드 타입에 PostHog API 키와 호스트를 설정하는 코드가 중복됩니다. 이러한 중복은 향후 키를 추가하거나 수정할 때 실수를 유발할 수 있습니다. buildTypes.all을 사용하거나 공통 함수를 만들어 중복을 제거하는 것을 고려해 보세요. 예를 들어, buildTypes 블록 밖에서 프로퍼티를 한 번만 로드하고 공통 설정을 적용할 수 있습니다. 이 리팩토링은 현재 추가된 PostHog 키 뿐만 아니라 기존의 다른 키 설정에도 적용하여 코드베이스를 더 깔끔하게 만들 수 있습니다.


isShrinkResources = true
isMinifyEnabled = true
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
Expand All @@ -82,6 +88,12 @@ android {
buildConfigField("String", "NAVER_MAPS_CLIENT_ID", "\"$naverMapsClientID\"")
manifestPlaceholders["NAVER_MAPS_CLIENT_ID"] = naverMapsClientID

val postHogApiKey: String = p.getProperty("POSTHOG_API_KEY")
buildConfigField("String", "POSTHOG_API_KEY", "\"$postHogApiKey\"")

val postHogHost: String = p.getProperty("POSTHOG_HOST")
buildConfigField("String", "POSTHOG_HOST", "\"$postHogHost\"")

isMinifyEnabled = false
}
}
Expand Down Expand Up @@ -238,6 +250,9 @@ dependencies {
// 현재 위치 정보
implementation(libs.play.services.location)

// PostHog
implementation(libs.posthog.android)

}

kapt {
Expand Down
28 changes: 25 additions & 3 deletions app/src/main/java/com/eatssu/android/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import com.google.firebase.analytics.ktx.analytics
import com.google.firebase.crashlytics.FirebaseCrashlytics
import com.google.firebase.ktx.Firebase
import com.kakao.sdk.common.KakaoSdk
import com.posthog.android.PostHogAndroid
import com.posthog.android.PostHogAndroidConfig
import dagger.hilt.android.HiltAndroidApp
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand All @@ -35,7 +37,7 @@ class App : Application(), Configuration.Provider {
super.onCreate()
FirebaseApp.initializeApp(this)

KakaoSdk.init(this,BuildConfig.KAKAO_NATIVE_APP_KEY)
KakaoSdk.init(this, BuildConfig.KAKAO_NATIVE_APP_KEY)

if (BuildConfig.DEBUG) {
Timber.plant(Timber.DebugTree())
Expand All @@ -47,21 +49,41 @@ class App : Application(), Configuration.Provider {
}

collectTokenState()
setupPostHog()
}

/** 토큰 상태를 application에서 감지하여 TokenEventBus에 전달 */
private fun collectTokenState(){
private fun collectTokenState() {
appScope.launch {
TokenStateManager.state.collect { state ->
if (state == TokenState.EXPIRED) {
TokenEventBus.notifyTokenExpired()
} else if(state == TokenState.ERROR) {
} else if (state == TokenState.ERROR) {
TokenEventBus.notifyServerError()
}
}
}
}

private fun setupPostHog() {
// Create a PostHog Config with the given API key and host
val config = PostHogAndroidConfig(
apiKey = BuildConfig.POSTHOG_API_KEY,
host = BuildConfig.POSTHOG_HOST,
).apply {
sessionReplay = true
sessionReplayConfig.screenshot = true
if (BuildConfig.DEBUG) {
sessionReplayConfig.maskAllTextInputs = false
sessionReplayConfig.maskAllImages = false
}
}


// Setup PostHog with the given Context and Config
PostHogAndroid.setup(this, config)
}

override val workManagerConfiguration: Configuration
get() = Configuration.Builder()
.setWorkerFactory(workerFactory)
Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ ossLicensesPlugin = "0.10.6"
glanceAppwidget = "1.1.1"
glanceAppwidgetPreview = "1.1.1"
glancePreview = "1.1.1"
posthog = "3.+"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

동적 버전(+)을 사용하면 새로운 버전이 출시될 때 예기치 않은 변경사항이나 빌드 오류가 발생할 수 있습니다. 이는 빌드의 재현성을 떨어뜨립니다. 안정적인 개발 환경을 위해 3.1.0과 같이 특정 버전을 명시하는 것을 권장합니다.

Suggested change
posthog = "3.+"
posthog = "3.1.0"


[libraries]

Expand Down Expand Up @@ -155,6 +156,7 @@ map-sdk = { module = "com.naver.maps:map-sdk", version.ref = "mapSdk" }
naver-map-compose = { module = "io.github.fornewid:naver-map-compose", version.ref = "naverMapCompose" }
naver-map-location = { module = "io.github.fornewid:naver-map-location", version.ref = "naverMapLocation" }
play-services-location = { module = "com.google.android.gms:play-services-location", version.ref = "playServicesLocation" }
posthog-android = { group = "com.posthog", name = "posthog-android", version.ref = "posthog" }

[plugins]
android-application = { id = "com.android.application", version.ref = "android" }
Expand Down