Client-side event logging for specialized application analytics available through Facebook Insights and Conversion Pixel conversion tracking for ads optimization.
The FBInsights
static class has a few related roles:
Logging predefined events to Facebook Application 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 'purchase' events to later be used for ads optimization around lifetime value.
Logging 'conversion pixels' for use in ads conversion tracking and optimization.
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 FBInsights
:
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 FBInsights
class in thread-safe in that events may be logged from any of the app's threads.
Some things to note when logging events:
Inherits from: | NSObject |
Declared in: | FBInsights.h |
appVersion
Gets the application version to the provided string. Insights allows breakdown of events by app version.
+ (NSString *)
appVersion;
FBInsights.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 FBInsightsLoggingResultNotification
.
+ (void)
flush;
FBInsights.h
flushBehavior
Get the current event flushing behavior specifying when events are sent back to Facebook servers.
+ (FBInsightsFlushBehavior)
flushBehavior;
FBInsights.h
logConversionPixel:valueOfPixel:
Log, or "Fire" a Conversion Pixel. Conversion Pixels are used for Ads Conversion Tracking. See https://www.facebook.com/help/435189689870514 to learn more.
Parameter | Description |
---|---|
pixelID | Numeric ID for the conversion pixel to be logged. See https://www.facebook.com/help/435189689870514 to learn how to create a conversion pixel. |
value | Value of what the logging of this pixel is worth to you. The currency that this is expressed in doesn't matter, so long as it is consistent across all logging for this pixel. This value will be rounded to the thousandths place (e.g., 12.34567 becomes 12.346). |
+ (void)
logConversionPixel: | (NSString *)pixelID |
valueOfPixel: | (double)value; |
This event immediately triggers a flush of the FBInsights
event queue, unless the flushBehavior
is set
to FBInsightsFlushBehaviorExplicitOnly
. The "client token" must be set via [FBSettings setClientToken] prior to
calling this method. An exception is thrown if it's not.
FBInsights.h
logConversionPixel:valueOfPixel:session:
Log, or "Fire" a Conversion Pixel. Conversion Pixels are used for Ads Conversion Tracking. See https://www.facebook.com/help/435189689870514 to learn more.
Parameter | Description |
---|---|
pixelID | Numeric ID for the conversion pixel to be logged. See https://www.facebook.com/help/435189689870514 to learn how to create a conversion pixel. |
value | Value of what the logging of this pixel is worth to you. The currency that this is expressed in doesn't matter, so long as it is consistent across all logging for this pixel. This value will be rounded to the thousandths place (e.g., 12.34567 becomes 12.346). |
session | to direct the event logging to, and thus be logged with whatever user (if any)
is associated with that . A value of |
+ (void)
logConversionPixel: | (NSString *)pixelID |
valueOfPixel: | (double)value |
session: | (FBSession *)session; |
This event immediately triggers a flush of the FBInsights
event queue, unless the flushBehavior
is set
to FBInsightsFlushBehaviorExplicitOnly
. The "client token" must be set via [FBSettings setClientToken] prior to
calling this method. An exception is thrown if it's not.
FBInsights.h
logPurchase:currency:
Log a purchase of the specified amount, in the specified currency.
Parameter | Description |
---|---|
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 FBInsights
event queue, unless the flushBehavior
is set
to FBInsightsFlushBehaviorExplicitOnly
. The "client token" must be set via [FBSettings setClientToken] prior to
calling this method. An exception is thrown if it's not.
FBInsights.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.
Parameter | Description |
---|---|
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 FBInsights
event queue, unless the flushBehavior
is set
to FBInsightsFlushBehaviorExplicitOnly
. The "client token" must be set via [FBSettings setClientToken] prior to
calling this method. An exception is thrown if it's not.
FBInsights.h
logPurchase:currency:parameters:session:
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.
Parameter | Description |
---|---|
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 |
session | to direct the event logging to, and thus be logged with whatever user (if any)
is associated with that . A value of |
+ (void)
logPurchase: | (double)purchaseAmount |
currency: | (NSString *)currency |
parameters: | (NSDictionary *)parameters |
session: | (FBSession *)session; |
This event immediately triggers a flush of the FBInsights
event queue, unless the flushBehavior
is set
to FBInsightsFlushBehaviorExplicitOnly
. The "client token" must be set via [FBSettings setClientToken] prior to
calling this method. An exception is thrown if it's not.
FBInsights.h
setAppVersion:
Sets the application version to the provided string. Insights allows breakdown of events by app version.
Parameter | Description |
---|---|
appVersion | The version identifier of the iOS app that events are being logged through. Enables analysis and breakdown of logged events by app version. |
+ (void)
setAppVersion:(NSString *)appVersion;
FBInsights.h
setFlushBehavior:
Set the current event flushing behavior specifying when events are sent back to Facebook servers.
Parameter | Description |
---|---|
flushBehavior | The desired |
+ (void)
setFlushBehavior:(FBInsightsFlushBehavior)flushBehavior;
FBInsights.h
FBInsightsLoggingResultNotification
extern NSString *const FBInsightsLoggingResultNotification;
NSNotificationCenter name indicating a result of a log flush attempt
FBInsights.h
FBInsightsFlushBehavior enum
Control when FBInsights sends log events to the server
typedef enum { FBInsightsFlushBehaviorAuto, FBInsightsFlushBehaviorExplicitOnly, } FBInsightsFlushBehavior;
If an instance of an app doesn't send during its lifetime, or can't establish connectivity, the events will be stashed for the next run and sent then.
FBInsights.h