はじめに
たぶんFirebaseEventsの上位互換です。
Xcode側での設定を載せるのでアカウント側の設定はドキュメントを見てください。
インストール
① 「File」を選択します
② 「Add Packages...」を選択します
③ https://github.com/mixpanel/mixpanel-swift
を検索します
④ 「Dependency Rule」を設定します
⑤ 「Add Package」を選択します
初期化
AppDelegate
import UIKit
import Mixpanel
class AppDelegate: NSObject, UIApplicationDelegate {
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil
) -> Bool {
// `MIXPANEL_TOKEN`にはアカウントのトークンを入力する
Mixpanel.initialize(token: "MIXPANEL_TOKEN", trackAutomaticEvents: true)
return true
}
}
SampleApp
import SwiftUI
@main
struct SampleApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
イベントを送信する
任意の場所に以下のコードをペーストします。
event
に渡した文字列がイベントを判別するキーになります。
Mixpanel.mainInstance().track(event: "sample button tapped")
おわり
集計したデータを元にアプリを改善していきたいです。