0% found this document useful (0 votes)
75 views2 pages

Get Started With Analytics For Android - Firebase

This document provides instructions for getting started with Analytics for Android using Firebase. It explains that Analytics automatically logs some events and user properties. To set it up, add the SDK dependency and declare a FirebaseAnalytics object. Events can then be logged using the logEvent method by passing an event name and optional parameters bundle. Verbose logging can confirm events are being sent.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views2 pages

Get Started With Analytics For Android - Firebase

This document provides instructions for getting started with Analytics for Android using Firebase. It explains that Analytics automatically logs some events and user properties. To set it up, add the SDK dependency and declare a FirebaseAnalytics object. Events can then be logged using the logEvent method by passing an event name and optional parameters bundle. Verbose logging can confirm events are being sent.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

25/12/2017 Get Started with Analytics for Android  |  Firebase

Get Started with Analytics for Android


Google Analytics for Firebase collects usage and behavior data for your app. The SDK logs two primary types of information:

Events: What is happening in your app, such as user actions, system events, or errors.
User properties: Attributes you de ne to describe segments of your user base, such as language preference or geographic
location.

Analytics automatically logs some events (https://support.google.com/ rebase/answer/6317485) and user properties


 (https://support.google.com/ rebase/answer/6317486); you don't need to add any code to enable them.

Prerequisites

1. Install the Firebase SDK (https:// rebase.google.com/docs/android/setup).


2. Add your app to your Firebase project in the Firebase console  (//console. rebase.google.com/).

3. Android Studio 1.5 or later.

Add Analytics to your app

Add the dependency for Google Analytics for Firebase to your app-level build.gradle le:

compile 'com.google.firebase:firebase-core:11.8.0'

Declare the com.google.firebase.analytics.FirebaseAnalytics object at the top of your activity

private FirebaseAnalytics mFirebaseAnalytics;


MainActivity.java (https://github.com/ rebase/quickstart-android/blob/master/analytics/app/src/main/java/com/google/ rebase/quickstart/analyti

Then initialize it in the onCreate() method

// Obtain the FirebaseAnalytics instance.


mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
MainActivity.java (https://github.com/ rebase/quickstart-android/blob/master/analytics/app/src/main/java/com/google/ rebase/quickstart/analyti

Log events

Once you have created a FirebaseAnalytics instance, you can use it to log either prede ned or custom events with the logEvent()
 (https:// rebase.google.com/docs/reference/android/com/google/ rebase/analytics/FirebaseAnalytics.html#logEvent(java.lang.String,%20android.os.Bu
ndle))
method. You can explore the prede ned events and parameters in the FirebaseAnalytics.Event
 (https:// rebase.google.com/docs/reference/android/com/google/ rebase/analytics/FirebaseAnalytics.Event) and FirebaseAnalytics.Param
 (https:// rebase.google.com/docs/reference/android/com/google/ rebase/analytics/FirebaseAnalytics.Param) reference documentation.

The following code logs a SELECT_CONTENT


 (https:// rebase.google.com/docs/reference/android/com/google/ rebase/analytics/FirebaseAnalytics.Event.html#SELECT_CONTENT) Event when a
user clicks on a speci c element in your app.

Bundle bundle = new Bundle(); 


bundle.putString(FirebaseAnalytics.Param.ITEM_ID, id);
bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, name);

https://firebase.google.com/docs/analytics/android/start/ 1/2
25/12/2017 Get Started with Analytics for Android  |  Firebase

bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, "image");
mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.SELECT_CONTENT, bundle);
MainActivity.java (https://github.com/ rebase/quickstart-android/blob/master/analytics/app/src/main/java/com/google/ rebase/quickstart/analyti

Con rm Events

You can enable verbose logging to monitor logging of events by the SDK to help verify that events are being logged properly. This
includes both automatically and manually logged events.

You can enable verbose logging with a series of adb commands:

adb shell setprop log.tag.FA VERBOSE


adb shell setprop log.tag.FA-SVC VERBOSE
adb logcat -v time -s FA FA-SVC

This command displays your events in the Android Studio logcat, helping you immediately verify that events are being sent.

Next Steps

See your data refresh periodically in the Firebase console  (//console. rebase.google.com/).

Explore the guides on logging events (https:// rebase.google.com/docs/analytics/android/events) and setting user properties
 (https:// rebase.google.com/docs/analytics/android/properties).

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 3.0 License (http://creativecommons.org/licenses/by/3.0/),
and code samples are licensed under the Apache 2.0 License (http://www.apache.org/licenses/LICENSE-2.0). For details, see our Site Policies
 (https://developers.google.com/terms/site-policies). Java is a registered trademark of Oracle and/or its a liates.

Última actualización: Diciembre 19, 2017

https://firebase.google.com/docs/analytics/android/start/ 2/2

You might also like