Skip to content

Commit 1d8e15e

Browse files
committed
[feat] #208 amplitude - 링크 상세, 저장
1 parent 0c63176 commit 1d8e15e

File tree

6 files changed

+77
-26
lines changed

6 files changed

+77
-26
lines changed

Projects/CoreKit/Sources/Core/Analytics/AnalyticsEvent.swift

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ public enum AnalyticsEvent {
1111
case view_home_pokit(entryPoint: String)
1212
case view_home_recommend(entryPoint: String)
1313
case add_folder(folderName: String)
14-
case add_link(folderId: String, linkDomain: String)
14+
case add_link(folderId: String, linkDomain: String, entryPoint: String? = nil, linkId: String? = nil, positionIndex: Int? = nil, algoVersion: String? = nil)
1515
case view_folder_detail(folderId: String)
16-
case view_link_detail(linkId: String, linkDomain: String)
16+
case view_link_detail(linkId: String, linkDomain: String, entryPoint: String? = nil, positionIndex: Int? = nil, cardType: String? = nil, algoVersion: String? = nil)
1717
case share_link(linkId: String, shareTarget: String)
1818
case session_end(duration: Int)
1919

@@ -70,20 +70,46 @@ public enum AnalyticsEvent {
7070
case let .add_folder(folderName):
7171
return [PropertyKey.folder_name.rawValue: folderName]
7272

73-
case let .add_link(folderId, linkDomain):
74-
return [
73+
case let .add_link(folderId, linkDomain, entryPoint, linkId, positionIndex, algoVersion):
74+
var props: [String: Any] = [
7575
PropertyKey.folder_id.rawValue: folderId,
7676
PropertyKey.link_domain.rawValue: linkDomain
7777
]
78+
if let entryPoint = entryPoint {
79+
props[PropertyKey.entry_point.rawValue] = entryPoint
80+
}
81+
if let linkId = linkId {
82+
props[PropertyKey.link_id.rawValue] = linkId
83+
}
84+
if let positionIndex = positionIndex {
85+
props[PropertyKey.position_index.rawValue] = positionIndex
86+
}
87+
if let algoVersion = algoVersion {
88+
props[PropertyKey.algo_version.rawValue] = algoVersion
89+
}
90+
return props
7891

7992
case let .view_folder_detail(folderId):
8093
return [PropertyKey.folder_id.rawValue: folderId]
8194

82-
case let .view_link_detail(linkId, linkDomain):
83-
return [
95+
case let .view_link_detail(linkId, linkDomain, entryPoint, positionIndex, cardType, algoVersion):
96+
var props: [String: Any] = [
8497
PropertyKey.link_id.rawValue: linkId,
8598
PropertyKey.link_domain.rawValue: linkDomain
8699
]
100+
if let entryPoint = entryPoint {
101+
props[PropertyKey.entry_point.rawValue] = entryPoint
102+
}
103+
if let positionIndex = positionIndex {
104+
props[PropertyKey.position_index.rawValue] = positionIndex
105+
}
106+
if let cardType = cardType {
107+
props[PropertyKey.card_type.rawValue] = cardType
108+
}
109+
if let algoVersion = algoVersion {
110+
props[PropertyKey.algo_version.rawValue] = algoVersion
111+
}
112+
return props
87113

88114
case let .share_link(linkId, shareTarget):
89115
return [
@@ -110,6 +136,9 @@ public enum PropertyKey: String {
110136
case link_id
111137
case share_target
112138
case duration
139+
case position_index
140+
case card_type
141+
case algo_version
113142
}
114143

115144
/// 로그인 방식

Projects/CoreKit/Sources/Data/Network/Content/ContentClient+LiveKey.swift

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,7 @@ extension ContentClient: DependencyKey {
1818
try await provider.requestNoBody(.컨텐츠_삭제(contentId: id))
1919
},
2020
컨텐츠_상세_조회: { id in
21-
let response: ContentDetailResponse
22-
response = try await provider.request(.컨텐츠_상세_조회(contentId: id))
23-
amplitudeTrack(.view_link_detail(
24-
linkId: "\(id)",
25-
linkDomain: response.data
26-
))
27-
return response
21+
try await provider.request(.컨텐츠_상세_조회(contentId: id))
2822
},
2923
컨텐츠_수정: { id, model in
3024
try await provider.request(.컨텐츠_수정(contentId: id, model: model))

Projects/Feature/FeatureContentCard/Sources/ContentCard/ContentCardFeature.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ public struct ContentCardFeature {
2121
private var openURL
2222
@Dependency(ContentClient.self)
2323
private var contentClient
24+
@Dependency(\.amplitude.track)
25+
private var amplitudeTrack
26+
2427
/// - State
2528
@ObservableState
2629
public struct State: Equatable, Identifiable {
@@ -113,7 +116,11 @@ private extension ContentCardFeature {
113116
guard let url = URL(string: state.content.data) else {
114117
return .none
115118
}
116-
return .run { send in
119+
return .run { [content = state.content] send in
120+
amplitudeTrack(.view_link_detail(
121+
linkId: "\(content.id)",
122+
linkDomain: content.data
123+
))
117124
await send(.async(.컨텐츠_상세_조회_API))
118125
await openURL(url)
119126
}

Projects/Feature/FeatureContentSetting/Sources/ContentSetting/ContentSettingFeature.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,11 @@ private extension ContentSettingFeature {
444444
thumbNail: state.domain.thumbNail
445445
)
446446
return .run { send in
447-
let content = try await contentClient.컨텐츠_추가(request)
447+
let response = try await contentClient.컨텐츠_추가(request)
448+
amplitudeTrack(.add_link(
449+
folderId: "\(response.contentId)",
450+
linkDomain: response.data
451+
))
448452
await send(.inner(.선택한_포킷_인메모리_삭제))
449453
await send(.delegate(.저장하기_완료(category: category)))
450454
} catch: { error, send in

Projects/Feature/FeatureRecommend/Sources/Recommend/RecommendFeature.swift

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ public struct RecommendFeature {
2323
private var categoryClient
2424
@Dependency(\.openURL)
2525
private var openURL
26+
@Dependency(\.amplitude.track)
27+
private var amplitudeTrack
28+
2629
/// - State
2730
@ObservableState
2831
public struct State: Equatable {
@@ -87,7 +90,7 @@ public struct RecommendFeature {
8790
case 링크_공유_완료되었을때
8891
case 검색_버튼_눌렀을때
8992
case 알림_버튼_눌렀을때
90-
case 추천_컨텐츠_눌렀을때(String)
93+
case 추천_컨텐츠_눌렀을때(BaseContentItem)
9194
case 경고시트_dismiss
9295
case 포킷선택_항목_눌렀을때(pokit: BaseCategoryItem)
9396
case 포킷_추가하기_버튼_눌렀을때
@@ -211,8 +214,17 @@ private extension RecommendFeature {
211214
return .send(.delegate(.검색_버튼_눌렀을때))
212215
case .알림_버튼_눌렀을때:
213216
return .send(.delegate(.알림_버튼_눌렀을때))
214-
case let .추천_컨텐츠_눌렀을때(urlString):
215-
guard let url = URL(string: urlString) else { return .none }
217+
case let .추천_컨텐츠_눌렀을때(content):
218+
guard let url = URL(string: content.data) else { return .none }
219+
let index = state.recommendedList?.index(id: content.id)
220+
amplitudeTrack(.view_link_detail(
221+
linkId: "\(content.id)",
222+
linkDomain: content.data,
223+
entryPoint: "recommend",
224+
positionIndex: index,
225+
cardType: "list",
226+
algoVersion: "v1.2"
227+
))
216228
return .run { _ in await openURL(url) }
217229
case .관심사_편집_버튼_눌렀을때:
218230
state.showKeywordSheet = true
@@ -355,12 +367,8 @@ private extension RecommendFeature {
355367
)
356368
return categoryListFetch(request: request)
357369
case .컨텐츠_추가_API:
358-
guard
359-
let categoryId = state.selectedPokit?.id,
360-
let category = state.domain.categoryListInQuiry.data?.first(where: {
361-
$0.id == categoryId
362-
}),
363-
let content = state.addContent
370+
guard let categoryId = state.selectedPokit?.id,
371+
let content = state.addContent
364372
else { return .none }
365373
let request = ContentBaseRequest(
366374
data: content.data,
@@ -370,8 +378,17 @@ private extension RecommendFeature {
370378
alertYn: "NO",
371379
thumbNail: content.thumbNail
372380
)
381+
let index = state.recommendedList?.index(id: content.id)
373382
return .run { send in
374-
let content = try await contentClient.컨텐츠_추가(request)
383+
let response = try await contentClient.컨텐츠_추가(request)
384+
amplitudeTrack(.add_link(
385+
folderId: "\(categoryId)",
386+
linkDomain: content.data,
387+
entryPoint: "recommend",
388+
linkId: "\(response.contentId)",
389+
positionIndex: index,
390+
algoVersion: "v1.2"
391+
))
375392
await send(.delegate(.저장하기_완료))
376393
}
377394
}

Projects/Feature/FeatureRecommend/Sources/Recommend/RecommendView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ private extension RecommendView {
196196

197197
@ViewBuilder
198198
func recommendedCard(_ content: BaseContentItem) -> some View {
199-
Button(action: { send(.추천_컨텐츠_눌렀을때(content.data)) }) {
199+
Button(action: { send(.추천_컨텐츠_눌렀을때(content)) }) {
200200
recomendedCardLabel(content)
201201
}
202202
}

0 commit comments

Comments
 (0)