Today marketing is an essential part of the app success. Usually, businesses use google or Facebook ads for marketing campaigns. But marketing alone is not enough we need good analytics so we can understand what is working and what is not?

“Success doesn't end with an install”

as this quote says we can't measure success by just looking at a number of installs. We must know how many users signed up, made purchases etc. So we can fix the bottlenecks and optimize every penny that we are spending on marketing.

What is Facebook analytics and app events?

Facebook provides some very good set of tools for analytics. We can track our app install, sign up and purchase, etc. We can also use some specific features like funnels, target audience to track and optimize our user's experience of the app. It is totally free for developers to use and Facebook login is not required to use analytics.

How to integrate Facebook analytics in android?

Configure Your Facebook App

  1. First, visit this link and login with your Facebook account.

  1. Now give detail of your app and upload key hashes. and follow the process.

Link Your Facebook Ad Account with Your App

To run ads and measure installs in the Ads Manager, you are required to associate at least one Ad Account with your app.

  1. In the app dashboard click Settings > Advanced.

  1. In Authorized Ad Account IDs, add your Ad Account IDs. You can get your ad account IDs from your Ads Manager.

 

Integrate the Facebook SDK in Your Android App

We can integrate Facebook analytics in our app through the following steps.

1. Firstly, log in to Facebook to create apps or register as a developer.

2. Now create a new android project in android studio with API 15 or higher.

3. In your build.gradle (Project) file add this.

mavenCentral()

4. Open build.gradle (Module: app) and add the following dependency.

implementation 'com.facebook.android:facebook-android-sdk:[5,6)'

5. Now open your string.xml file and add following lines.(get the app id from facebook dashboard)

<string name="facebook_app_id">[APP_ID]</string>
<string name="fb_login_protocol_scheme">fb[APP_ID]</string>

6. In your AndroidManifest.xml file 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. Also, provide internet permission in AndroidManifest.xml file.

<uses-permission android:name="android.permission.INTERNET"/>

6. Build your project.

Yay !! You have successfully integrated the Facebook analytics SDK. Now you can verify this by opening the app and you will see the event on the console.

 

Automatic Logged Events

SDK will automatically record the following events.

  1. App Installs

  1. App Launch

  1. In-App Purchases

 

Manually Logged Events

Apart from automatic logged events, we can also manually log our custom events in the following steps.

1. Create an object of the AppEventsLogger class.

AppEventsLogger logger = AppEventsLogger.newLogger(this);

2. Now log the event.

logger.logEvent(AppEventsConstants.EVENT_NAME_X);

3. You can also use two optional parameters in the log event method.

  • Bundle - You can add a bundle and add key and value pairs in it.

  • valueToSum - It is a value that is summed for all the events posted by the same user or different user. For example, if 10 users by ₹ 10 worth items. Then this value will get summed up to ₹ 100.

logger.logEvent(AppEventsConstants.EVENT_NAME_X,valueToSum,Bundle);

4. For example we can log an event of e-commerce app in the following way.

Bundle params = new Bundle();
    params.putInt(AppEventsConstants.EVENT_PARAM_CART_QUANTITY, "5 items");
    params.putString(AppEventsConstants.EVENT_PARAM_CART_TOTAL_AMOUNT, "₹ 400.00");
    
    logger.logEvent(AppEventsConstants.EVENT_NAME_CART,
                    ,400 //this valueToSum will be added for all the users
                    params);

 

Conclusion

In this article, we have learned how we can integrate Facebook Analytics in our android app. We have also learned how we can manually log our custom event to the Facebook analytics console. I hope you have found this article helpful. If you have any queries or suggestions feel free to post it in the comment section below or contact me at yash@gkmit.co, I will be really glad to assist you.