Skip to content

How to create custom events on Firebase for Android and iOS

How to create custom events on Firebase for Android and iOS

At Kurve, we believe that advertising technology is as important as creative quality. By combining these complementary strategies we are able to achieve great results for our clients, driving installations and improving long-term retention. A key component in this tactic is the integration of custom events into our app campaigns.

In this article, we are going to share our step-by-step guide on how to create the custom events that we identified as the most effective.

Tracking unique interactions to optimise app performance

Firebase Analytics allows you to track predefined events such as app installations, updates or in-app purchases. These are automatically collected and are essential to provide basic user data.

With Firebase, it’s also possible to create custom events, which can help map out the actions that are unique to an app’s user interactions and respond to the optimisation needs of specific campaigns.

Tracking unique interactions to optimise app performance with Firebase Analytics

In the following sections, you will find out how to monitor user quality, engagement and retention by creating two key custom events:

For each event, we are going to provide the code that needs to be executed for Android and iOS and tailor it to different programming languages.

Both App opened X times in X days and Reached X Level have the goal of encouraging the algorithm to find active users rather than installers. In fact, on platforms like Google and TikTok, for example, setting the number of installations as the primary metric of success means targeting not only engaged users but also low-quality customers who might have downloaded the app but never 
opened it again.

Track unique interactions to optimise app performance

Reactions to advertisements can vary significantly: what catches one person’s attention might not resonate with another and quick installations following ad exposure don’t always translate into continued engagement. Often, the journey begins with users downloading an app out of curiosity, only to realise that it doesn't align with their interests.

For instance, Kurve ran successful campaigns for our clients Treecard and Sweatcoin, managing to drive growth at a very competitive cost per install. The next challenge was then to retain new users to ensure the effectiveness of these strategies over time.

By using Firebase custom events for Google Ads we were able to track engaged installations and improve retention.

Read on to find out how we achieved this. 

Firebase custom events

Firebase custom events step by step

App opened X times in X days

Tracking the frequency of app opens provides insights into engagement levels and can help determine user quality and increase retention. 

To promote our client Treecard’s Walk to Plant initiative, we tracked users who launched the app three times within a week and five times in fourteen days. This helped us direct the algorithm to people who were more likely to engage with the app, for example, dog walkers or fitness enthusiasts. Setting this metric as our benchmark for success in Google Ads enabled us to optimise our campaigns effectively.

Here are the three main steps to create an app_open custom event on Firebase:

  1. Set up Firebase tracking for all important events in the app
  2. Integrate Firebase with Bigquery
  3. Write and run SQL query in Bigquery

1. Set up Firebase tracking for app_open events in the app

This step involves modifying the app's code to ensure that an app_open event is captured and sent to Firebase Analytics every time a user opens the app.

Android tracking

On Java:

Use the instance mFirebaseAnalytics to log a predefined app_open event.

mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.app_open);

On Kotlin+KTX:

In Kotlin, the code { } indicates that no additional data is being passed with the event, but it can be included if needed.

mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.app_open); { }

iOS tracking

On Swift:

In Swift, the code parameters: [] also indicates that no extra information is accompanying this event, although it's possible to include more data.

Analytics.logEvent(AnalyticsEventLogin, parameters: [])

On Objective-C:

The same goes for parameters:@{} in Objective-C: 

[FIRAnalytics logEventWithName:kFIREventLogin];

2. Integrate Firebase with Bigquery

To deepen the analysis you can integrate Firebase with BigQuery, which enables running complex queries against analytics data. This setup requires adding a billing method to your Google Cloud Account and following the integration instructions on Firebase.

Here’s how to add a billing method to your Google Cloud Account:

  • Choose Billing in the main menu

  • Go to Firebase and select Settings Project/Integrations/BigQuery

  • Follow the instructions on Firebase

    This integration allows Firebase to automatically export analytics data to BigQuery.

3. Write and run SQL query in BigQuery

To analyse the app_open data, you can run a SQL query that counts the number of app_open events per user within a specified date range and add filters to only include users who have opened the app more than a certain number of times.

To do this, open Google Cloud, choose BigQuery and execute this code:

select count(user_pseudo_id) as users

From

(SELECT  user_pseudo_id, count(user_pseudo_id) as actions
FROM `krasotkapro.analytics_245540592.events_*`
WHERE (event_date BETWEEN '2024-01-01' AND '2024-01-31') AND
event_name="app_open"
GROUP BY user_pseudo_id)

Where actions>10

The example above groups app_open events by user_pseudo_id and counts the number of app_opens for each user within the specified date range (in this case, between 01.01.2024 and 01.31.2024). In the filters, where actions>10 allows you to only include users who performed more than 10 app_opens while krasotkapro.analytics_245540592.events_* refers to the BigQuery dataset that stores Firebase events.

Write and run SQL query in BigQuery

 

Reached X level event

This event marks every time a user reaches a new level within a game or app and helps understand and measure user interactions, which levels are more challenging, which are the favourite characters and how engaging the app is. These insights can inform user experience and retention strategies, from balancing game difficulty to enhancing app content.

This approach can be useful not only for games but for all gamified apps that feature different levels (for example, an app like Duolingo).

Reached X level event

Below is the code to be executed to implement the logEvent() method and it includes two key parameters:

  • level: indicates the level the user has reached and it shows their progression within the app;
  • character represents the character the user was playing when the level_up event happened and it provides insights on the character’s popularity and user preferences.

Android tracking

On Java:

Create a Bundle object by adding the level the user has reached and the character they are playing as parameters. Then log the level_up event using the mFirebaseAnalytics.logEvent() method

Bundle bundle = new Bundle();
bundle.putString(FirebaseAnalytics.Param.level, x);
bundle.putString(FirebaseAnalytics.Param.character, player1);
mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.level_up, bundle);

On Kotlin+KTX:

On Kotlin you can log the event with the same parameters while using scoped functions. These are part of Kotlin's standard library and provide a way to execute a block of code within the context of an object.

firebaseAnalytics.logEvent(FirebaseAnalytics.Event.level_up) {
     param(FirebaseAnalytics.Param.level, x)
     param(FirebaseAnalytics.Param.character, player1)
   }

iOS tracking

On Swift:

You can log the level_up event using the Analytics.logEvent() method, passing a dictionary of parameters that include the level and the character.

Analytics.logEvent(AnalyticsEventLevel_up, parameters: [
AnalyticsParameterLevel: x,
AnalyticsParameterItemCharacter: player1
])

On Objective-C

You can log the level_up event by calling [FIRAnalytics logEventWithName:parameters:] and passing a dictionary with the level and character.

[FIRAnalytics logEventWithName:kFIREventLevel_up
     parameters:@{
          kFIRParameterLevel:x,
          kFIRParameterItemCharacter
:player1
          }];

Kurve’s recommendations 
for optimising app performance:


Don’t overlook user retention

Leverage Firebase Analytics to assess campaign progress

Integrate with BigQuery to ensure seamless, data-driven insights

Customise your analysis by defining and monitoring unique interactions

Track app_open frequency and level progression to target high-quality users


Want to improve
engagement and retention?


k 1

Read the full guide