Skip to content

Commit

Permalink
Merge pull request #85 from Team-HMH/feat/#82-Aplitude
Browse files Browse the repository at this point in the history
Feat [#82] Amplitude 추가
  • Loading branch information
kim-seonwoo authored Sep 2, 2024
2 parents 7d7dc7c + aa0db19 commit cbfc1c7
Show file tree
Hide file tree
Showing 15 changed files with 141 additions and 9 deletions.
2 changes: 2 additions & 0 deletions HMH_iOS/HMH-iOS-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>AMPLITUDE_API_KEY</key>
<string>$(AMPLITUDE_API_KEY)</string>
<key>BASE_URL</key>
<string>$(BASE_URL)</string>
<key>BGTaskSchedulerPermittedIdentifiers</key>
Expand Down
37 changes: 37 additions & 0 deletions HMH_iOS/HMH_iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
0B3C296F2BA01C2800435B30 /* HomeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B3C296E2BA01C2800435B30 /* HomeView.swift */; };
0B3C29712BA01C3000435B30 /* MyPageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B3C29702BA01C3000435B30 /* MyPageView.swift */; };
0B3C29732BA01DCE00435B30 /* CustomTabView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B3C29722BA01DCE00435B30 /* CustomTabView.swift */; };
0B3DC0842C6C804C0021AC61 /* Amplitude in Frameworks */ = {isa = PBXBuildFile; productRef = 0B3DC0832C6C804C0021AC61 /* Amplitude */; };
0B3DC0862C6C80880021AC61 /* Amplitude in Frameworks */ = {isa = PBXBuildFile; productRef = 0B3DC0852C6C80880021AC61 /* Amplitude */; };
0B5140542BE3A2D600C78B9F /* LoginView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B5140532BE3A2D600C78B9F /* LoginView.swift */; };
0B6301562C15B8C20020B375 /* ServicePrepareView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B6301552C15B8C20020B375 /* ServicePrepareView.swift */; };
0B6301582C15E0DF0020B375 /* GetEarnPointResponseDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B6301572C15E0DF0020B375 /* GetEarnPointResponseDTO.swift */; };
Expand All @@ -25,6 +27,8 @@
0B6A836B2C0864640095060C /* UserPointResponseDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B6A836A2C0864640095060C /* UserPointResponseDTO.swift */; };
0B6A836E2C08C0520095060C /* HMHToastView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B6A836D2C08C0520095060C /* HMHToastView.swift */; };
0B719C382BF1C45D00DF1D92 /* CustomAlertModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B719C372BF1C45D00DF1D92 /* CustomAlertModifier.swift */; };
0B7222372C6A09A4005EB365 /* Amplitude in Frameworks */ = {isa = PBXBuildFile; productRef = 0B7222362C6A09A4005EB365 /* Amplitude */; };
0B7222392C6B48ED005EB365 /* OnboardingAmplitudeModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B7222382C6B48EC005EB365 /* OnboardingAmplitudeModel.swift */; };
0B7646BB2BB13F6100C56D7A /* SurveyButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B7646BA2BB13F6100C56D7A /* SurveyButton.swift */; };
0B82ECB02BC9152F002D5CF3 /* MyPageViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B82ECAF2BC9152F002D5CF3 /* MyPageViewModel.swift */; };
0B82ECB22BC916C6002D5CF3 /* MyPageButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B82ECB12BC916C6002D5CF3 /* MyPageButton.swift */; };
Expand Down Expand Up @@ -285,6 +289,7 @@
0B6A836A2C0864640095060C /* UserPointResponseDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserPointResponseDTO.swift; sourceTree = "<group>"; };
0B6A836D2C08C0520095060C /* HMHToastView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HMHToastView.swift; sourceTree = "<group>"; };
0B719C372BF1C45D00DF1D92 /* CustomAlertModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomAlertModifier.swift; sourceTree = "<group>"; };
0B7222382C6B48EC005EB365 /* OnboardingAmplitudeModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingAmplitudeModel.swift; sourceTree = "<group>"; };
0B7646BA2BB13F6100C56D7A /* SurveyButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SurveyButton.swift; sourceTree = "<group>"; };
0B82ECAF2BC9152F002D5CF3 /* MyPageViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyPageViewModel.swift; sourceTree = "<group>"; };
0B82ECB12BC916C6002D5CF3 /* MyPageButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyPageButton.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -420,6 +425,7 @@
0B8693912BE8B99E000D7CE1 /* KakaoSDKCommon in Frameworks */,
365CD6D52B7E4CE900245CDD /* RxMoya in Frameworks */,
365CD6CF2B7E4CE900245CDD /* CombineMoya in Frameworks */,
0B7222372C6A09A4005EB365 /* Amplitude in Frameworks */,
365CD6DE2B7E4D4E00245CDD /* Then in Frameworks */,
0BDDA0172C005A53001BD43E /* KeychainAccess in Frameworks */,
365CD6DB2B7E4D3600245CDD /* SnapKit in Frameworks */,
Expand All @@ -436,6 +442,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
0B3DC0842C6C804C0021AC61 /* Amplitude in Frameworks */,
3672443C2BF32481007A5A7B /* DeviceActivity.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -461,6 +468,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
0B3DC0862C6C80880021AC61 /* Amplitude in Frameworks */,
3606F3702C07A8B6002A1386 /* Lottie in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -644,6 +652,7 @@
isa = PBXGroup;
children = (
0BC0E5A82BB03EE400FB0330 /* OnboardingModel.swift */,
0B7222382C6B48EC005EB365 /* OnboardingAmplitudeModel.swift */,
);
path = Models;
sourceTree = "<group>";
Expand Down Expand Up @@ -1071,6 +1080,7 @@
0B8693902BE8B99E000D7CE1 /* KakaoSDKCommon */,
0B8693922BE8B99E000D7CE1 /* KakaoSDKUser */,
0BDDA0162C005A53001BD43E /* KeychainAccess */,
0B7222362C6A09A4005EB365 /* Amplitude */,
);
productName = HMH_iOS;
productReference = 365CD6B92B7E4C4F00245CDD /* HMH_iOS.app */;
Expand All @@ -1090,6 +1100,7 @@
);
name = DeviceActivityMonitor;
packageProductDependencies = (
0B3DC0832C6C804C0021AC61 /* Amplitude */,
);
productName = DeviceActivityMonitor;
productReference = 3672443B2BF32481007A5A7B /* DeviceActivityMonitor.appex */;
Expand Down Expand Up @@ -1145,6 +1156,7 @@
name = HMHDeviceActivityReport;
packageProductDependencies = (
3606F36F2C07A8B6002A1386 /* Lottie */,
0B3DC0852C6C80880021AC61 /* Amplitude */,
);
productName = HMHDeviceActivityReport;
productReference = 368C5D942BCC41990035A1AC /* HMHDeviceActivityReport.appex */;
Expand Down Expand Up @@ -1194,6 +1206,7 @@
365CD6DC2B7E4D4E00245CDD /* XCRemoteSwiftPackageReference "Then" */,
0B86938B2BE8B99E000D7CE1 /* XCRemoteSwiftPackageReference "kakao-ios-sdk" */,
0BDDA0152C005A53001BD43E /* XCRemoteSwiftPackageReference "KeychainAccess" */,
0B7222352C6A09A4005EB365 /* XCRemoteSwiftPackageReference "Amplitude-iOS" */,
);
productRefGroup = 365CD6BA2B7E4C4F00245CDD /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -1364,6 +1377,7 @@
367243E62BEDEAF8007A5A7B /* SignUpRequestDTO.swift in Sources */,
36B833BF2C5A3107009C2C3E /* ChallengeHeaderView.swift in Sources */,
3606F35F2C078CA8002A1386 /* DeviceActivityMonitorExtension.swift in Sources */,
0B7222392C6B48ED005EB365 /* OnboardingAmplitudeModel.swift in Sources */,
0B6301582C15E0DF0020B375 /* GetEarnPointResponseDTO.swift in Sources */,
367244092BEDEC7F007A5A7B /* Providers.swift in Sources */,
368780E32C024DAD00454827 /* CustomButtonModifer.swift in Sources */,
Expand Down Expand Up @@ -1937,6 +1951,14 @@
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
0B7222352C6A09A4005EB365 /* XCRemoteSwiftPackageReference "Amplitude-iOS" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/amplitude/Amplitude-iOS";
requirement = {
branch = main;
kind = branch;
};
};
0B86938B2BE8B99E000D7CE1 /* XCRemoteSwiftPackageReference "kakao-ios-sdk" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/kakao/kakao-ios-sdk";
Expand Down Expand Up @@ -1996,6 +2018,21 @@
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
0B3DC0832C6C804C0021AC61 /* Amplitude */ = {
isa = XCSwiftPackageProductDependency;
package = 0B7222352C6A09A4005EB365 /* XCRemoteSwiftPackageReference "Amplitude-iOS" */;
productName = Amplitude;
};
0B3DC0852C6C80880021AC61 /* Amplitude */ = {
isa = XCSwiftPackageProductDependency;
package = 0B7222352C6A09A4005EB365 /* XCRemoteSwiftPackageReference "Amplitude-iOS" */;
productName = Amplitude;
};
0B7222362C6A09A4005EB365 /* Amplitude */ = {
isa = XCSwiftPackageProductDependency;
package = 0B7222352C6A09A4005EB365 /* XCRemoteSwiftPackageReference "Amplitude-iOS" */;
productName = Amplitude;
};
0B86938C2BE8B99E000D7CE1 /* KakaoSDK */ = {
isa = XCSwiftPackageProductDependency;
package = 0B86938B2BE8B99E000D7CE1 /* XCRemoteSwiftPackageReference "kakao-ios-sdk" */;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,24 @@
"version" : "5.9.1"
}
},
{
"identity" : "amplitude-ios",
"kind" : "remoteSourceControl",
"location" : "https://github.com/amplitude/Amplitude-iOS",
"state" : {
"branch" : "main",
"revision" : "b7a66d2d9935d3244bc3275d8071acc4b1f0c6a5"
}
},
{
"identity" : "analytics-connector-ios",
"kind" : "remoteSourceControl",
"location" : "https://github.com/amplitude/analytics-connector-ios.git",
"state" : {
"revision" : "e2ca17ac735bcbc48b13062484541702ef45153d",
"version" : "1.0.3"
}
},
{
"identity" : "kakao-ios-sdk",
"kind" : "remoteSourceControl",
Expand Down
7 changes: 7 additions & 0 deletions HMH_iOS/HMH_iOS/Global/Application/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import UIKit
import SwiftUI
import UserNotifications
import BackgroundTasks
import Amplitude

class AppDelegate: NSObject, UIApplicationDelegate {
let amplitudeAPIKey = Bundle.main.infoDictionary?["AMPLITUDE_API_KEY"] as! String
var appStateViewModel = AppStateViewModel.shared
let taskIdentifier = "com.HMH.dailyTask"

Expand All @@ -26,6 +28,11 @@ class AppDelegate: NSObject, UIApplicationDelegate {
registerBackgroundTasks()
scheduleDailyResetTask()

Amplitude.instance().defaultTracking.sessions = true
Amplitude.instance().defaultTracking.screenViews = true
Amplitude.instance().defaultTracking = AMPDefaultTrackingOptions.initWithAllEnabled()
Amplitude.instance().initializeApiKey(amplitudeAPIKey)

return true
}

Expand Down
8 changes: 8 additions & 0 deletions HMH_iOS/HMH_iOS/Global/Manager/NotificationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import UserNotifications
import UIKit
import SwiftUI

import Amplitude

class NotificationManager: NSObject, UNUserNotificationCenterDelegate {
static let shared = NotificationManager()

Expand All @@ -33,6 +35,7 @@ class NotificationManager: NSObject, UNUserNotificationCenterDelegate {
AppStateViewModel.shared.onAppear()
AppStateViewModel.shared.currentAlertType = .usePoints
AppStateViewModel.shared.showCustomAlert = true
Amplitude.instance().logEvent("view_unlock_popup")
completionHandler()
}

Expand All @@ -58,11 +61,15 @@ class AppStateViewModel: ObservableObject {
case .usePoints:
currentAlertType = .unlock
case .unlock:
Amplitude.instance().logEvent("click_unlock_button")
patchPointUse()
getUsagePoint()
case .unlockComplete:
Amplitude.instance().logEvent("click_unlock_complete_button")
showCustomAlert = false
case .insufficientPoints:
Amplitude.instance().logEvent("click_unlock_buypoint")
Amplitude.instance().logEvent("view_shop", withEventProperties: ["view_type": "click_unlock_buypoint"] )
showCustomAlert = false
UserManager.shared.appStateString = "servicePrepare"
default:
Expand All @@ -77,6 +84,7 @@ class AppStateViewModel: ObservableObject {
func onAppear() {
getUsagePoint()
getCurrentPoint()
Amplitude.instance().logEvent("view_unlock_popup")
}

/// 포인트 사용해서 잠금 해제하는 부분
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import SwiftUI
import FamilyControls

import Amplitude

enum ChallengeType {
case empty
case normal
Expand Down Expand Up @@ -70,6 +72,7 @@ final class ChallengeViewModel: ObservableObject {
func challengeButtonTapped() {
if !(statuses.contains("UNEARNED")) {
navigateToCreate = true
Amplitude.instance().logEvent("click_newchallenge_button")
} else {
isToastPresented = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import Foundation

import Amplitude

final class PointViewModel: ObservableObject {
@Published var challengeDay = 1
@Published var currentPoint = 0
Expand Down Expand Up @@ -39,6 +41,8 @@ final class PointViewModel: ObservableObject {
// 앱 잠금해제시에 사용될 포인트를 조회하는 api입니다.

func patchEarnPoint(day: Int) {
Amplitude.instance().logEvent("click_getpoint_button", withEventProperties: ["get_point_date": day + 1] )

let date = pointList[day].challengeDate
let request = PointRequestDTO(challengeDate: date)
Providers.pointProvider.request(target: .patchEarnPoint(data: request),
Expand All @@ -52,6 +56,8 @@ final class PointViewModel: ObservableObject {
// 하루하루 챌린지를 성공하고, 포인트를 받는 버튼을 눌렀을 때, 포인트를 받는 API

func getPointList() {
Amplitude.instance().logEvent("view_point")

Providers.pointProvider.request(target: .getPointList,
instance: BaseResponse<PointListResponseDTO>.self) { result in
guard let data = result.data else { return }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import SwiftUI
import FamilyControls
import ManagedSettings
import DeviceActivity
import Amplitude

@MainActor
final class ScreenTimeViewModel: ObservableObject {
Expand Down Expand Up @@ -43,6 +44,8 @@ final class ScreenTimeViewModel: ObservableObject {
DispatchQueue.main.async {
self.selectedApp = newSelection
}

Amplitude.instance().logEvent("click_add_complete")
}

func requestAuthorization() {
Expand Down
4 changes: 2 additions & 2 deletions HMH_iOS/HMH_iOS/Presentation/Common/Custom/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ struct ContentView: View {
SplashView(viewModel: loginViewModel)
} else {
switch userManager.appState {
case .onboarding:
case .home:
OnboardingContentView()
case .onboardingComplete:
OnboardingCompleteView()
case .servicePrepare:
ServicePrepareView()
case .home:
case .onboarding:
TabBarView(showGuideView: $showGuideView)
.onAppear {
appStateViewModel.onAppear()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import SwiftUI
import FamilyControls
import DeviceActivity
import Combine
import Amplitude

class HomeViewModel: ObservableObject {
@AppStorage(AppStorageKey.totalGoalTime.rawValue, store: UserDefaults(suiteName: APP_GROUP_NAME))
Expand Down Expand Up @@ -49,4 +50,11 @@ class HomeViewModel: ObservableObject {
return (hours, minutes, seconds)
}

func addButtonClicked() {
Amplitude.instance().logEvent("click_add_button")
}

func editButtonClicked() {
Amplitude.instance().logEvent("click_edit_button")
}
}
4 changes: 4 additions & 0 deletions HMH_iOS/HMH_iOS/Presentation/Home/Views/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import SwiftUI
import FamilyControls
import DeviceActivity

import Amplitude
import Lottie

struct HomeView: View {
Expand Down Expand Up @@ -73,6 +74,7 @@ extension HomeView {
Spacer()
Button(action: {
isPresented = true
homeViewModel.editButtonClicked()
}, label: {
Text("편집")
.font(.text4_semibold_16)
Expand All @@ -82,12 +84,14 @@ extension HomeView {
selection: screenTimeViewModel.$selectedApp)
.onChange(of: screenTimeViewModel.selectedApp) { newSelection in
screenTimeViewModel.selectedApp = newSelection
Amplitude.instance().logEvent("complete_add_new")
}
}
DeviceActivityReport(appContext, filter: appFilter)
.frame(height: 72 * CGFloat(screenTimeViewModel.selectedApp.applicationTokens.count))
Button(action: {
isPresented = true
homeViewModel.addButtonClicked()
}, label: {
Image(.appAddBtn)
.resizable()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import SwiftUI
import Amplitude
import AuthenticationServices

import KakaoSDKUser
Expand All @@ -14,6 +15,8 @@ class LoginViewModel: NSObject, ObservableObject {
}

func handleAppleLogin() {
Amplitude.instance().logEvent("click_onboarding_apple")

let request = ASAuthorizationAppleIDProvider().createRequest()
request.requestedScopes = [.fullName, .email]

Expand All @@ -23,6 +26,8 @@ class LoginViewModel: NSObject, ObservableObject {
}

func handleKakaoLogin() {
Amplitude.instance().logEvent("click_onboarding_kakao")

if (UserApi.isKakaoTalkLoginAvailable()) {
UserApi.shared.loginWithKakaoTalk {(oauthToken, error) in
if let error = error {
Expand Down
Loading

0 comments on commit cbfc1c7

Please sign in to comment.