Google Firebase Analytics

Google Firebase Analytics

These integration steps will help you integrate Google Firebase Analytics into your app. Firebase Analytics is a powerful tool that provides unlimited analytics at no cost, helping you understand user behavior to make informed decisions about app marketing and performance optimizations.

Step-by-Step Integration of Google Firebase Analytics

1. Add Google Firebase Analytics

Click on "Add" button to add Google Firebase Analytics. Once you add, it will appear in Add-ons menu.

Screenshot 2025-05-12 122532.png


2. Configure Firebase Analytics

After adding the add-on, you will see the settings option in the section.

Screenshot 2025-05-12 120709.png


Upload your google-service.json file.

Screenshot 2025-05-12 124143.png


Firebase Analytics Functions

1. Enable/Disable Analytics Data Collection

Plain JavaScript:

const { Analytics: FirebaseAnalytics } = window.WTN.Firebase;
 
FirebaseAnalytics.setCollection({
   enabled: true // or false
});

ES6+:

import { setCollection } from "webtonative/Firebase/Analytics";
 
setCollection({
    enabled: true // or false
});

2. Identify User

Plain JavaScript:

const { Analytics: FirebaseAnalytics } = window.WTN.Firebase;
 
FirebaseAnalytics.setUserId({
   userId: "customuserId"
});

ES6+:

import { setUserId } from "webtonative/Firebase/Analytics";
 
setUserId({
    userId: "customuserId"
});

3. Set User Properties

Plain JavaScript:

const { Analytics: FirebaseAnalytics } = window.WTN.Firebase;
 
FirebaseAnalytics.setUserProperty({
   key: 'name',
   value: 'Webtonative'
});

ES6+:

import { setUserProperty } from "webtonative/Firebase/Analytics";
 
setUserProperty({
    key: 'name',
    value: 'Webtonative'
});

4. Set Default Event Parameters

Plain JavaScript:

const { Analytics: FirebaseAnalytics } = window.WTN.Firebase;
 
FirebaseAnalytics.setDefaultEventParameters({
   parameters: {
       "level_name": "Caverns01",
       "level_difficulty": 4
   }
});

ES6+:

import { setDefaultEventParameters } from "webtonative/Firebase/Analytics";
 
setDefaultEventParameters({
    parameters: {
        "level_name": "Caverns01",
        "level_difficulty": 4
    }
});

5. Log Events

Plain JavaScript:

const { Analytics: FirebaseAnalytics } = window.WTN.Firebase;
 
FirebaseAnalytics.logEvent({
   eventName: 'Your event name',
   parameters: {
       "level_name": "Caverns01",
       "level_difficulty": 4
   }
});

ES6+:

import { logEvent } from "webtonative/Firebase/Analytics";
 
logEvent({
    eventName: 'Your event name',
    parameters: {
        "level_name": "Caverns01",
        "level_difficulty": 4
    }
});

6. Track Screen View

Plain JavaScript:

const { Analytics: FirebaseAnalytics } = window.WTN.Firebase;
 
FirebaseAnalytics.logScreen({
   screenName: "Screen Name",
   screenClass: "Screen Class"
});

ES6+:

import { logScreen } from "webtonative/Firebase/Analytics";
 
logScreen({
    screenName: "Screen Name",
    screenClass: "Screen Class"
});

Click on the "Save" button. Rebuild your app to apply and view the changes. This ensures that all configurations are applied correctly and Firebase Analytics functions as expected.