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, some 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. Add a meta-data element to the application element:
    
    <application android:label="@string/app_name" ...>
        ...
        <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
        ...
    </application>
    
    
  7. 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

The Events Manager displays the events you send to Facebook Analytics. If this is the first time you launched your app with this code, you may have to wait at least 20 minutes before your events appear.
Note: Events may take up to 20 minutes to appear in the dashboard.

7. Add More Events

Use the App Event Builder to generate the code in your language to implement either a custom or pre-defined app event that you can then add to your app.

To Generate Code for a Standard Event

  1. Choose the Standard Event tab.
  2. In Event Name, choose a standard event.
  3. Choose Get Code.
  4. In the window, select a language to see the code to copy and paste into your app.

Automatically Logged Events

After you integrate the Facebook SDK into your app, the following events are automatically logged:

EventDetails

App Install

The first time a new user activates an app or the first time an app starts on a particular device.

App Launch

When the Facebook SDK is initialized in your app for each session.

In-App Purchase

When a purchase processed by the Apple App Store or Google Play has been completed. If you use other payments platforms, you will need to add purchase event code manually.

Facebook SDK Crash Report

(For Facebook Use Only.)

If your app crashed due to the Facebook SDK, a crash report is generated and sent to Facebook when your app is restarted. This report contains no user data and helps Facebook ensure the quality and stability of the SDK. To opt out of logging this event, disable automatically logged events.

Pre-defined Events

The following table contains the pre-defined events. Use the App Event Builder to get the code for these events.

Event NameDescription

Achieve Level

Log this event when a person achieves specific levels you define within your application, business, or organization.


Add Payment Info

Log this event during the addition of customer payment information during a checkout process.


Recommended Parameters

  • content_category
  • content_ids
  • contents
  • currency
  • value

Add to Cart

Log this event during the addition of an item to a shopping cart or basket (example: clicking an Add to Cart button on a website).


Recommended Parameters

  • content_ids*
  • content_name
  • content_type*
  • contents*
  • currency
  • value

*Required parameters for Dynamic Ads.

Add to Wishlist

Log this event during the addition of items to a wishlist (example: clicking an Add to Wishlist button on a website).


Recommended Parameters

  • contentData
  • contentId
  • contentType
  • currency

Complete Registration

Log this event during the submission of information in exchange for a service provided by your business (example: sign up for email subscription).


Recommended Parameters

  • content_name
  • currency
  • status
  • value

Complete Tutorial

Log this event during the completion of a tutorial on your app.


Contact

Log this event during a telephone/SMS, email, chat, or other type of contact between a customer and your business.

Customize Product

Log this event during the customization of products through a configuration tool or other application your business owns.

Donate

Log this event during the donation of funds to your organization.

Find Location

Log this event when a web or app search for one of your business locations suggest that someone might intend to visit (example: searching for a product and finding it at one of your local stores.

In-App Ad Click

Log this event when an ad from a third-party platform is clicked within your app.

In-App Ad Impression

Log this event when an ad from a third-party platform appears on-screen within your app.

Initiate Checkout

Log this event at the start of a checkout process.


Recommended Parameters

  • content_category
  • content_ids
  • contents
  • currency
  • num_items
  • value

Purchase

Log this event during the completion of a purchase, usually signified by receiving order/purchase confirmation or a transaction receipt

If you use Facebook to manage your in-app purchases, the purchase events are automatically logged.


Required Parameters

  • currency
  • value

Recommended Parameters

  • content_ids*
  • content_name
  • content_type*
  • contents*
  • num_items

*Required for Dynamic Ads

Rate

Log this event during a rating of something within your app, business, or organization (example: rates a restaurant within a restaurant review app).

Schedule

Log this event during the booking of an appointment to visit one of your locations.

Search

Log this event during a search performed on your website, app or other property (example: product searches, travel searches).


Recommended Parameters

  • content_category
  • content_ids
  • contents
  • currency
  • search_string
  • value

Spend Credits

Log this event during the completion of a transaction where people spend credits (example: in-app currency) specific to your business or application.


Start Trial

Log this event at the start of a free trial of a product or service you offer (example: trial subscription).


Recommended Parameters

  • currency
  • predicted_ltv
  • value

Submit Application

Log this event during the submission of an application for a product, service, program you offer example: credit card, educational program, or job).

Subscribe

Log this event at the start of a paid subscription for a product or service you offer.


Recommended Parameters

  • currency
  • predicted_ltv
  • value

Unlocked Achievement

Log this event during the completion of specific activities or actions you want to reward within your application, business or organization (refer a friend, complete your profile, etc.).

View Content

Log this event during a visit to a content page you care about, such as a product page, landing page or article.


Recommended Parameters

  • content_ids*
  • content_name
  • content_type*
  • contents*
  • currency
  • value

*Required for Dynamic Ads

Test your events with the App Ads Helper

The App Ads Helper allows you to test your app events to ensure that your app is sending events to Facebook.

a. Open the App Ads Helper.

b. In Select an App, choose your app and choose Submit.

c. Go to the bottom and choose Test App Events.

d. Start your app and send an event. The event appears on the web page.

8. 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.