Olive Study Room
[Mixpanel in Swift] 믹스패널 사용하기 본문
Mixpanel?
- 서비스가 유저들과 어떻게 상호작용 하고 있는지 파악할 수 있는 사용자 행동 분석 툴
mixpanel github
mixpanel 공식 quickstart
✏️ Setting
1. 라이브러리 설치
// 프로젝트 Podfile
pod 'Mixpanel-swift'
// terminal
pod install
// 사용할 파일
import Mixpanel
2. 초기화
/// AppDelegate
#if DEBUG
let token = Bundle.main.infoDictionary?["TOKEN_DEBUG"] as! String
Mixpanel.initialize(token: token, trackAutomaticEvents: true)
#else
let token = Bundle.main.infoDictionary?["TOKEN_RELEASE"] as! String
Mixpanel.initialize(token: token, trackAutomaticEvents: true)
#endif
✏️ User
1. createAlias
- alias를 생성해주지 않으면 유저 프로퍼티를 지정해도 mixpanel 사이트의 project>Users에서 확인할 수 없다. (아예 유저가 생성되지 않음) → 이벤트는 확인할 수 있음
- alias를 생성해주지 않고 이벤트를 발생시키거나 유저 프로퍼티를 지정한 후 alias를 뒤늦게 생성할 경우 이전 이벤트와 프로퍼티가 그대로 반영된다. (User 에서 확인할 수 있고 alias 생성 이전에 발생한 Event에도 User 정보가 할당됨. 즉 연동된다고 보면 됨) → 이게 Alias의 순 역할!
- 하지만 연동 하려면 연동 이전 이벤트에 대한 distinctId와 연동할 때의 distinctId가 반드시 같아야 함
mixpanel.createAlias("testAlias", distinctId: String(user.id))
2. identify
- 한 번 생성된 유저에 대해(createAlias를 이미 한 경우) 그 유저로 접속할 수 있다.
- mixpanel.identify(distinctId: String(user.id))
✏️ User Property
1. 유저 프로퍼티 세팅
- 디폴트 유저 프로퍼티로 지정되어있는 경우 앞에 $를 붙임
mixpanel.people.set(properties: [
"$name": name, // 디폴트 유저 프로퍼티
"$email": email, // 디폴트 유저 프로퍼티
"State of 시스템 푸시 동의": false,
"State of 마케팅 정보 알림 동의": false,
"Total number of 사진 저장": 0,
"Total number of 알림 설정": 0,
"Total number of 플랫폼 유형": 0,
"Total number of 검색어": 0,
])
2. 유저 프로퍼티 수정
// 값 지정하여 수정
mixpanel.people.set(property: "Total number of 사진 저장", to: 43)
// 증감 값으로 수정
mixpanel.people.increment(property: type.rawValue, by: 1) // +1
✏️ Event track
// 프로퍼티가 없는 경우
mixpanel.track(event: "푸시_알림창 Clicked")
// 프로퍼티가 있는 경우
mixpanel.track(event: "공유_사진 저장 Completed",
properties: [
"초기입력 태그명" : ["솝트", "포토서퍼"]
])
'Coding > iOS' 카테고리의 다른 글
[iOS] UINavigationController, ViewController Life cycle, 화면 전환 (0) | 2022.01.11 |
---|---|
[iOS] Cocoa touch(UIKit, Foundation) (0) | 2021.10.10 |
[Swift, iOS] Swift 개요와 개발환경 (0) | 2021.10.07 |
[Swift] 소수점 다루기 (0) | 2021.06.23 |
[Swift] Map VS compactMap VS flatMap (0) | 2021.06.23 |
Comments