In Firebase Analytics, What are Events?

It’s not concerning the marriage event of your crush wherever you’ll get depressed when viewing your attractive woman.

Firebase Analytics

But it’s an event of firebase Analytics that collects information concerning any interactions together with your app that you simply will live.

3 Types of Firebase Analytics Events

Firebase Analytics will capture plenty of events mechanically for you, however the bulk of the events belong to a few styles of events:

1. Automatic Events

As the name suggests, these area unit the events that area unit measured mechanically for you notwithstanding you don’t do something at decision.

2. Suggested Events

Automatic events, as good developers know, aren't enough to get the most out of an app.

You may use the following events in the suggested events:
  • Games
  • Retail/eCommerce
  • Jobs
  • Education
  • Travel
  • Local Deals
  • Real Estate
For example, you wish to check once a user submits their payment information; you'll be able to use add_payment_info event that falls within the property event class.

I recommend you to use one in every of these predefined events rather than making a replacement (custom) one as a result of base of operations understands the context around these predefined events far better.

3. Custom Events

Experienced developers normally use custom events since the last word freedom is provided.

You can collect info concerning any events you want you may have tracked .

When does one would like custom events?

When the events don't seem to be mentioned within the automatic and advised events.

You are perpetually welcome to use base API with the custom name.

Firebase makes it terribly straightforward for you. It’s one line of code that you just have to be compelled to write.

logEvent ("my_event", {...} );

Simply provide the name and, if desired, any of the parameters that can contextualise that event and provide you with more information about what's going on in your app.

How Can You Integrate Events into Your App?

There square measure some ways to implements events and parameters in firebase analytics, however I even have some best practices that i like to recommend you.

You’re progressing to implement a custom event, however by finishing this tutorial, you'll simply handle steered events similarly.

1. Make a New Android Studio Project

To begin, open Android Studio and build a new project or open an existing project.

2. Incorporate Firebase into Your Project

Then, if you haven't already, add Firebase to your project.

3. Incorporate the Analytics SDK into your project

3.1 Include the dependencies mentioned below in your construct. File for Gradle (app)

implementation 'com.google.firebase:firebase-analytics:17.3.0'

3.2 At the start of MainActivity.java, declare the FirebaseAnalytics object

private FirebaseAnalytics mFirebaseAnalytics;

3.3 In the onCreate() method of MainAvtivity.java, create this object

//Get the FirebaseAnalytics item
mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);

You now have analytics integrated into your app.

In reality, if you don't do anything at this stage, you're doomed.

You're about to begin collecting data in the Firebase Console, such as total use, user interaction, income, and attention.

3.4 Begin logging events

You've successfully created a FirebaseAnalytics case.

With the logEvents() process, you can now start the case.

Other activities are directly relevant to companies and are recommended for all forms of apps.

To get the most information in the reports, you must submit suggested events along with their parameters. Who knows, it could come in handy in the near future.

When a user clicks on a specific item in your app, the code below fires the SELECT CONTENT case.

//Add a suggested Event to your calendar.
Bundle bundle = new Bundle();
bundle.putString(FirebaseAnalytics.Param.ITEM_ID, id);  
// The constant's parameter value is "FirebaseAnalytics.Param.ITEM ID."
bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, name);
bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, "image");
//"FirebaseAnalytics.Event.SELECT CONTENT" is the predefined condition in this case.
mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.SELECT_CONTENT, bundle); 

FirebaseAnalytics.Event (recommended Events Reference) is that the predefined constant that's on the market in our SDK and this documentation (Prescribed parameters of Events Reference) helps you to grasp that parameter goes with that events.

And if your application wants don't fulfill with the recommended event then you'll be able to use custom events with the assistance of the below code.

//log a custom event
Bundle params = new Bundle();
params.putString("image_name", name);
params.putString("full_text", text);
mFirebaseAnalytics.logEvent("share_image", params);


3.5 Do Some Code

To make the tutorial easier to follow, I've included a button in the activity main.xml file.

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/viewPager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <Button
        android:id="@+id/btn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="click me"
        android:textSize="25dp"/>

</RelativeLayout>

Here's where I logged a custom event in MainActivity.java.

package com.example.demodemo;

import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import com.google.firebase.analytics.FirebaseAnalytics;


public class MainActivity extends AppCompatActivity {
    private FirebaseAnalytics mFirebaseAnalytics;
    private Button button;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //Get the instance of FirebaseAnalytics.
        mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
        button = findViewById(R.id.btn);

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                String name = "click me";
                // [START custom_event]
                Bundle params = new Bundle();
                params.putString("btn_name", name);
                mFirebaseAnalytics.logEvent("share_btn", params);
                // [END custom_event]

            }
        });

    }
}

3.6 Run the App

Now just run the app.

Now once you click on the button base Analytics shows you that your event is scheduled for roughly quarter-hour.

In your case, perhaps it’s time is low or even high.

It depends on the android OS workload.

I’m victimization the emulator that’s why time is just too a lot of.

After 15-minute event is uploaded.

3.7 View Events in Firebase Dashboard

Now comes the fun thing.

The data is available in the event console.

This is where you can see the event report that is generated automatically for each action that occurs in your app.

Since the Dashboard updates on a regular basis, you won't be able to see the changes until later (every 24 hours).

After 24 hours, you can access specific events by clicking on them. You can see all of the information regarding that particular case.

3.8 View Events in Debug View

So you don’t need to wait twenty four hours?

Don’t worry you'll check your event report within the correct read window yet.

In order to observe events within the correct read window, you have got to implement one or two of things.

As represented in support.google.com add below code within the terminal window of the automaton studio.

//This is syntx
adb shell setprop debug.firebase.analytics.app <package_name>

//This is example
adb shell setprop debug.firebase.analytics.app "com.example.demodemo"

Reason You get the Error?

“%USERPROFILE%\AppData\Local\Android\sdk\platform-tools” is no longer accessible in newer versions of Android Studio. Yes, I realize it's a flaw. You can manually add this path to the environment variable depending on your Windows version (see How to add the path to the environment variable).

When a route has been successfully inserted, run the cmd below once more.

Post a Comment

Previous Post Next Post