Facebook Analytics Quickstart Guide for Android

1. Login

Please log in to Facebook to create apps or register as a developer.

2. Add the Facebook SDK

When you use the Facebook SDK, events in your app are automatically logged and collected for Facebook Analytics unless you disable automatic event logging. For details about what information is collected and how to disable automatic event logging, see Automatic App Event Logging.

To add the Facebook SDK to a project, add the SDK as a build dependency.

If you're adding the SDK to an existing project, start at step 3.

  1. Go to Android Studio | Start a new Android Studio project | Application name | Minimum SDK.
  2. Select API 15: Android 4.0.3 9 (IceCreamSandwich) or higher and click Next.
  3. Click Basic Activity and then click Next, and then Finish.
  4. In your project, open <your_app> | Gradle Scripts | build.gradle (Project) and add the following to the buildscript { repositories {}} section to download the SDK from the Maven Central Repository:
    mavenCentral()
  5. In your project, open <your_app> | Gradle Scripts | build.gradle (Module: app) and add the following to the dependencies{} section to compile the latest version of the SDK:
    implementation 'com.facebook.android:facebook-android-sdk:[4,5)'
    
  6. Build your project.

3. Add Facebook App ID

You need to login to complete this step.

4. Tell Us about Your Android Project

You need to login to complete this step.

5. Add Your Development and Release Key Hashes

You need to login to complete this step.

6. Verify Your App Event

To see events, open Facebook Analytics. Choose your app and navigate to Activity > Event Debugging.
You should see your app launch event. If not, click the refresh button to load the latest events for your app.
Note: Events may take up to 20 minutes to appear in the dashboard.
Once you've verified that your events are being delivered, you're ready to create your first funnel to help you measure conversion for a sequence of events in your app.

7. Log App Events

App events are the key actions that people take as they use your app, such as launching your app, viewing content, or making a purchase You can log app events for any meaningful actions people take in your app. There are many pre-defined events such as completed registration, viewed content, searched, added to cart, spent credits, and more.
In this step, you add code to your project that shows a custom event in the dashboard.
  1. Shut down the simulator.
  2. In MainActivity.java, add the following import statements:
    import com.facebook.FacebookSdk;
    import com.facebook.appevents.AppEventsLogger;
  3. Add the following function to the MainActivity class:
    /**
     * This function assumes logger is an instance of AppEventsLogger and has been
     * created using AppEventsLogger.newLogger() call.
     */
    public void logSentFriendRequestEvent () {
        logger.logEvent("sentFriendRequest");
    }
  4. Build the project and then run the project in the simulator.
  5. See the results in the Dashboard.
For more information on logging app events, see App Events for Android.

Take a guided tour of Facebook Analytics

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

The demo app does not have an Event Debugging link. This link is only available in apps that you create.

Next Steps

Be sure to check out our other documentation pages for more advanced guides.