Facebook Analytics for Apps quickstart guide

This guide helps you set up Facebook Analytics for Apps quickly so you can see data, analyze trends and better understand the behavior of people who use your app.

Before you start

Make sure you have a Facebook Developer account—if you don't have one already,

create one

.



You'll also need to add the Facebook SDK to your app. The following guides take you through all of the necessary steps. When you're done, return here to finish setting up Analytics for Apps.

iOS SDK SetupAndroid SDK SetupJavaScript SDK Setup

1. Log app events

App events are the key actions that people take, such as launching your app, viewing content or making a purchase.

When you integrated the Facebook SDK with your native mobile app, you probably added the code to log your first event: activateApp.

If not, you can use the code shown below.

The examples in this document are written in Objective-C. If you're using Swift, refer to App Events with the Facebook SDK for Swift.

// Add to your AppDelegate.m file
- (void)applicationDidBecomeActive:(UIApplication *)application {    
    // Call the 'activateApp' method to log an app event for use
    // in analytics and advertising reporting.
    [FBSDKAppEvents activateApp];
}
// Add to each long-lived activity
@Override
protected void onResume() { 
  super.onResume(); 
  AppEventsLogger.activateApp(this); 
}
  
// for Android, you should also log app deactivation
@Override
protected void onPause() { 
  super.onPause(); 
  AppEventsLogger.deactivateApp(this);
}
<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId      : 'your-app-id',
      xfbml      : true,
      version    : 'v2.7'
    });
    FB.AppEvents.logPageView();
  };

  (function(d, s, id){
     var js, fjs = d.getElementsByTagName(s)[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement(s); js.id = id;
     js.src = "//connect.facebook.net/en_US/sdk.js";
     fjs.parentNode.insertBefore(js, fjs);
   }(document, 'script', 'facebook-jssdk'));
</script>

Logging web activity

You can log app events for any meaningful actions people take on your website. There are many pre-defined events such as completed registration, viewed content, searched, added to cart, spent credits and more.

For websites, we recommend triggering the page view event on all pages to ensure accurate user accounts and session durations.

Analytics for Apps supports up to 1,000 unique events for your app or website, so you can also define your own custom events. Try this now by adding the following code to a button click handler in your app:

// Add to a button click handler
- (void)buttonClick:(id)sender {    
    // logs your custom event, feel free to use 
    // a string of your choosing here
    [FBSDKAppEvents logEvent:@"sentFriendRequest"];
}
AppEventsLogger logger = AppEventsLogger.newLogger(this);
  
// Add to a button click handler  
logger.logEvent("sentFriendRequest");
function onButtonClick() {
  // Add this to a button's onclick handler
  FB.AppEvents.logEvent("sentFriendRequest");
}

Now launch your app and click the button where you added the above code to. Taking that action will log your first custom event.


2. Verify Your app events

You can review the most recent events logged by your app or website. To verify these events, visit Analytics for Apps. Then choose your app and go to Activity > Event Debugging.

You should see your app launch (if you're setting up an app) or the page view event (if you're setting up a website) as well as the custom event for the button click. If not, click the refresh button to load the latest events.

Once you've verified that your events are being logged correctly, then you can create your first funnel to help you measure conversion for any sequence of events you choose.


3. Take a guided tour of Facebook Analytics for Apps

Now that you're logging events, visit our guided demo app to take a tour of all of the key features that Facebook Analytics for Apps offers you and your business.


Learn More