Skip to content

Instantly share code, notes, and snippets.

@yashnagda04
Created May 23, 2020
Embed
What would you like to do?

Ultimate Guide to Facebook Analytics

Created By: Yash Nagda Last Edited: Mar 05, 2020 4:00 PM

Today marketing is essential part of the app success. Usually businesses use google or facebook ads for the marketing campaigns. But marketing alone is not enough we need a 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 number of installs. We must know how many users singed up, made purchases etc. So we can fix the bottlenecks and optimise every penny that we are spending on marketing.

What is facebook analytics and app events ?

Facebook provide 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 feature like funnels, target audience to track and optimise our users experience of the app. It is totally free for developer 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 you facebook account.
  2. 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.
  2. 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 in 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.

https://gist.github.com/d798a5eeaa60f984155f041da1aa89c3

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

https://gist.github.com/a2b2bd1584955d84f27855ed0574c5c8

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

https://gist.github.com/c0f9eecc4ad86a0786555940e6fcb081

  1. In your AndroidManifest.xml file add a meta-data element to the application element.

https://gist.github.com/a4cebb390dd679a8cbdc4f718eff749f

  1. Also provide internet permission in AndroidManifest.xml file.

https://gist.github.com/bbf060f1df9051f7e45581e0272dbf1d

  1. 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 following events.

  1. App Installs
  2. App Launch
  3. In-App Purchases

Manually Logged Events

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

  1. Create object of the AppEventsLogger class.

https://gist.github.com/d81e35c74070215e5889ce3e9702738a

  1. Now log the event.

https://gist.github.com/f93e9c5243de0acfd2567217f547e3d2

  1. You can also use two optional parameter in the log event method.
  • Bundle - You can add a bundle and add key and value pair in it.
  • valueToSum - It is a value which is summed for all the events posted by same user or different user. For example if 10 user by ₹ 10 worth items. Then this value will get summed up to ₹ 100.

https://gist.github.com/62f3f194baaa69e9d674d5dd6b4b9602

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

https://gist.github.com/5cb02dfc00597f968083fff53a6b43a5

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 facebook analytics console. I hope you have found this article helpful. If you have any query or suggestions you can post it in the comments below or contact me at yash@gkmit.co, I will be really glad to assist you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment