Skip to content

Commit

Permalink
feat: Search log 추가 (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
hryeong66 committed Sep 2, 2024
1 parent b905d33 commit 0709348
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import PPACModels
import PPACDomain
import PPACNetwork
import PPACData
import PPACAnalytics

import MemeDetail

@MainActor
Expand Down Expand Up @@ -68,8 +70,9 @@ public final class SearchResultViewModel: ViewModelType, ObservableObject {
await fetchData()
case .memeDetailTapped(let meme):
router?.showMemeDetail(memeDetail: meme)
logSearch(event: .meme, keyword: state.keyword)
case .memeCopyTapped(let meme):
await copyImage(urlString: meme.imageUrlString)
await copyImage(meme: meme)
break
case .naviBackButtonTapped:
router?.popView()
Expand All @@ -87,12 +90,39 @@ public final class SearchResultViewModel: ViewModelType, ObservableObject {
}

@MainActor
private func copyImage(urlString: String) async {
private func copyImage(meme: MemeDetail) async {
do {
try await copyImageUseCase.execute(url: urlString)
try await copyImageUseCase.execute(url: meme.imageUrlString)
state.isActiveCopyPopup = true
logSearch(event: .copy, meme: meme)
} catch(let error) {
debugPrint("error = \(error)")
}
}

func logSearch(
event: PPACAnalytics.UserEvent,
keyword: String? = nil,
pageCount: Int? = nil,
meme: MemeDetail? = nil
) {
var parameters: [String: Any] = [:]

if let keyword {
parameters["keyword_name"] = keyword
}

if let pageCount {
parameters["page_count"] = pageCount
}

PPACAnalytics.shared
.log(interaction: .click,
event: event,
page: .searchDetail,
memeId: meme?.id,
memeTitle: meme?.title,
extraParameters: parameters
)
}
}
1 change: 1 addition & 0 deletions Projects/Features/Search/Sources/View/SearchView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public struct SearchView: View {
keywords: memeCategory.keywords
) { keyword in
viewModel.dispatch(type: .recommendKeywordTapped(keyword: keyword))
viewModel.logSearch(event: .keyword, keyword: keyword, category: memeCategory.category)
}
}
}
Expand Down
27 changes: 27 additions & 0 deletions Projects/Features/Search/Sources/View/SearchViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import PPACModels
import PPACDomain
import PPACNetwork
import PPACData
import PPACAnalytics

import MemeDetail

@MainActor
Expand Down Expand Up @@ -67,10 +69,12 @@ public final class SearchViewModel: ViewModelType, ObservableObject {
await fetchData()
case .searchBarTapped:
state.isPresenting = true
logSearch(event: .searchBar)
case .dismissSearchBarAlert:
state.isPresenting = false
case .hotKeywordTapped(let keyword):
router?.showSearchResult(keyword: keyword)
logSearch(event: .hotKeyword, keyword: keyword)
case .recommendKeywordTapped(let keyword):
router?.showSearchResult(keyword: keyword)
}
Expand All @@ -88,4 +92,27 @@ public final class SearchViewModel: ViewModelType, ObservableObject {
debugPrint("error = \(error)")
}
}

func logSearch(
event: PPACAnalytics.UserEvent,
keyword: String? = nil,
category: String? = nil
) {
var parameters: [String: Any] = [:]

if let keyword {
parameters["keyword_name"] = keyword
}

if let category {
parameters["category"] = category
}

PPACAnalytics.shared
.log(interaction: .click,
event: event,
page: .search,
extraParameters: parameters
)
}
}

0 comments on commit 0709348

Please sign in to comment.