0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Swift】Mixpanelの使い方

Posted at

はじめに

たぶんFirebaseEventsの上位互換です。
Xcode側での設定を載せるのでアカウント側の設定はドキュメントを見てください。

インストール

① 「File」を選択します
② 「Add Packages...」を選択します
スクリーンショット 2023-03-12 19.45.15.png

https://github.com/mixpanel/mixpanel-swiftを検索します
④ 「Dependency Rule」を設定します
⑤ 「Add Package」を選択します
スクリーンショット 2023-03-12 19.51.13.png

⑥ 「Add Package」を選択します
スクリーンショット 2023-03-12 19.54.40.png

初期化

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")

おわり

集計したデータを元にアプリを改善していきたいです。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?