Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • How to Enable Facebook Analytic in Android Application?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1
    • 0
    • 1.81k
    Comment on it

    With around 1.7 billion users and which are growing day by day, Facebook has now come a very important medium to promote your app and website world wide.



    Facebook along with social sharing provides many other tools and options to track the reports of your business/product page engagement and the tool is Facebook Analytics. It helps the page owner to understand and analyse, how users are using your app or website. So, in this tutorial Enable Facebook Analytic in Android Application.

    "For more on FB analytics you can visit the Facebook official page:


    To use this feature you have to make your app enabled with Facebook analytics, for that you need to go through following steps:


    1. Create a new app on facebook portal making use of “” link.


    2. Now you need to import facebook sdk to your project


    • Create a new app on your android Studio with minimum API level 15:Android 4.0.3 that is IcreamSandwich or else you can choose greater version than the mentioned one.


    • Now in your project open Gradel Script then select the build.gradle(project) level and add the mavenCentral() in buildscript { repositories {}} section as shown below.

    buildscript {
        repositories {
        dependencies {
            classpath ''
            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
    allprojects {
        repositories {
    task clean(type: Delete) {
        delete rootProject.buildDir


    • After adding this click on the build.gradle file and add the line compile'[4,5)' in yor dependencies{} section as shown below.

    dependencies {
        compile fileTree(include: ['*.jar'], dir: 'libs')
        androidTestCompile('', {
            exclude group: '', module: 'support-annotations'
        compile ''
        compile ''
        compile '[4,5)'
        testCompile 'junit:junit:4.12'


    3. Now you need to add facebook app id

    open your string file in your project copy your app id from facebook portal and paste it in string file as shown below

    4.Now use Internet permission by adding <uses-permission android:name="android.permission.INTERNET"/> in your manifest file

    and do add the below given code to your manifest file

    <meta-data android:name="com.facebook.sdk.ApplicationId" 
        <activity android:name="com.facebook.FacebookActivity"
            android:label="@string/app_name" />
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="@string/fb_login_protocol_scheme" />

    5. Now add your app package name to facebook portal @


    6. Now add devlopment or release key hash to facebook portal by running the following command in your terminal for linux

    keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64

    This will give you an output somthing like this ga0RGNYHvNM5d0SLGQfpQWAPGJ8= known as key hash add this to your app on facebook portal.

    Now make simple facebook login and see the login events on facebook analytics portal.

    Below I have shown the code for login event by making use of facebook login button .

    public class LandingScreen extends AppCompatActivity {
        private LoginButton loginButton;
        private CallbackManager callbackManager;
        private LayoutInflater inflater;
        protected void onCreate(Bundle savedInstanceState) {
            callbackManager = CallbackManager.Factory.create();
            loginButton = (LoginButton)findViewById(;
            // If using in a fragment
            // Other app specific specialization
            // Callback registration
            loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
                public void onSuccess(LoginResult loginResult) {
                    // App code
                public void onCancel() {
                    // App code
                public void onError(FacebookException exception) {
                    // App code
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
            callbackManager.onActivityResult(requestCode, resultCode, data);


    Below is the XML for the above Activity

    <?xml version="1.0" encoding="utf-8"?>
            android:layout_marginBottom="30dp" />


    How to Enable Facebook Analytic in Android Application?

 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: