Client-side event logging for specialized application analytics available through Facebook App Insights and for use with Facebook Ads conversion tracking and optimization.
The FBSDKAppEvents
static class has a few related roles:
+ Logging predefined and application-defined events to Facebook App Insights with a
numeric value to sum across a large number of events, and an optional set of key/value
parameters that define "segments" for this event (e.g., 'purchaserStatus' : 'frequent', or
'gamerLevel' : 'intermediate')
+ Logging events to later be used for ads optimization around lifetime value.
+ Methods that control the way in which events are flushed out to the Facebook servers.
Here are some important characteristics of the logging mechanism provided by FBSDKAppEvents
:
+ Events are not sent immediately when logged. They're cached and flushed out to the Facebook servers
in a number of situations:
- when an event count threshold is passed (currently 100 logged events).
- when a time threshold is passed (currently 15 seconds).
- when an app has gone to background and is then brought back to the foreground.
+ Events will be accumulated when the app is in a disconnected state, and sent when the connection is
restored and one of the above 'flush' conditions are met.
+ The FBSDKAppEvents
class is thread-safe in that events may be logged from any of the app's threads.
+ The developer can set the flushBehavior
on FBSDKAppEvents
to force the flushing of events to only
occur on an explicit call to the flush
method.
+ The developer can turn on console debug output for event logging and flushing to the server by using
the FBSDKLoggingBehaviorAppEvents
value in [FBSettings setLoggingBehavior:]
.
Some things to note when logging events:
+ There is a limit on the number of unique event names an app can use, on the order of 1000.
+ There is a limit to the number of unique parameter names in the provided parameters that can
be used per event, on the order of 25. This is not just for an individual call, but for all
invocations for that eventName.
+ Event names and parameter names (the keys in the NSDictionary) must be between 2 and 40 characters, and
must consist of alphanumeric characters, _, -, or spaces.
+ The length of each parameter value can be no more than on the order of 100 characters.
Superclass: | NSObject |
Declared in: | FBSDKAppEvents.h |
activateApp
Notifies the events system that the app has launched and, when appropriate, logs an "activated app" event. Should typically be placed in the
app delegates' applicationDidBecomeActive:
method.
This method also takes care of logging the event indicating the first time this app has been launched, which, among other things, is used to
track user acquisition and app install ads conversions.
+ (void)
activateApp;
activateApp
will not log an event on every app launch, since launches happen every time the app is backgrounded and then foregrounded.
"activated app" events will be logged when the app has not been active for more than 60 seconds. This method also causes a "deactivated app"
event to be logged when sessions are "completed", and these events are logged with the session length, with an indication of how much
time has elapsed between sessions, and with the number of background/foreground interruptions that session had. This data
is all visible in your app's App Events Insights.
FBSDKAppEvents.h
flush
Explicitly kick off flushing of events to Facebook. This is an asynchronous method, but it does initiate an immediate
kick off. Server failures will be reported through the NotificationCenter with notification ID FBSDKAppEventsLoggingResultNotification
.
+ (void)
flush;
FBSDKAppEvents.h
flushBehavior
Get the current event flushing behavior specifying when events are sent back to Facebook servers.
+ (FBSDKAppEventsFlushBehavior)
flushBehavior;
FBSDKAppEvents.h
logEvent:
Log an event with just an eventName.
パラメーター | 説明 |
---|---|
eventName | The name of the event to record. Limitations on number of events and name length
are given in the |
+ (void)
logEvent:(NSString *)eventName;
FBSDKAppEvents.h
logEvent:parameters:
Log an event with an eventName and a set of key/value pairs in the parameters dictionary. Parameter limitations are described above.
パラメーター | 説明 |
---|---|
eventName | The name of the event to record. Limitations on number of events and name construction
are given in the |
parameters | Arbitrary parameter dictionary of characteristics. The keys to this dictionary must
be NSString's, and the values are expected to be NSString or NSNumber. Limitations on the number of
parameters and name construction are given in the |
+ (void)
logEvent: | (NSString *)eventName |
parameters: | (NSDictionary *)parameters; |
FBSDKAppEvents.h
logEvent:valueToSum:
Log an event with an eventName and a numeric value to be aggregated with other events of this name.
パラメーター | 説明 |
---|---|
eventName | The name of the event to record. Limitations on number of events and name length
are given in the |
valueToSum | Amount to be aggregated into all events of this eventName, and App Insights will report the cumulative and average value of this amount. |
+ (void)
logEvent: | (NSString *)eventName |
valueToSum: | (double)valueToSum; |
FBSDKAppEvents.h
logEvent:valueToSum:parameters:
Log an event with an eventName, a numeric value to be aggregated with other events of this name, and a set of key/value pairs in the parameters dictionary.
パラメーター | 説明 |
---|---|
eventName | The name of the event to record. Limitations on number of events and name construction
are given in the |
valueToSum | Amount to be aggregated into all events of this eventName, and App Insights will report the cumulative and average value of this amount. |
parameters | Arbitrary parameter dictionary of characteristics. The keys to this dictionary must
be NSString's, and the values are expected to be NSString or NSNumber. Limitations on the number of
parameters and name construction are given in the |
+ (void)
logEvent: | (NSString *)eventName |
valueToSum: | (double)valueToSum |
parameters: | (NSDictionary *)parameters; |
FBSDKAppEvents.h
logEvent:valueToSum:parameters:accessToken:
Log an event with an eventName, a numeric value to be aggregated with other events of this name,
and a set of key/value pairs in the parameters dictionary. Providing session lets the developer
target a particular FBSession
. If nil is provided, then [FBSession activeSession]
will be used.
パラメーター | 説明 |
---|---|
eventName | The name of the event to record. Limitations on number of events and name construction
are given in the |
valueToSum | Amount to be aggregated into all events of this eventName, and App Insights will report
the cumulative and average value of this amount. Note that this is an NSNumber, and a value of |
parameters | Arbitrary parameter dictionary of characteristics. The keys to this dictionary must
be NSString's, and the values are expected to be NSString or NSNumber. Limitations on the number of
parameters and name construction are given in the |
accessToken | The optional access token to log the event as. |
+ (void)
logEvent: | (NSString *)eventName |
valueToSum: | (NSNumber *)valueToSum |
parameters: | (NSDictionary *)parameters |
accessToken: | (FBSDKAccessToken *)accessToken; |
FBSDKAppEvents.h
loggingOverrideAppID
Get the 'override' App ID for App Event logging.
+ (NSString *)
loggingOverrideAppID;
FBSDKAppEvents.h
logPurchase:currency:
Log a purchase of the specified amount, in the specified currency.
パラメーター | 説明 |
---|---|
purchaseAmount | Purchase amount to be logged, as expressed in the specified currency. This value will be rounded to the thousandths place (e.g., 12.34567 becomes 12.346). |
currency | Currency, is denoted as, e.g. "USD", "EUR", "GBP". See ISO-4217 for specific values. One reference for these is <http://en.wikipedia.org/wiki/ISO_4217>. |
+ (void)
logPurchase: | (double)purchaseAmount |
currency: | (NSString *)currency; |
This event immediately triggers a flush of the FBSDKAppEvents
event queue, unless the flushBehavior
is set
to FBSDKAppEventsFlushBehaviorExplicitOnly
.
FBSDKAppEvents.h
logPurchase:currency:parameters:
Log a purchase of the specified amount, in the specified currency, also providing a set of additional characteristics describing the purchase.
パラメーター | 説明 |
---|---|
purchaseAmount | Purchase amount to be logged, as expressed in the specified currency.This value will be rounded to the thousandths place (e.g., 12.34567 becomes 12.346). |
currency | Currency, is denoted as, e.g. "USD", "EUR", "GBP". See ISO-4217 for specific values. One reference for these is <http://en.wikipedia.org/wiki/ISO_4217>. |
parameters | Arbitrary parameter dictionary of characteristics. The keys to this dictionary must
be NSString's, and the values are expected to be NSString or NSNumber. Limitations on the number of
parameters and name construction are given in the |
+ (void)
logPurchase: | (double)purchaseAmount |
currency: | (NSString *)currency |
parameters: | (NSDictionary *)parameters; |
This event immediately triggers a flush of the FBSDKAppEvents
event queue, unless the flushBehavior
is set
to FBSDKAppEventsFlushBehaviorExplicitOnly
.
FBSDKAppEvents.h
logPurchase:currency:parameters:accessToken:
Log a purchase of the specified amount, in the specified currency, also providing a set of
additional characteristics describing the purchase, as well as an FBSession
to log to.
パラメーター | 説明 |
---|---|
purchaseAmount | Purchase amount to be logged, as expressed in the specified currency.This value will be rounded to the thousandths place (e.g., 12.34567 becomes 12.346). |
currency | Currency, is denoted as, e.g. "USD", "EUR", "GBP". See ISO-4217 for specific values. One reference for these is <http://en.wikipedia.org/wiki/ISO_4217>. |
parameters | Arbitrary parameter dictionary of characteristics. The keys to this dictionary must
be NSString's, and the values are expected to be NSString or NSNumber. Limitations on the number of
parameters and name construction are given in the |
accessToken | The optional access token to log the event as. |
+ (void)
logPurchase: | (double)purchaseAmount |
currency: | (NSString *)currency |
parameters: | (NSDictionary *)parameters |
accessToken: | (FBSDKAccessToken *)accessToken; |
This event immediately triggers a flush of the FBSDKAppEvents
event queue, unless the flushBehavior
is set
to FBSDKAppEventsFlushBehaviorExplicitOnly
.
FBSDKAppEvents.h
requestForCustomAudienceThirdPartyIDWithAccessToken:
Creates a request representing the Graph API call to retrieve a Custom Audience "third party ID" for the app's Facebook user. Callers will send this ID back to their own servers, collect up a set to create a Facebook Custom Audience with, and then use the resultant Custom Audience to target ads.
パラメーター | 説明 |
---|---|
accessToken | The access token to use to establish the user's identity for users logged into Facebook through this app.
If |
+ (FBSDKGraphRequest *)
requestForCustomAudienceThirdPartyIDWithAccessToken:(FBSDKAccessToken *)accessToken;
The JSON in the request's response will include an "custom_audience_third_party_id" key/value pair, with the value being the ID retrieved.
This ID is an encrypted encoding of the Facebook user's ID and the invoking Facebook app ID.
Multiple calls with the same user will return different IDs, thus these IDs cannot be used to correlate behavior
across devices or applications, and are only meaningful when sent back to Facebook for creating Custom Audiences.
The ID retrieved represents the Facebook user identified in the following way: if the specified access token is valid,
the ID will represent the user associated with that token; otherwise the ID will represent the user logged into the
native Facebook app on the device. If there is no native Facebook app, no one is logged into it, or the user has opted out
at the iOS level from ad tracking, then a nil
ID will be returned.
This method returns nil
if either the user has opted-out (via iOS) from Ad Tracking, the app itself has limited event usage
via the [FBSDKSettings limitEventAndDataUsage]
flag, or a specific Facebook user cannot be identified.
FBSDKAppEvents.h
setFlushBehavior:
Set the current event flushing behavior specifying when events are sent back to Facebook servers.
パラメーター | 説明 |
---|---|
flushBehavior | The desired |
+ (void)
setFlushBehavior:(FBSDKAppEventsFlushBehavior)flushBehavior;
FBSDKAppEvents.h
setLoggingOverrideAppID:
Set the 'override' App ID for App Event logging.
パラメーター | 説明 |
---|---|
appID | The Facebook App ID to be used for App Event logging. |
+ (void)
setLoggingOverrideAppID:(NSString *)appID;
In some cases, apps want to use one Facebook App ID for login and social presence and another
for App Event logging. (An example is if multiple apps from the same company share an app ID for login, but
want distinct logging.) By default, this value is nil
, and defers to the FBSDKAppEventsOverrideAppIDBundleKey
plist value. If that's not set, it defaults to [FBSDKSettings appID]
.
This should be set before any other calls are made to FBSDKAppEvents
. Thus, you should set it in your application
delegate's application:didFinishLaunchingWithOptions:
delegate.
FBSDKAppEvents.h
FBSDKAppEventNameAchievedLevel
FBSDK_EXTER N NSString *const FBSDKAppEventNameAchievedLevel;
Log this event when the user has achieved a level in the app.
FBSDKAppEvents.h
FBSDKAppEventNameAddedPaymentInfo
FBSDK_EXTER N NSString *const FBSDKAppEventNameAddedPaymentInfo;
Log this event when the user has entered their payment info.
FBSDKAppEvents.h
FBSDKAppEventNameAddedToCart
FBSDK_EXTER N NSString *const FBSDKAppEventNameAddedToCart;
Log this event when the user has added an item to their cart. The valueToSum passed to logEvent should be the item's price.
FBSDKAppEvents.h
FBSDKAppEventNameAddedToWishlist
FBSDK_EXTER N NSString *const FBSDKAppEventNameAddedToWishlist;
Log this event when the user has added an item to their wishlist. The valueToSum passed to logEvent should be the item's price.
FBSDKAppEvents.h
FBSDKAppEventNameCompletedRegistration
FBSDK_EXTER N NSString *const FBSDKAppEventNameCompletedRegistration;
Log this event when a user has completed registration with the app.
FBSDKAppEvents.h
FBSDKAppEventNameCompletedTutorial
FBSDK_EXTER N NSString *const FBSDKAppEventNameCompletedTutorial;
Log this event when the user has completed a tutorial in the app.
FBSDKAppEvents.h
FBSDKAppEventNameInitiatedCheckout
FBSDK_EXTER N NSString *const FBSDKAppEventNameInitiatedCheckout;
Log this event when the user has entered the checkout process. The valueToSum passed to logEvent should be the total price in the cart.
FBSDKAppEvents.h
FBSDKAppEventNameRated
FBSDK_EXTER N NSString *const FBSDKAppEventNameRated;
Log this event when the user has rated an item in the app. The valueToSum passed to logEvent should be the numeric rating.
FBSDKAppEvents.h
FBSDKAppEventNameSearched
FBSDK_EXTER N NSString *const FBSDKAppEventNameSearched;
Log this event when a user has performed a search within the app.
FBSDKAppEvents.h
FBSDKAppEventNameSpentCredits
FBSDK_EXTER N NSString *const FBSDKAppEventNameSpentCredits;
Log this event when the user has spent app credits. The valueToSum passed to logEvent should be the number of credits spent.
FBSDKAppEvents.h
FBSDKAppEventNameUnlockedAchievement
FBSDK_EXTER N NSString *const FBSDKAppEventNameUnlockedAchievement;
Log this event when the user has unlocked an achievement in the app.
FBSDKAppEvents.h
FBSDKAppEventNameViewedContent
FBSDK_EXTER N NSString *const FBSDKAppEventNameViewedContent;
Log this event when a user has viewed a form of content in the app.
FBSDKAppEvents.h
FBSDKAppEventParameterNameContentID
FBSDK_EXTER N NSString *const FBSDKAppEventParameterNameContentID;
Parameter key used to specify an ID for the specific piece of content being logged about. Could be an EAN, article identifier, etc., depending on the nature of the app.
FBSDKAppEvents.h
FBSDKAppEventParameterNameContentType
FBSDK_EXTER N NSString *const FBSDKAppEventParameterNameContentType;
Parameter key used to specify a generic content type/family for the logged event, e.g. "music", "photo", "video". Options to use will vary based upon what the app is all about.
FBSDKAppEvents.h
FBSDKAppEventParameterNameCurrency
FBSDK_EXTER N NSString *const FBSDKAppEventParameterNameCurrency;
Parameter key used to specify currency used with logged event. E.g. "USD", "EUR", "GBP". See ISO-4217 for specific values. One reference for these is http://en.wikipedia.org/wiki/ISO_4217
.
FBSDKAppEvents.h
FBSDKAppEventParameterNameDescription
FBSDK_EXTER N NSString *const FBSDKAppEventParameterNameDescription;
Parameter key used to specify a description appropriate to the event being logged. E.g., the name of the achievement unlocked in the FBAppEventNameAchievementUnlocked
event.
FBSDKAppEvents.h
FBSDKAppEventParameterNameLevel
FBSDK_EXTER N NSString *const FBSDKAppEventParameterNameLevel;
Parameter key used to specify the level achieved in a FBAppEventNameAchieved
event.
FBSDKAppEvents.h
FBSDKAppEventParameterNameMaxRatingValue
FBSDK_EXTER N NSString *const FBSDKAppEventParameterNameMaxRatingValue;
Parameter key used to specify the maximum rating available for the FBAppEventNameRate
event. E.g., "5" or "10".
FBSDKAppEvents.h
FBSDKAppEventParameterNameNumItems
FBSDK_EXTER N NSString *const FBSDKAppEventParameterNameNumItems;
Parameter key used to specify how many items are being processed for an FBAppEventNameInitiatedCheckout
or FBAppEventNamePurchased
event.
FBSDKAppEvents.h
FBSDKAppEventParameterNamePaymentInfoAvailable
FBSDK_EXTER N NSString *const FBSDKAppEventParameterNamePaymentInfoAvailable;
Parameter key used to specify whether payment info is available for the FBAppEventNameInitiatedCheckout
event. FBSDKAppEventParameterValueYes
and FBSDKAppEventParameterValueNo
are good canonical values to use for this parameter.
FBSDKAppEvents.h
FBSDKAppEventParameterNameRegistrationMethod
FBSDK_EXTER N NSString *const FBSDKAppEventParameterNameRegistrationMethod;
Parameter key used to specify method user has used to register for the app, e.g., "Facebook", "email", "Twitter", etc
FBSDKAppEvents.h
FBSDKAppEventParameterNameSearchString
FBSDK_EXTER N NSString *const FBSDKAppEventParameterNameSearchString;
Parameter key used to specify the string provided by the user for a search operation.
FBSDKAppEvents.h
FBSDKAppEventParameterNameSuccess
FBSDK_EXTER N NSString *const FBSDKAppEventParameterNameSuccess;
Parameter key used to specify whether the activity being logged about was successful or not. FBSDKAppEventParameterValueYes
and FBSDKAppEventParameterValueNo
are good canonical values to use for this parameter.
FBSDKAppEvents.h
FBSDKAppEventParameterValueNo
FBSDK_EXTER N NSString *const FBSDKAppEventParameterValueNo;
No-valued parameter value to be used with parameter keys that need a Yes/No value
FBSDKAppEvents.h
FBSDKAppEventParameterValueYes
FBSDK_EXTER N NSString *const FBSDKAppEventParameterValueYes;
Yes-valued parameter value to be used with parameter keys that need a Yes/No value
FBSDKAppEvents.h
FBSDKAppEventsLoggingResultNotification
FBSDK_EXTER N NSString *const FBSDKAppEventsLoggingResultNotification;
FBSDKAppEvents.h
FBSDKAppEventsOverrideAppIDBundleKey
FBSDK_EXTER N NSString *const FBSDKAppEventsOverrideAppIDBundleKey;
FBSDKAppEvents.h
NS_ENUM
Specifies when FBSDKAppEvents
sends log events to the server.
typedef NS_ENUM(NSUInteger, FBSDKAppEventsFlushBehavior) { /*! Flush automatically: periodically (once a minute or every 100 logged events) and always at app reactivation. */ FBSDKAppEventsFlushBehaviorAuto = 0, /*! Only flush when the `flush` method is called. When an app is moved to background/terminated, the */ FBSDKAppEventsFlushBehaviorExplicitOnly, };
定数 | 説明 |
---|---|
FBSDKAppEventsFlushBehaviorAuto | Flush automatically: periodically (once a minute or every 100 logged events) and always at app reactivation. |
FBSDKAppEventsFlushBehaviorExplicitOnly | Only flush when the |
(NSUInteger, FBSDKAppEventsFlushBehavior)
FBSDKAppEvents.h