Skip to content

Analytics

YYBartT edited this page Aug 29, 2024 · 7 revisions

Analytics

Analytics Overview

Google Analytics for Firebase provides free, unlimited reporting on up to 500 distinct events. The SDK automatically captures certain key events and user properties, and you can define your own custom events to measure the things that uniquely matter to your business. Analytics surfaces data about user behavior in your iOS and Android and Web apps, enabling you to make better decisions about your app or game and marketing optimization. View crash data, notification effectiveness, deep-link performance, in-app purchase data, and more. Check the official page for more information.

Setup

Before starting to use any Firebase extensions, you are required to follow some initial configuration steps. However if you've already done these for any of the other modules you can skip this configuration section and go straight to using the API functions.

Functions

The following functions are given for working with Analytics extension:



Back To Top

FirebaseAnalytics_LogEvent

This function logs an app event. The event can have up to 25 parameters. Note that events with the same name must have the same parameters. Up to 500 event names are supported. Using predefined FirebaseAnalytics.Event and/or FirebaseAnalytics.Param is recommended for optimal reporting.


Syntax:

FirebaseAnalytics_LogEvent(event, params)
Argument Type Description
event String The event data (available events reference)
params String The data as a JSON formatted string (available params reference)



Returns:

N/A


Example:

var _data = { screen_name : room_get_name(room) };

FirebaseAnalytics_LogEvent("screen_view", json_stringify(_data));

In the code sample above we will submit a log to the event "screen_view" (see event details), so first create a data struct with a parameter named "screen_name" (this is one of the allowed parameters) and convert it to a string using the json_stringify function.




Back To Top

FirebaseAnalytics_ResetAnalyticsData

This function clears all analytics data for the app from the current device and resets the app instance ID.

Note

This will not clear analytics previously collected by the app that have already been pushed to the server.


Syntax:

FirebaseAnalytics_ResetAnalyticsData()



Returns:

N/A


Example:

if (global.stopDataCollection)
{
    FirebaseAnalytics_ResetAnalyticsData();
    FirebaseAnalytics_SetAnalyticsCollectionEnabled(false);
}

The code above will check if a global variable is set to true (global.stopDataCollection) and if so we will clear the local collected data for this extension and disable the analytics data collection (using the function FirebaseAnalytics_SetAnalyticsCollectionEnabled).




Back To Top

FirebaseAnalytics_SetAnalyticsCollectionEnabled

This function is used to enable or disable analytics collection for the app on the current device. This setting is persisted across app sessions. By default it is enabled.


Syntax:

FirebaseAnalytics_SetAnalyticsCollectionEnabled(enable)
Argument Type Description
enable Boolean Whether or not analytics collection should be enabled.



Returns:

N/A


Example:

if (global.stopDataCollection)
{
    FirebaseAnalytics_ResetAnalyticsData();
    FirebaseAnalytics_SetAnalyticsCollectionEnabled(false);
}

The code above will check if a global variable is set to true and if so we will clear the local collected data (using the function FirebaseAnalytics_ResetAnalyticsData) for this extension and disable the analytics data collection.




Back To Top

FirebaseAnalytics_SetDefaultEventParameters

This function sets "default" parameters that will be provided with every event logged from the SDK, including automatic ones. The values passed in the parameters bundle will be added to the map of default event parameters. These parameters persist across app runs. They are of lower precedence than event parameters, so if an event parameter and a parameter set using this function have the same name, the value of the event parameter will be used. The same limitations on event parameters apply to default event parameters.


Syntax:

FirebaseAnalytics_SetDefaultEventParameters(parameters)
Argument Type Description
parameters String A JSON formatted string of a struct to be added to every event. These parameters will be added to the default event parameters, replacing any existing parameter with the same name. Valid parameter values are string and double . Setting a key's value to pointer_null will clear that parameter.



Returns:

N/A


Example:

var _parameters = {
    playerName: "Hero",
    bossName: pointer_null,
};

FirebaseAnalytics_SetDefaultEventParameters(json_stringify(_parameters));

With the code above we are setting the default parameters to be used on all further calls to FirebaseAnalytics_LogEvent. First we create a struct (_parameters) with a "playerName" and "bossName" keys, the boss name is set to pointer_null meaning it will be removed from the set of default event parameters.




Back To Top

FirebaseAnalytics_SetSessionTimeoutDuration

This function sets the duration of inactivity (in milliseconds) that terminates the current session. The default value is 1800000 (30 minutes).


Syntax:

FirebaseAnalytics_SetSessionTimeoutDuration(milliseconds)
Argument Type Description
milliseconds Real Session timeout duration in milliseconds.



Returns:

N/A


Example:

FirebaseAnalytics_SetSessionTimeoutDuration(3600000); //1 hour

The code above sets the timeout duration to 1 hour, meaning that if no events are logged within this timeout the session will be terminated.




Back To Top

FirebaseAnalytics_SetUserId

This function sets the user ID property. This feature must be used in accordance with Google's Privacy Policy.


Syntax:

FirebaseAnalytics_SetUserId(userID)
Argument Type Description
userID String The user ID string to assign to the user of this app on this device, which must be non-empty and no more than 256 characters long. Setting the ID to pointer_null removes the user ID.



Returns:

N/A


Example:

FirebaseAnalytics_SetUserId("myUser123");

The above code will set the user ID to the string "myUser123".




Back To Top

FirebaseAnalytics_SetUserProperty

This function sets a user property to the given value. Up to 25 user property names are supported. Once set, user property values persist throughout the app life cycle and across sessions.


Syntax:

FirebaseAnalytics_SetUserProperty(key, value)
Argument Type Description
key String The name of the user property to set. Should contain 1 to 24 alphanumeric characters or underscores and must start with an alphabetic character.

> [!WARNING]
>
> The "firebase_", "google_" and "ga_" prefixes are reserved and should not be used for user property names.
value String The value of the user property. Values can be up to 36 characters long. Setting the value to pointer_null removes the user property.



Returns:

N/A


Example:

FirebaseAnalytics_SetUserProperty("location", "UK");

The code above will set a user property "location" to the value "UK".