Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature/#83] set up amplitude #85

Merged
merged 10 commits into from
Sep 26, 2024
3 changes: 3 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,6 @@

-keep class * extends android.app.Activity { *; }
-keep class * extends android.app.Service { *; }

#play-services-ads.
-keep class com.google.android.gms.ads.** { *; }
12 changes: 12 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
<uses-permission android:name="android.permission.READ_MEDIA_VISUAL_USER_SELECTED" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="com.google.android.gms.permission.AD_ID" />

<application
android:name=".WableApp"
android:allowBackup="true"
Expand All @@ -30,6 +33,15 @@
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="@color/white" />
<meta-data
android:name="com.google.android.gms.ads.AD_MANAGER_APP"
android:value="true" />
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="com.teamwable.wable" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />

<service
android:name=".service.WableFirebaseMessagingService"
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/teamwable/wable/WableApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.os.Build
import androidx.appcompat.app.AppCompatDelegate
import com.kakao.sdk.common.KakaoSdk
import com.kakao.sdk.common.util.Utility
import com.teamwable.common.util.AmplitudeUtil.initAmplitude
import com.teamwable.ui.util.FcmTag.CHANNEL_ID
import com.teamwable.ui.util.FcmTag.CHANNEL_NAME
import com.teamwable.wable.BuildConfig.KAKAO_APP_KEY
Expand All @@ -29,6 +30,7 @@ class WableApp : Application() {
setDarkMode()
setKaKaoSdk()
createNotificationChannel()
initAmplitude(applicationContext)
Copy link
Member

Choose a reason for hiding this comment

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

p3 : μœ„μ—μ„œ μ£Όμž…ν•œ contextλ₯Ό μ‚¬μš©ν•΄λ„ λ˜μ§€ μ•Šλ‚˜μš©?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

μ•— κ·Έκ±Έ λͺ»λ΄€λ„€μš” μˆ˜μ •ν–ˆμŠ΅λ‹ˆλ‹€!
aba653d

}

private fun setTimber() {
Expand Down
29 changes: 29 additions & 0 deletions core/common/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,36 @@
import java.util.Properties

@Suppress("DSL_SCOPE_VIOLATION")
plugins {
id("com.teamwable.wable.feature")
}

val properties = Properties().apply {
load(rootProject.file("local.properties").inputStream())
}

android {
namespace = "com.teamwable.common"

buildTypes {
getByName("debug") {
val amplitudeDevApiKey = properties["amplitude.dev.api.key"] as? String ?: ""
buildConfigField("String", "AMPLITUDE_API_KEY", "\"${amplitudeDevApiKey}\"")
}

getByName("release") {
val amplitudeRelApiKey = properties["amplitude.rel.api.key"] as? String ?: ""
buildConfigField("String", "AMPLITUDE_API_KEY", "\"${amplitudeRelApiKey}\"")
}
}

buildFeatures.apply {
buildConfig = true
}
}

dependencies {
// Third Party
implementation(libs.amplitude)
implementation(libs.google.play.services)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.teamwable.common.util

object AmplitudeTag {
const val CLICK_POST_UPLOAD = "click_post_upload"
const val CLICK_REPLY_UPLOAD = "click_reply_upload"
const val CLICK_POST_VIEW = "click_post_view"
const val CLICK_POST_LIKE = "click_post_like"
const val CLICK_REPLY_LIKE = "click_reply_like"
const val CLICK_ACCOUNT_JOIN_DONE = "click_account_join_done"
const val CLICK_ACCOUNT_DELETE_DONE = "click_account_delete_done"
}

object AmplitudeSignInTag {
const val CLICK_SIGNIN_KAKAO = "click_signin_kakao"
const val CLICK_AGREE_POPUP_SIGNUP = "click_agree_popup_signup"
}

object AmplitudeSignUpTag {
const val CLICK_NEXT_YEAR_SIGNUP = "click_next_year_signup"
const val CLICK_DETOUR_TEAM_SIGNUP = "click_detour_team_signup"
const val CLICK_NEXT_TEAM_SIGNUP = "click_next_team_signup"
const val CLICK_CHANGE_PICTURE_PROFILE_SIGNUP = "click_change_picture_profile_signup"
const val CLICK_ADD_PICTURE_PROFILE_SIGNUP = "k_add_picture_profile_signup"
const val CLICK_NEXT_PROFILE_SIGNUP = "click_next_profile_signup"
const val CLICK_COMPLETE_TNC_SIGNUP = "click_complete_tnc_signup"
const val CLICK_JOIN_POPUP_SIGNUP = "click_join_popup_signup"
}

object AmplitudeHomeTag {
const val CLICK_HOME_BOTNAVI = "click_home_botnavi"
const val CLICK_NEWS_BOTNAVI = "click_news_botnavi"
const val CLICK_NOTI_BOTNAVI = "click_noti_botnavi"
const val CLICK_MYPROFILE_BOTNAVI = "click_myprofile_botnavi"
const val CLICK_LIKE_POST = "click_like_post"
const val CLICK_GHOST_POST = "click_ghost_post"
const val CLICK_WRITE_POST = "click_write_post"
const val CLICK_DELETE_POST = "click_delete_post"
const val CLICK_WITHDRAWGHOST_POPUP = "click_withdrawghost_popup"
const val CLICK_APPLYGHOST_POPUP = "click_applyghost_popup"
const val CLICK_LIKE_COMMENT = "click_like_comment"
const val CLICK_GHOST_COMMENT = "click_ghost_comment"
const val CLICK_WRITE_COMMENT = "click_write_comment"
const val CLICK_GOBACK_HOME = "click_goback_home"
}

object AmplitudePostTag {
const val CLICK_UPLOAD_POST = "click_upload_post"
const val CLICK_ATTACH_PHOTO = "click_attach_photo"
}

object AmplitudeNewsTag {
const val CLICK_GAMESCHEDULE = "click_gameschedule"
const val CLICK_RANKING = "click_ranking"
}

object AmplitudeNotiTag {
const val CLICK_ACTIVITIESNOTI = "click_activitiesnoti"
const val CLICK_INFONOTI = "click_infonoti"
}

object AmplitudeProfileTag {
const val CLICK_WRITE_FIRSTPOST = "click_write_firstpost"
}

object AmplitudeAuthTag {
const val CLICK_DELETE_ACCOUNT = "click_delete_account"
const val CLICK_NEXT_DELETEREASON = "click_next_deletereason"
const val CLICK_NEXT_DELETEGUIDE = "click_next_deleteguide"
const val CLICK_NEXT_DELETEACCOUNT = "click_done_deleteaccount"
const val CLICK_COMPLETE_LOGOUT = "click_complete_logout"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.teamwable.common.util

import android.content.Context
import com.amplitude.android.Amplitude
import com.amplitude.android.Configuration
import com.teamwable.common.BuildConfig.AMPLITUDE_API_KEY

object AmplitudeUtil {
private lateinit var amplitude: Amplitude

fun initAmplitude(applicationContext: Context) {
val key = AMPLITUDE_API_KEY
amplitude = Amplitude(
Configuration(
apiKey = key,
context = applicationContext,
),
)
}

fun trackEvent(eventTag: String) {
amplitude.track(eventTag)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import android.os.Bundle
import androidx.fragment.app.setFragmentResult
import androidx.navigation.NavController
import androidx.navigation.fragment.findNavController
import com.teamwable.common.util.AmplitudeAuthTag.CLICK_COMPLETE_LOGOUT
import com.teamwable.common.util.AmplitudeAuthTag.CLICK_NEXT_DELETEACCOUNT
import com.teamwable.common.util.AmplitudeHomeTag.CLICK_APPLYGHOST_POPUP
import com.teamwable.common.util.AmplitudeHomeTag.CLICK_WITHDRAWGHOST_POPUP
import com.teamwable.common.util.AmplitudeUtil.trackEvent
import com.teamwable.ui.base.BindingDialogFragment
import com.teamwable.ui.databinding.DialogTwoButtonBinding
import com.teamwable.ui.extensions.DeepLinkDestination
Expand Down Expand Up @@ -49,12 +54,24 @@ class TwoButtonDialog() : BindingDialogFragment<DialogTwoButtonBinding>(DialogTw

private fun initNoBtnClickListener() {
binding.btnDialogTwoButtonNo.setOnClickListener {
when (type) {
DialogType.TRANSPARENCY -> trackEvent(CLICK_WITHDRAWGHOST_POPUP)
else -> Unit
}

findNavController().popBackStack()
}
}

private fun initYesBtnClickListener() {
binding.btnDialogTwoButtonYes.setOnClickListener {
when (type) {
DialogType.TRANSPARENCY -> trackEvent(CLICK_APPLYGHOST_POPUP)
DialogType.DELETE_ACCOUNT -> trackEvent(CLICK_NEXT_DELETEACCOUNT)
DialogType.LOGOUT -> trackEvent(CLICK_COMPLETE_LOGOUT)
else -> Unit
}

val result = Bundle().apply { putString(DIALOG_TYPE, type.name) }
setFragmentResult(DIALOG_RESULT, result)
findNavController().popBackStack()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import android.content.Context
import androidx.fragment.app.FragmentManager
import androidx.lifecycle.LifecycleOwner
import androidx.navigation.NavController
import com.teamwable.common.util.AmplitudeHomeTag.CLICK_GHOST_COMMENT
import com.teamwable.common.util.AmplitudeHomeTag.CLICK_LIKE_COMMENT
import com.teamwable.common.util.AmplitudeUtil.trackEvent
import com.teamwable.model.Comment
import com.teamwable.model.LikeState
import com.teamwable.ui.component.BottomSheet
Expand Down Expand Up @@ -43,6 +46,7 @@ class CommentActionHandler(
}

fun onGhostBtnClick(type: DialogType, updateGhost: () -> Unit) {
trackEvent(CLICK_GHOST_COMMENT)
navigateToDialog(type)
handleDialogResult { dialogType ->
when (dialogType) {
Expand All @@ -55,6 +59,7 @@ class CommentActionHandler(
fun onLikeBtnClick(viewHolder: CommentViewHolder, id: Long, saveLike: (Long, LikeState) -> Unit) {
val likeCount = viewHolder.likeCountTv.text.toString().toInt()
val updatedLikeCount = if (viewHolder.likeBtn.isChecked) {
trackEvent(CLICK_LIKE_COMMENT)
likeCount + 1
} else {
if (likeCount > 0) likeCount - 1 else 0
Expand Down
11 changes: 10 additions & 1 deletion core/ui/src/main/java/com/teamwable/ui/util/FeedActionHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import android.content.Context
import androidx.fragment.app.FragmentManager
import androidx.lifecycle.LifecycleOwner
import androidx.navigation.NavController
import com.teamwable.common.util.AmplitudeHomeTag.CLICK_DELETE_POST
import com.teamwable.common.util.AmplitudeHomeTag.CLICK_GHOST_POST
import com.teamwable.common.util.AmplitudeHomeTag.CLICK_LIKE_POST
import com.teamwable.common.util.AmplitudeUtil.trackEvent
import com.teamwable.model.Feed
import com.teamwable.model.LikeState
import com.teamwable.ui.component.BottomSheet
Expand Down Expand Up @@ -33,7 +37,10 @@ class FeedActionHandler(
}
handleDialogResult { dialogType ->
when (dialogType) {
DialogType.DELETE_FEED -> removeFeed(feed.feedId)
DialogType.DELETE_FEED -> {
trackEvent(CLICK_DELETE_POST)
removeFeed(feed.feedId)
}
DialogType.REPORT -> {
navController.popBackStack()
reportUser(feed.postAuthorNickname, "${feed.title}\n${feed.content}")
Expand All @@ -45,6 +52,7 @@ class FeedActionHandler(
}

fun onGhostBtnClick(type: DialogType, updateGhost: () -> Unit) {
trackEvent(CLICK_GHOST_POST)
navigateToDialog(type)
handleDialogResult { dialogType ->
when (dialogType) {
Expand All @@ -62,6 +70,7 @@ class FeedActionHandler(
fun onLikeBtnClick(viewHolder: FeedViewHolder, id: Long, saveLike: (Long, LikeState) -> Unit) {
val likeCount = viewHolder.likeCountTv.text.toString().toInt()
val updatedLikeCount = if (viewHolder.likeBtn.isChecked) {
trackEvent(CLICK_LIKE_POST)
likeCount + 1
} else {
if (likeCount > 0) likeCount - 1 else 0
Expand Down
4 changes: 4 additions & 0 deletions feature/home/src/main/java/com/teamwable/home/HomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import androidx.paging.LoadState
import androidx.paging.map
import com.google.android.gms.tasks.OnCompleteListener
import com.google.firebase.messaging.FirebaseMessaging
import com.teamwable.common.util.AmplitudeHomeTag.CLICK_WRITE_POST
import com.teamwable.common.util.AmplitudeUtil.trackEvent
import com.teamwable.home.databinding.FragmentHomeBinding
import com.teamwable.model.Feed
import com.teamwable.model.Ghost
Expand Down Expand Up @@ -76,6 +78,7 @@ class HomeFragment : BindingFragment<FragmentHomeBinding>(FragmentHomeBinding::i
navigateToHomeDetailFragment(it.intent.getStringExtra(RELATED_CONTENT_ID)?.toLong() ?: return@let)
it.intent.removeExtra(RELATED_CONTENT_ID)
}

is HomeUiState.AddPushAlarmPermission -> initPushAlarmPermissionAlert()
}
}
Expand Down Expand Up @@ -189,6 +192,7 @@ class HomeFragment : BindingFragment<FragmentHomeBinding>(FragmentHomeBinding::i

private fun initNavigatePostingFabClickListener() {
binding.fabHomeNavigatePosting.setOnClickListener {
trackEvent(CLICK_WRITE_POST)
findNavController().deepLinkNavigateTo(requireContext(), DeepLinkDestination.Posting)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import androidx.navigation.fragment.navArgs
import androidx.paging.LoadState
import androidx.paging.map
import androidx.recyclerview.widget.ConcatAdapter
import com.teamwable.common.util.AmplitudeHomeTag.CLICK_WRITE_COMMENT
import com.teamwable.common.util.AmplitudeUtil.trackEvent
import com.teamwable.home.R
import com.teamwable.home.databinding.FragmentHomeDetailBinding
import com.teamwable.model.Comment
Expand Down Expand Up @@ -166,6 +168,7 @@ class HomeDetailFragment : BindingFragment<FragmentHomeDetailBinding>(FragmentHo

private fun initUploadingActivateBtnClickListener(contentId: Long, commentSnackbar: Snackbar) {
binding.ibHomeDetailCommentInputUpload.setOnDuplicateBlockClick {
trackEvent(CLICK_WRITE_COMMENT)
viewModel.addComment(contentId, binding.etHomeDetailCommentInput.text.toString())
commentSnackbar.show()
binding.etHomeDetailCommentInput.text.clear()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class AppUpdateHandler(private val context: Context) {
appUpdateManager.startUpdateFlowForResult(
appUpdateInfo,
activityResultLauncher,
AppUpdateOptions.newBuilder(AppUpdateType.IMMEDIATE).build(),
AppUpdateOptions.newBuilder(AppUpdateType.FLEXIBLE).build(),
)
}

Expand All @@ -55,7 +55,7 @@ class AppUpdateHandler(private val context: Context) {
appUpdateManager.startUpdateFlowForResult(
appUpdateInfo,
activityResultLauncher,
AppUpdateOptions.newBuilder(AppUpdateType.IMMEDIATE).build(),
AppUpdateOptions.newBuilder(AppUpdateType.FLEXIBLE).build(),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.teamwable.main
import androidx.navigation.NavController
import androidx.navigation.NavOptions
import androidx.navigation.fragment.findNavController
import com.teamwable.common.util.AmplitudeHomeTag.CLICK_GOBACK_HOME
import com.teamwable.common.util.AmplitudeUtil.trackEvent
import com.teamwable.main.databinding.FragmentErrorBinding
import com.teamwable.ui.base.BindingFragment

Expand All @@ -13,6 +15,7 @@ class ErrorFragment : BindingFragment<FragmentErrorBinding>(FragmentErrorBinding

private fun initNavigateToHomeBtnClickListener() {
binding.btnErrorNavigateToHome.setOnClickListener {
trackEvent(CLICK_GOBACK_HOME)
val navController = findNavController()
val navOptions = NavOptions.Builder()
.setPopUpTo(R.id.navigation_error, inclusive = true)
Expand Down
Loading