From a418571db7cc7b02528ea55fd259d1addea069c0 Mon Sep 17 00:00:00 2001 From: kxxhyorim Date: Wed, 8 Nov 2023 03:31:12 +0900 Subject: [PATCH] [FEAT] Home / FirstMissionClick Logging (#156) --- .../domain/logging/FirstMissionClickScheme.kt | 43 +++++++++++++++++++ .../domain/logging/HomeMissionClickScheme.kt | 2 +- .../domain/logging/HomeScreenClickScheme.kt | 41 ------------------ .../lgtm/android/main/home/HomeFragment.kt | 26 +++++++++-- .../lgtm/android/main/home/HomeViewModel.kt | 5 ++- .../com/swm/logging/android/SWMLogging.kt | 2 +- .../logging_scheme/SWMLoggingScheme.kt | 6 +-- 7 files changed, 75 insertions(+), 50 deletions(-) create mode 100644 domain/src/main/java/com/lgtm/domain/logging/FirstMissionClickScheme.kt delete mode 100644 domain/src/main/java/com/lgtm/domain/logging/HomeScreenClickScheme.kt diff --git a/domain/src/main/java/com/lgtm/domain/logging/FirstMissionClickScheme.kt b/domain/src/main/java/com/lgtm/domain/logging/FirstMissionClickScheme.kt new file mode 100644 index 00000000..97dc3639 --- /dev/null +++ b/domain/src/main/java/com/lgtm/domain/logging/FirstMissionClickScheme.kt @@ -0,0 +1,43 @@ +package com.lgtm.domain.logging + +import com.swm.logging.android.logging_scheme.ClickScheme + +class FirstMissionClickScheme( + missionId : Int, + spendingTime : Long +) : ClickScheme() { + + init { + setLoggingScheme( + eventLogName = "firstMissionClick", + screenName = "HomeFragment", + logVersion = "1", + logData = mutableMapOf( + "missionId" to missionId, + "spendingTime" to spendingTime + ) + ) + } + + class Builder { + private var missionId : Int = 0 + private var spendingTime : Long = 0 + + fun setMissionId(missionId : Int): Builder { + this.missionId = missionId + return this + } + + fun setSpendingTime(spendingTime : Long): Builder { + this.spendingTime = spendingTime + return this + } + + fun build(): FirstMissionClickScheme { + return FirstMissionClickScheme( + missionId, + spendingTime + ) + } + } +} \ No newline at end of file diff --git a/domain/src/main/java/com/lgtm/domain/logging/HomeMissionClickScheme.kt b/domain/src/main/java/com/lgtm/domain/logging/HomeMissionClickScheme.kt index 665d8199..dd346630 100644 --- a/domain/src/main/java/com/lgtm/domain/logging/HomeMissionClickScheme.kt +++ b/domain/src/main/java/com/lgtm/domain/logging/HomeMissionClickScheme.kt @@ -9,7 +9,7 @@ class HomeMissionClickScheme( init { setLoggingScheme( - logName = "homeMissionClick", + eventLogName = "homeMissionClick", screenName = "HomeFragment", logVersion = "1", logData = mutableMapOf( diff --git a/domain/src/main/java/com/lgtm/domain/logging/HomeScreenClickScheme.kt b/domain/src/main/java/com/lgtm/domain/logging/HomeScreenClickScheme.kt deleted file mode 100644 index 550d6593..00000000 --- a/domain/src/main/java/com/lgtm/domain/logging/HomeScreenClickScheme.kt +++ /dev/null @@ -1,41 +0,0 @@ -package com.lgtm.domain.logging - -import com.swm.logging.android.logging_scheme.ClickScheme - -class HomeScreenClickScheme( - titleName: String, - age: String -) : ClickScheme() { - - init { - setLoggingScheme( - logName = "notificationClick", - screenName = "HomeFragment", - logVersion = "1", - logData = mutableMapOf( - "titleName" to titleName, - "age" to age - ) - ) - } - - class Builder { - private lateinit var titleName: String - private lateinit var age: String - fun setTitleName(titleName: String): Builder { - this.titleName = titleName - return this - } - - fun setAge(age: String): Builder { - this.age = age - return this - } - - fun build(): HomeScreenClickScheme { - return HomeScreenClickScheme( - titleName, age - ) - } - } -} \ No newline at end of file diff --git a/feature/main/src/main/java/com/lgtm/android/main/home/HomeFragment.kt b/feature/main/src/main/java/com/lgtm/android/main/home/HomeFragment.kt index 0250beba..e36b6616 100644 --- a/feature/main/src/main/java/com/lgtm/android/main/home/HomeFragment.kt +++ b/feature/main/src/main/java/com/lgtm/android/main/home/HomeFragment.kt @@ -11,16 +11,21 @@ import com.lgtm.android.common_ui.util.setOnThrottleClickListener import com.lgtm.android.main.R import com.lgtm.android.main.databinding.FragmentHomeBinding import com.lgtm.domain.constants.Role +import com.lgtm.domain.logging.FirstMissionClickScheme import com.lgtm.domain.logging.HomeMissionClickScheme import com.lgtm.domain.server_drive_ui.SduiContent import com.lgtm.domain.server_drive_ui.SectionItemVO import com.swm.logging.android.logging_scheme.SWMLoggingScheme import dagger.hilt.android.AndroidEntryPoint +import kotlin.properties.Delegates @AndroidEntryPoint class HomeFragment : BaseFragment(R.layout.fragment_home) { private val homeViewModel by viewModels() private lateinit var commonAdapter: SduiAdapter + private var isFirstMissionClick = false + private val entryTime = System.currentTimeMillis() + private var firstMissionClickTime by Delegates.notNull() override fun initializeViewModel() { viewModel = homeViewModel @@ -76,12 +81,27 @@ class HomeFragment : BaseFragment(R.layout.fragment_home) { } private fun onClickMissionItem(sduiContent: SduiContent) { - val scheme = getHomeExposureLoggingScheme(sduiContent) - homeViewModel.shotHomeExposureLogging(scheme) + if (!isFirstMissionClick) logFirstMissionClick(sduiContent) + logMissionClick(sduiContent) moveToMissionDetail((sduiContent as SectionItemVO).missionId) } - private fun getHomeExposureLoggingScheme(sduiContent: SduiContent): SWMLoggingScheme { + private fun logFirstMissionClick(sduiContent: SduiContent) { + firstMissionClickTime = System.currentTimeMillis() + isFirstMissionClick = true + val firstMissionClickScheme = FirstMissionClickScheme.Builder() + .setMissionId((sduiContent as SectionItemVO).missionId) + .setSpendingTime(firstMissionClickTime - entryTime) + .build() + homeViewModel.shotFirstMissionClickLogging(firstMissionClickScheme) + } + + private fun logMissionClick(sduiContent: SduiContent) { + val scheme = getHomeMissionClickLoggingScheme(sduiContent) + homeViewModel.shotHomeMissionClickLogging(scheme) + } + + private fun getHomeMissionClickLoggingScheme(sduiContent: SduiContent): SWMLoggingScheme { return HomeMissionClickScheme.Builder() .setMissionContent(sduiContent) .build() diff --git a/feature/main/src/main/java/com/lgtm/android/main/home/HomeViewModel.kt b/feature/main/src/main/java/com/lgtm/android/main/home/HomeViewModel.kt index d099b0a1..a3b5f076 100644 --- a/feature/main/src/main/java/com/lgtm/android/main/home/HomeViewModel.kt +++ b/feature/main/src/main/java/com/lgtm/android/main/home/HomeViewModel.kt @@ -56,10 +56,13 @@ class HomeViewModel @Inject constructor( } } - fun shotHomeExposureLogging(swmLoggingScheme: SWMLoggingScheme) { + fun shotHomeMissionClickLogging(swmLoggingScheme: SWMLoggingScheme) { SWMLogging.logEvent(swmLoggingScheme) } fun getUserRole() = role + fun shotFirstMissionClickLogging(swmLoggingScheme: SWMLoggingScheme) { + SWMLogging.logEvent(swmLoggingScheme) + } } \ No newline at end of file diff --git a/swm-logging/src/main/java/com/swm/logging/android/SWMLogging.kt b/swm-logging/src/main/java/com/swm/logging/android/SWMLogging.kt index 4d9b6c73..ec4286f1 100644 --- a/swm-logging/src/main/java/com/swm/logging/android/SWMLogging.kt +++ b/swm-logging/src/main/java/com/swm/logging/android/SWMLogging.kt @@ -34,7 +34,7 @@ object SWMLogging { } override fun onNext(value: SWMLoggingScheme) { - println("Rx: 아이템 받음: ${value.logName}") + println("Rx: 아이템 받음: ${value.eventLogName}") runBlocking { val result = async { shotLogging(value) } println("Rx: 로깅 결과: ${result.await()}") diff --git a/swm-logging/src/main/java/com/swm/logging/android/logging_scheme/SWMLoggingScheme.kt b/swm-logging/src/main/java/com/swm/logging/android/logging_scheme/SWMLoggingScheme.kt index 43bddd81..6408a5f6 100644 --- a/swm-logging/src/main/java/com/swm/logging/android/logging_scheme/SWMLoggingScheme.kt +++ b/swm-logging/src/main/java/com/swm/logging/android/logging_scheme/SWMLoggingScheme.kt @@ -3,7 +3,7 @@ package com.swm.logging.android.logging_scheme import com.swm.logging.android.SWMLogging abstract class SWMLoggingScheme { - open lateinit var logName: String + open lateinit var eventLogName: String open lateinit var screenName: String open lateinit var logVersion: String private val osVersionAndName: String = SWMLogging.getOsNameAndVersion() @@ -14,12 +14,12 @@ abstract class SWMLoggingScheme { private val appVersion = SWMLogging.getAppVersion() private val region = SWMLogging.getRegion() fun setLoggingScheme( - logName: String, + eventLogName: String, screenName: String, logVersion: String, logData: MutableMap?, ) { - this.logName = logName + this.eventLogName = eventLogName this.screenName = screenName this.logVersion = logVersion this.logData = logData