Facebook Install Ad Tracking on iOS

If you do not already have the Facebook SDK for iOS you will need to download and install it from here.

You must then follow the clear instructions on

It is highly recommended that you define macros for the various keys and identifiers needed. A good place to place them is the config.h file of your project.

Please not that there is some unavoidable information scatter as the URL scheme—used for deep interaction and/or to prevent the ad from showing to users who alady have the app installed—must be defined in the application's Info.plist (which you will find by selecting the info tab of the product settings in Xcode).

Tracking purchases

Tracking purchases can be done by adding a SKPaymentTransactionObserver to the project and setting it as an observer of the payment queue using:

      [[SKPaymentQueue defaultQueue] addTransactionObserver:**myObs**];

A good place to set it as a delegate it immediately after the calls to [FBAppEvents activateApp] as this guarantee that the everything is properly initialised before your custom delegate makes any call to the tracking code.

The implementation of your SKPaymentTransactionObserver should look something like this:

	- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
	 NSMutableSet *productIds = [NSMutableSet set];
	  for (SKPaymentTransaction *t in transactions) {
	    if (t.transactionState == SKPaymentTransactionStatePurchased) {
	      [productIds addObject:t.payment.productIdentifier];
	  if ([productIds count] > 0) {
	    SKProductsRequest *req = [[SKProductsRequest alloc] initWithProductIdentifiers:productIds];
	    req.delegate = (id<SKProductsRequestDelegate>)self;
	    [req start];

	- (void)paymentQueue:(SKPaymentQueue *)queue updatedDownloads:(NSArray *)downloads {
	  // NOOP

	- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
	  for (SKProduct *product in response.products) {
	    double price = [product.price doubleValue];
	    NSString *currency = [product.priceLocale objectForKey:NSLocaleCurrencyCode];
	    NSDictionary *params = @{FBAppEventParameterNameContentID: product.productIdentifier};
	    [FBAppEvents logPurchase:price currency:currency parameters:params];
Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request


Powered by Zendesk