【iOS】GoogleアナリティクスをiOSアプリに実装する
このGoogleのドキュメント通りだが、Firebase
ではなくGoogle Analytics
だけ使いたい場合にすぐこのページが出てこなかったのでメモを。
- CocoaPodsのPodfileに 'Google/Analytics'を追加
- 設定ファイル(
GoogleService-Info.plist
)を取得、プロジェクトに追加 AppDelegate
に#import <Google/Analytics.h>
を記述didFinishLaunchingWithOptions
に以下の初期設定的な実装を追加
// Configure tracker from GoogleService-Info.plist. NSError *configureError; [[GGLContext sharedInstance] configureWithError:&configureError]; NSAssert(!configureError, @"Error configuring Google services: %@", configureError); // Optional: configure GAI options. GAI *gai = [GAI sharedInstance]; gai.trackUncaughtExceptions = YES; // report uncaught exceptions gai.logger.logLevel = kGAILogLevelVerbose; // remove before app release
あとは、必要に応じたトラッキングを実装する。