1. 程式人生 > >Getting Started with App Events-iOS

Getting Started with App Events-iOS

1. Select an App or Create a New App

Please select an app or create a new one to get a Facebook App ID.

Setup Your App Details for Advertising

  1. Go to your App Dashboard and select the app you wish to update.
  2. In the left side navigation panel of the App Dashboard, click Settings > Basic to view the App Details
    Panel with your App ID, your App Secret, and other details about your app.
  3. To set up your app for advertising set the following details:
  • App Domains - Provide Apple App Store URL of your app.
  • Platform - Scroll to the bottom of the Settings panel to add the iOS Platform.
  • Privacy Policy URL - You must provide a
    Privacy Policy
    URL. Must be provided to take your app public.
  • Terms of Service URL - You must provide a Terms of Service URL.
See the App Development docs to add more details, an icon or category, to your app.

To run ads and measure installs in the

Ads Manager, you need to associate at least one Ad Account with your App.

  1. In the App Dashboard click Settings > Advanced.
  2. In Authorized Add Account IDs, add your Ad Account IDs. You can get your ad account IDs from your Ads Manager.
  3. If you also have a business account, in Authorized Businesses, add your Business Manager ID. You can find your business manager id in the URL of your Business Manager

3. Set Up Your Development Environment

  1. Install Cocoapods - Open a terminal window and run:
    sudo gem install cocoapods
  2. Go to the project directory of the existing project
  3. (Optional) If you haven't used Cocoapods in your project, create a pod file for the project. In a terminal window, run:
    pod init
  4. Add the following line to the pod file of your project:
    pod 'FacebookSDK' 
  5. Install the Facebook SDK. In the terminal window, run the following command:
     pod install 
    For Swift:
    • Add the following to the AppDelegate.swift file:
      import FBSDKCoreKit
    • Add the following line to this function:
      application(_ application: UIApplication, 
      didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool
      func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
      
        // Add any custom logic here.
        
        return true
      }
      
      func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
        let handled = FBSDKApplicationDelegate.sharedInstance().application(app, open: url, options: options)
      
        // Add any custom logic here.
        
        return handled
      }
    For Objective-C:
    • Add the following to the AppDelegate.m file:
      #import <FBSDKCoreKit/FBSDKCoreKit.h>
    • Add the following to the (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions function in the AppDelegate.m file:
      - (BOOL)application:(UIApplication *)application 
          didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
      		  
          [[FBSDKApplicationDelegate sharedInstance] application:application
          didFinishLaunchingWithOptions:launchOptions];
      
          // Add any custom logic here.
          return YES;
      }
      		
      - (BOOL)application:(UIApplication *)application 
          openURL:(NSURL *)url 
      		options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
      		
          BOOL handled = [[FBSDKApplicationDelegate sharedInstance] application:application
              openURL:url
      		    sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
      		    annotation:options[UIApplicationOpenURLOptionsAnnotationKey]
          		];
      
        // Add any custom logic here.
      	return handled;
      }

4. Configure Your Information Property List

In Xcode, right-click info.plist and choose Open As Source Code.

  • If your code does not have CFBundleURLTypes add the following just before the final </dict> element:
    <key>CFBundleURLTypes</key>
    <array>
      <dict>
      <key>CFBundleURLSchemes</key>
      <array>
        <string>fb[APP_ID]</string>
      </array>
      </dict>
    </array>
    <key>FacebookAppID</key>
    <string>[APP_ID]</string>
    <key>FacebookDisplayName</key>
    <string>[APP_NAME]</string>
  • If your code already contains CFBundleURLTypes insert the following:
    <array>
      <dict>
      <key>CFBundleURLSchemes</key>
      <array>
        <string>fb[APP_ID]</string>
      </array>
      </dict>
    </array>
    <key>FacebookAppID</key>
    <string>[APP_ID]</string>
    <key>FacebookDisplayName</key>
    <string>[APP_NAME]</string>
  • In the XML snippet, replace the following:
    • [APP_ID] with the App ID of your app.
    • [APP_NAME] with the name of your app.

5. Build and Run Your Project in the Simulator

In Xcode, select an iOS simulator and click Run. Xcode builds your project and then launches the most recent version of your app running in Simulator.

6. Add App Events

There are three types of App Events: Automatically Logged Events, Standard Events, popular events that Facebook has created for you, and Custom Events, events you create that are specific to your app.

You can set up standard events and custom events events in two ways:

  • Use our codeless set up tool in Facebook's Events Manager: This is a simple tool for setting up events without implementing codes. You can interact with app screen elements such as buttons, images or links to define event names. As your users navigate through the app and interact with these UI elements, events will be sent to Facebook.

  • Install your app event codes manually: You will need to add event codes manually to your app. To learn where to place your App Event code in your app, we have example apps with a screen by screen breakdown of the different events and parameters that can be collected in our Best Practices Guide.

The instructions below are for version 4.0 and higher of the SDK. If you are still using version 3.X, you will need to omit "SDK" from your App Event calls. For example, you would use FBAppEvents instead of FBSDKAppEvents.

Automatically Logged Events

Beginning with v3.22, the Facebook iOS SDK automatically logs app installs, app sessions, and in-app purchases.

After you integrate the Facebook SDK into your app, these events are automatically logged.

EventDetails

App Install

The first time a new user activates an app or the first time an app starts on a particular device.

App Launch

When the Facebook SDK is initialized in your app for each session.

In-App Purchase

When a purchase processed by the Apple App Store or Google Play has been completed. If you use other payments platforms, you will need to add purchase event code manually.

In-app purchases are automatically logged in new apps created after October 4, 2017. For apps created before that date, enable in-app purchase events in Settings in the app dashboard.

Disable Automatically Logged Events

To disable automatic event logging, open the application's .plist as code in Xcode and add the following XML to the property dictionary:

<key>FacebookAutoLogAppEventsEnabled</key>
<false/>

In some cases, you may wish to only delay the collection of automatically logged events, such as to obtain user consent or fulfill legal obligations. Open the application's .plist as code in Xcode and add the same XML to the property dictionary:

<key>FacebookAutoLogAppEventsEnabled</key>
<false/>

Then re-enable auto-logging after an end-user provides consent, by calling the setAutoLogAppEventsEnabled method of the FBSDKSettings class.

For Swift:

FBSDKSettings.setAutoLogAppEventsEnabled(true)

For Objective-C:

[FBSDKSettings setAutoLogAppEventsEnabled:YES];

To suspend collection again for any reasons, add the following line.

For Swift:

FBSDKSettings.setAutoLogAppEventsEnabled(false)

For Objective-C:

[FBSDKSettings setAutoLogAppEventsEnabled:NO];

Standard Events

You can add standard events, see the Event Names and Event Parameters below, to your app. Use the Code Generator to get the code for these events.

To Generate Code for a Standard Event

  1. Choose the Standard Event tab.
  2. In Event Name, choose a standard event.
  3. Choose Get Code.
  4. In the window, select a language to see the code to copy and paste into your app.

Take a look at our Example Apps to view some scenarios of using App Events.

Standard Event Names

Event Name: FBSDKAppEventName valueToSum Parameters

Achieved Level:

FBSDKAppEventNameAchievedLevel

Level

Launched the App:

FBSDKAppEventNameActivatedApp

Clicked on an Ad:

FBSDKAppEventNameAdClick

AdType

Shown an Ad:

FBSDKAppEventNameAdImpression

AdType

Added Payment Info:

FBSDKAppEventNameAddedPaymentInfo

Success

Added To Cart:

FBSDKAppEventNameAddedToCart

Price of item added

ContentType, ContentID or Content, and Currency

Added To Wishlist:

FBSDKAppEventNameAddedToWishlist

Price of item added

ContentType, ContentID or Content, and Currency

Completed Registration:

FBSDKAppEventNameCompletedRegistration

RegistrationMethod

Completed Tutorial:

FBSDKAppEventNameCompletedTutorial

Success, and ContentID or Content

Added Contact Information:

FBSDKAppEventNameContact

Customized a Product:

FBSDKAppEventNameCustomizeProduct

Donated:

FBSDKAppEventNameDonate

Searched for a Location:

FBSDKAppEventNameFindLocation

Initiated Checkout:

FBSDKAppEventNameInitiatedCheckout

Total price of items in cart

ContentType, ContentID or Content, NumItems, PaymentInfoAvailable, and Currency

Purchased:

`FBSDKAppEventNamePurchased`

Use the logPurchase method instead.

Purchase price

NumItems, ContentType, ContentID or Content, and Currency

Rated:

FBSDKAppEventNameRated

Rating given

ContentType, ContentID or Content, and MaxRatingValue

Scheduled:

FBSDKAppEventNameSchedule

Searched:

FBSDKAppEventNameSearched

ContentType, SearchString, and Success

Spent Credits:

FBSDKAppEventNameSpentCredits

Total value of credits spent

ContentType, and ContentID or Content

Started a Trial:

FBSDKAppEventNameStartTrial

Price of Subscription

OrderID

and

Currency

Submitted an Application:

FBSDKAppEventNameSubmitApplication

Subscription:

FBSDKAppEventNameSubscription

Price of Subscription

OrderID

and

Currency

Unlocked Achievement:

FBSDKAppEventNameUnlockedAchievement

Description

Viewed Content:

FBSDKAppEventNameViewedContent

Price of item viewed (if applicable)

ContentType, ContentID or Content, and Currency

Parameters

The table below are typically useful parameters for inclusion with the events shown above, or with your own custom events. You can also provide your own parameters as well.

These pre-defined parameters are intended to provide guidance on typically useful logging patterns, and may have a more readable form in reporting and other UI. Log the set of parameters you're interested in seeing broken down in Analytics. 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 an NSDictionary where the key holds the parameter name as an NSString (iOS SDK constants for the pre-defined ones are listed below), and the value must be either an NSString or an NSNumber:

Parameter: FBSDKAppEventParameterName Possible Values Description

Ad Type:

FBSDKAppEventParameterNameAdType

string

Type of ad: banner, interstitial, reward_video, native

Content:

FBSDKAppEventParameterNameContent

string

A list of JSON object that contains the International Article Number (EAN) when applicable, or other product or content identifier(s) as well as additional information about the products. id, quantity, and item_price are the available fields. e.g. "[{\"id\": \"1234\", \"quantity\": 2, \"item_price\": 5.99}, {\"id\": \"5678\", \"quantity\": 1, \"item_price\": 9.99}]"

Content ID:

FBSDKAppEventParameterNameContentID

string

International Article Number (EAN) when applicable, or other product or content identifier

Content Type:

FBSDKAppEventParameterNameContentType

string

product or product_group

Currency:

FBSDKAppEventParameterNameCurrency

string

ISO 4217 code, e.g., EUR, USD, JPY

Description:

FBSDKAppEventParameterNameDescription

string

A string description

Level:

FBSDKAppEventParameterNameLevel

string

Level of a player

Max. Rating Value:

FBSDKAppEventParameterNameMaxRatingValue

int

Upper bounds of a rating scale, for example 5 on a 5 star scale

Number of Items:

FBSDKAppEventParameterNameNumItems

int

Number of items

Order ID:

FBSDKAppEventParameterNameOrderID

string

The unique ID for all events within a subscription

Payment Info Available:

FBSDKAppEventParameterNamePaymentInfoAvailable

1 or 0

1 for yes, 0 for no

Registration Method:

FBSDKAppEventParameterNameRegistrationMethod

string

Facebook, Email, Twitter, etc.

Search String:

FBSDKAppEventParameterNameSearchString

string

The text string that was searched for

Success:

FBSDKAppEventParameterNameSuccess

1 or 0

1 for yes, 0 for no

Custom App Events

You can also choose to create your own custom events. Use the Code Generator to generate code for these events.

Do not use event as the name of a parameter. Custom parameters with the name event will not be logged. Use another name or add a prefix or suffix to the name, such as my_custom_event.

To Generate Code for a Custom Event

  1. Choose the Custom Event tab.
  2. In Event Name, enter the name of your event.
  3. Click Add Event Paramter if you'd like to add parameters to your event.
  4. Click Get Code.
  5. In the window, select a language to get the code to copy and paste into your app.

To log a custom event, just pass the name of the event as an NSString:

[FBSDKAppEvents logEvent:@"battledAnOrc"];

Example Apps

We have created some examples for different app types in order 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 required, you can create your own events and parameters.

It is important to note that these guides should be used as a starting point for your app and should be customized by you.

7. Test Your Events

The App Ads Helper allows you to test the app events in your app to ensure that your app is sending events to Facebook.

b. In Select an App, choose your app and choose Submit.

c. Go to the bottom and choose Test App Events.

d. Start your app and send an event. The event appears on the web page.

相關推薦

Getting Started with App Events-iOS

1. Select an App or Create a New App Please select an app or create a new one to get a Facebook App ID. Setup Your App Details for Advertising Go to your

Getting Started with iOS App Development

Explore the tools, technologies, capabilities, and languages included in the iOS SDK that make app development possible. Some iOS SDK essentials

Getting Started with Android App Development

As an open platform, Android developers have a few choices for distributing apps to users, customers, developers, and business associates. For pu

LLVM每日談之十九 LLVM的第一本系統的書&lt;Getting Started with LLVM Core Libraries&gt;

關於 日本 簡單的 lvm 作者 普通 lan 最好 裏的 作者:史寧寧(snsn1984)LLVM最終有了一本系統的書了——《Getting Started with LLVM Core Libraries》。這本書號稱是LLVM的第一本書,可是據說日本早就有兩本日文的

Getting started with Kentico

sbo short conf doc body his learn cati site https://docs.kentico.com/k10tutorial https://docs.kentico.com/k10tutorial/getting-started

[原創]Getting Started with Skywalking

-c java word nta rec compress tar mbed already Getting Started with Skywalking Pre JDK 1.8+ Skywalking(v3.2.6) (All packages can

Getting started with docker - 1.Orientation and setup

Get Started, Part 1: Orientation and setup Get Started, Part 1: Orientation and setup Docker concepts Images and cont

Getting Started with Processing 第四章總結

為什麼要使用變數: 我們使用變數的一個重要原因就是避免變成過程中的重複工作,如果你重複使用某一個數字超過了一次,就可以考慮使用一個變數來代替它,這樣你的程式會更加通用並且易於更新。 定義變數 定義變數的時候,要確定其變數名(name),資料型別(data type) 和變數值 value.在 Proce

Getting Started with Processing 第五章的easing問題

分析 使用 easing easing 的感官目的是為了 draw 的時候,畫的圖形不是即時 mouseX 的值,而是稍有落後一點。從演算法分析,就是讓所畫圖形的 x 座標 落後於 mouseX 的值,並且朝 mouseX 的方向進行運動。程式如下: float x; float easing =

Getting Started with Processing 第五章的easing問題(2)

上一個 第五章 RoCE mouse process 一次 成了 參數 二維 程序代碼清單如下: float x; float y; float px; float py; float easing = 0.05; void setup(){ size(480,120)

Getting Started with Processing 第五章的總結

Getting Started with Processing 第五章:響應 一次與永久 setup()函式 Processing 中,setup()函式只執行一次,用於設定一些初始的值,比如畫布的大小,還有填充和線條粗細,顏色的程式碼。第一行總是size(),接下啦是其他宣告。 draw()函式

Getting started with Processing 第七章總結

媒體 如何將檔案匯入 Processing 中 在 Processing 中,程式是通過應用 data 資料夾中的檔案來顯示的,這個資料夾可以通過選單欄中的 Sketch>show sketch folder(command+K),來顯示,可以通過兩個辦法新增檔案: 打卡data資料夾,向其

[2] Getting Started With Data Reflections

Getting Started With Data Reflections Why Data Reflections? 分析中通常涉及較大資料集和資源密集型的操作,資料分析和資料科學家需要較高效的互動式查詢來完成他們的分析工作,其中分析任務多是迭代關聯性的,每一

Getting Started with XlsxWriter

下面是一些關於使用XlsxWriter模組的簡單介紹。   安裝XlsxWriter 下面的是幾個安裝XlsxWriter模組的方法: 1、使用Pip 使用pip 方式是最推薦的從PyPi安裝Python模組的方法。 Python 安裝包索引: 2、使用 Easy_install

Getting Started with Processing 第十章——物件

不像原始資料型別boolean,int 和 float 只能存一個值,一個物件可以存很多值。但這也是我們講的一部分,物件也是用相關函式將變數編組的一種方式。 域和方法 在物件的上下文中,一個變數被叫做一個值域(field),一個函式被叫做一個方法(method)。值域和方法的工作原理與函式和變數一樣 類

Getting Started with Processing 第十章——對象

int oat ext get dom started 不返回 類定義 ole 不像原始數據類型boolean,int 和 float 只能存一個值,一個對象可以存很多值。但這也是我們講的一部分,對象也是用相關函數將變量編組的一種方式。 域和方法 在對象的上下文中,一個變量

Getting started with Processing 示例11-9 追隨鼠標移動

總結 數組 繼續 並且 隨機數 tar The get for 程序片段 int num = 60; int[] x = new int[num]; int[] y = new int[num]; void setup(){ size(240,120); noStrok

Getting started with Processing 示例11-9 追隨滑鼠移動

程式片段 int num = 60; int[] x = new int[num]; int[] y = new int[num]; void setup(){ size(240,120); noStroke(); } void draw(){ background(0); //from back

Getting started with Processing 第十一章——陣列

Getting started with Processing 第十一章——陣列 從變數到陣列: 使用陣列,無需為每一個變數建立一個新的名稱/這讓程式碼變得更短,更容易理解,更方便更新。 建立陣列的三個步驟 建立一個數組,需要經過三個步驟: 宣告陣列,定義資料型別。這裡的資料型別可以是任何型別

Getting started with Processing 第十三章——延伸(1)

匯入庫: 匯入庫的名稱為:import processing.libName.* 聲音 播放聲音 支援的格式:wav,aiff,mp3宣告: SoundFile blip;建立:blip = new SoundFile(this,"filename");物件可以使用的函式:loop() 和 play(