This guide shows you how to add App Events to your new or existing app by integrating the Facebook SDK then logging these events.
Changes have been made to the Facebook iOS SDK. We recommend upgrading to the new version of the Facebook iOS SDK. See the Device Consent section for more information about this change.
You will need:
Go to the App Dashboard, click My Apps, and create a new app if you don't already have one. Navigate to Settings > Basic to view the App Details Panel with your App ID, your App Secret, and other details about your app.
Scroll down to the bottom of the page and click Add Platform. Choose iOS, add your app details, and save your changes.
Set up your app for advertising by adding the following details:
To learn more about adding details to your app, such as an icon or category, visit the App Development docs.
To run ads and measure installs in the Ads Manager, associate at least one Ad Account and a Business Account with your App.
The following procedure uses Swift Package Manager to set up your development environment in Xcode.
Add Your Bundle Identifier and enable Single Sign-On for your app.
シングルサインオン iOSお知らせから起動します |
Info.plist
ファイルに、アプリに関するデータが含まれているXMLスニペットを挿入します。 Facebookログインを統合すると、特定のアプリイベントは、アプリイベントの自動記録を無効にしない限り、イベントマネージャのために自動的に記録、収集されます。これは、アプリコードで変更できます。また、アプリダッシュボードかイベントマネージャの[アプリイベント]の下のトグルで切り替えることもできます。AutoLogAppEventsEnabled
のフラグとトグルとの間で値が競合している場合、「Facebook SDKの自動イベント記録」のトグル値が優先されることに注意してください。収集される情報やアプリイベントの自動記録を無効にする方法については、アプリイベントの自動記録をご覧ください。
Info.plist
を右クリックし、[プログラムで開く]▸[ソースコード]を選択します。 <dict>...</dict>
)に貼り付けます。 [CFBundleURLSchemes]
の<array><string>
にあるAPP-IDは、自身のアプリIDに置き換えてください。FacebookAppID
の<string>
にあるAPP-IDは、自身のアプリIDに置き換えてください。FacebookClientToken
の<string>
にあるCLIENT-TOKENは、アプリダッシュボードの[設定 > 高度 > クライアントトークン]にある値に置き換えてください。FacebookDisplayName
の<string>
にあるAPP-NAMEは、実際のアプリ名に置き換えてください。Info.plist
に以下を含める必要があります。 Info.plist
にキーとしてFacebookAutoLogAppEventsEnabled
を追加することで、アプリイベントの自動収集をtrueまたはfalseに直接設定できるようになります。
AppDelegate.swift
内のコードを置き換えます。このコードは、アプリの起動時にSDKを初期化し、ログインアクションやシェアアクションが実行されたときにネイティブFacebookアプリのログインとシェアリングをSDKが処理できるようにします。このコードを使用しない場合は、ユーザーはFacebookにログインした状態で、ログイン用のアプリ内ブラウザーを使用する必要があります。 // AppDelegate.swift import UIKit import FacebookCore @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { ApplicationDelegate.shared.application( application, didFinishLaunchingWithOptions: launchOptions ) return true } func application( _ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:] ) -> Bool { ApplicationDelegate.shared.application( app, open: url, sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String, annotation: options[UIApplication.OpenURLOptionsKey.annotation] ) } }
SceneDelegate
に移動されました。iOS 13以上を使用している場合は、次のメソッドを SceneDelegate
に追加して、ログインや共有機能のような操作を意図したとおりに行えるようにしてください。 // SceneDelegate.swift import FacebookCore ... func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) { guard let url = URLContexts.first?.url else { return } ApplicationDelegate.shared.application( UIApplication.shared, open: url, sourceApplication: nil, annotation: [UIApplication.OpenURLOptionsKey.annotation] ) }
There are three ways events are tracked in your app:
アプリが収集してFacebookに送信するイベントによっては、App Store Connect質問表でそのようなデータタイプを公開するよう求められる場合があります。アプリのプライバシーポリシーでこの点が反映されていることを確認するのは、開発者の責任です。公開する必要があるデータタイプの詳細については、Apple App Storeでのプライバシーに関する詳細情報の記事をご覧ください。
Facebook SDKを使用すると、イベントの自動記録を無効にしない限り、アプリの特定のイベントは自動的に記録、収集され、Facebookイベントマネージャに使用されます。このようなイベントは、ターゲット設定、効果測定、最適化などあらゆるユースケースに関連します。
具体的には、アプリのインストール、アプリの起動、購入という3つの主要イベントが自動で記録されます。自動記録が有効である場合、広告主はこれらのイベントや、ログインインプレッションイベントなどほかのFacebook内部イベントを無効化できます。一方、自動記録を無効にした場合に、インストールや購入などの特定のイベントを記録するには、該当するイベントの記録をアプリ内で手動実装する必要があります。
イベント | 詳細 |
---|---|
アプリのインストール | 新しい利用者がアプリを初めてアクティベートしたとき、または特定のデバイスでアプリが初めて起動されたとき。 |
アプリの起動 | 利用者がアプリを起動し、Facebook SDKが初期化されてイベントがログに記録されたとき。ただし、最初のアプリの起動イベントから60秒以内に2回目のアプリの起動イベントが発生した場合、2回目のイベントはログ記録されません。 |
アプリ内購入 | Apple App StoreまたはGoogle Playにより処理された購入が完了したとき。ほかの支払いプラットフォームを使用している場合、購入イベントコードを手動で追加する必要があります。 |
Facebook SDKクラッシュレポート (Facebookの使用に限定。) | Facebook SDKが原因でアプリがクラッシュした場合、クラッシュレポートが生成されて、アプリの再起動時にFacebookに送られます。このレポートは、ユーザーデータを含んでおらず、FacebookがSDKの品質と安定性を確認する上で役立つものです。このイベントのログ記録をオプトアウトするには、自動でログ記録されるイベントを無効にしてください。 |
Starting with iOS 14.5, you will need to set isAdvertiserTrackingEnabled
and log each time you give a device permission to share data with Facebook.
If a device provides consent, set Settings.shared.isAdvertiserTrackingEnabled = true
.
If a device does not allow tracking, set Settings.shared.isAdvertiserTrackingEnabled = false
.
To disable automatic event logging, open the application's Info.plist
as code in Xcode and add the following XML to the property dictionary:
<key>FacebookAutoLogAppEventsEnabled</key> <false/>
In some cases, you want to delay the collection of automatically logged events, such as to obtain User consent or fulfill legal obligations, instead of disable it. In this case, set Settings.shared.isAutoLogAppEventsEnabled = true
to re-enable auto-logging after the end-user provides consent.
To suspend collection again for any reasons, set Settings.shared.isAutoLogAppEventsEnabled = false
.
You can also disable automatic In-App Purchase event logging using the app dashboard. Go to the iOS card under Basic>Settings and toggle the switch to No.
To disable collection of advertiser-id
, open the application's .plist
as code in Xcode and add the following XML to the property dictionary:
<key>FacebookAdvertiserIDCollectionEnabled</key> <false/>
In some cases, you want to delay the collection of advertiser_id
, such as to obtain User consent or fulfill legal obligations, instead of disabling it. In this case, set Settings.shared.isAdvertiserIDCollectionEnabled = true
after the end-user provides consent.
To suspend collection for any reason, set Settings.shared.isAdvertiserIDCollectionEnabled = false
.
To log a custom event, just pass the name of the event as an AppEvents.Name
:
AppEvents.shared.logEvent(AppEvents.Name("battledAnOrc"))
Facebook has created a set of useful event parameters for inclusion with standard events or with your own custom events. You can also provide your own parameters.
These pre-defined parameters are intended to provide guidance on common logging patterns, and may have a more readable form in reporting and other UIs. Log the set of parameters you're interested in seeing broken down. The recommended description for these are guidance only - you can use these parameters for whatever makes sense for your app.
The parameters are passed via a dictionary where the key holds the parameter name as an AppEvents.ParameterName
, and the value must be either a String
or a number (Int
, Double
, etc.).
The App Ads Helper allows you to test the app events in your app to ensure that your app is sending events to Facebook.
If you plan to optimize/track your events in SKAdNetwork campaigns, you also need to properly configure event priority (also known as conversion value) in order for Facebook to correctly receive the conversions. More details can be found here.
We have created some examples for different app types to make it easier for you to see how you can use app events. Each of the example apps provides a screen by screen breakdown of the different events and parameters that can be collected. At the end of each section, there is a table listing the recommended events and parameters for each app. And, if necessary, you can create your own events and parameters.