Let's assume that you need to adjust the values of some parameters in your app after you publish your app on the Play store. Typically, you should republish a new version of your app, and the users should update the app on their phone as well.

In general, the app update will work if you want to commit a long-lasting change to your app. However, what if you're going to adjust the value of some parameters in your app frequently? Or, what if you want to run some experiments to find the optimal app configuration?

In these cases, app update would not work well. Because it requires some time until the update entirely propagated to the users. Also, it's quite challenging to run the experiments across several app versions.

Also, how you can determine whether the user journey of the app is working as intended? You may rely on user comments on the Play console. However, it might not be precise enough to make a clear decision.

What you'll learn

What you'll need

How would you rate your level of experience with AdMob?

Novice Intermediate Proficient

How would you rate your level of experience with Firebase?

Novice Intermediate Proficient

Download the code

Click the following button to download all the code for this codelab:

Download source code

Unpack the downloaded zip file. This will unpack a root folder named admob-firebase-codelabs-unity-master.

...or clone the GitHub repository from the command line.

$ git clone https://github.com/googlecodelabs/admob-firebase-codelabs-unity

The repository contains four folders as follows:

Prepare required files

The Awesome Drawing Quiz uses several open-source codes, which are required to compile and run the project.

Open the terminal, and move to the repository root directory. Then, run ./gradlew :prepareThirdPartyFiles (gradlew.bat :prepareThirdPartyFiles on Windows) from the terminal to copy required files into the project.

Import the starter app

Launch Unity, choose "Open" in the welcome screen. Then select the 101-complete_and_102-base directory from the code you have downloaded.

You should now have the project open in Unity.

Add Google Mobile Ads Unity Plugin

To serve AdMob Ads on the Unity app, you need to add the Google Mobile Ads Unity Plugin into the project.

  1. Download the Google Mobile Ads Unity Plugin 3.18.1 package. (Note that this Codelab may not compatible with the other version of the plugin)
  2. In the Awesome Drawing Quiz Unity project. In the project, navigate to Assets > Import Package > Custom Package.
  3. Import the GoogleMobileAds.unitypackage into the project that you have downloaded.

You need to set the AdMob app ID as well. In the Unity editor, select Assets > Google Mobile Ads > Settings from the menu.

Enable AdMob by clicking Enabled checkbox under Google AdMob section. Then enter the AdMob app ID as follows:

Add Firebase config files to the Unity project

  1. From the overview screen of the Awesome Drawing Quiz project, click the Settings icon.
  2. Under the General tab, select each Android and iOS app to download the google-service.json (for Android) and the GoogleService-Info.plist (for iOS) file.
  3. Move both configuration files into the android_studio_folder.pngAssets folder in the Unity project.

Add Firebase Analytics SDK

  1. Download the Firebase Unity SDK 5.5.0 and unzip it somewhere convenient. (skip this step if you have already downloaded the SDK)
  2. Open the Awesome Drawing Quiz Unity project, navigate to Assets > Import Package > Custom Package.
  3. From the unzipped SDK, import the Firebase Analytics SDK (dotnet4/FirebaseAnalytics.unitypackage).
  4. In the Import Unity package window, click Import.

Before moving on to the next step, open the project from the Firebase console that you have created in the ‘Setup Firebase Project' step of the AdMob+Firebase 101 Codelab.

There might be a few app events that you've added to track the user activity inside of the app. By reading the report of each app event, you can get the details associated with the event like total counts, average counts per user, demographics, etc..

However, what if you want to see the completion rate of a series of events, instead of focusing on a specific event? In the Google Analytics for Firebase, you can use the Funnel to visualize and optimize the completion rate of a series of app events.

Create a funnel

To create a funnel:

  1. Go to the Firebase console and select the Awesome Drawing Quiz project you created earlier.
  2. Click the Funnels.
  3. Click NEW FUNNEL.
  4. Enter a name and description for the funnel.
  5. Select the first two events you want to use as steps in the funnel.
  6. Click ADD ANOTHER EVENT for each additional step, and select an event.
  7. Click CREATE.

By following the above steps, create the following funnels:

#1
Funnel name:
Level success rate
Events: level_start, level_success

#2
Funnel name:
Rewarded Ad completion rate
Events: ad_reward_prompt, ad_reward_impression, ad_reward

#3
Funnel name: Game completion rate
Events: game_start, game_complete

View funnel analysis

Once you have created some funnels, you can access it in the Funnels menu in the Firebase console. By clicking the funnel name in the list, you can see the detailed analysis of each funnel.

As an example, click the Level success rate. It will show the funnel details as follows:

From the above screenshot, you can see the % of users who have cleared a level (triggered the level_success event) after starting a level (triggered the level_start event). In here, you can see that 46.2% of the users have cleared the level.

Once you click Event count, it will show the metrics based on number of events as follows:

Based on the metrics on the above screenshot, there were 116 attempts (triggered the level_start event) and 57 clears (triggered the level_success event) during the period.

Since the completion rate based on the events(49.1%) is slightly higher than the rate based on the user(46.2%), you can say that there are a few people who perform better than the others.

Since you can get some insights on your app based on the app events and the funnel, you may want to optimize your app. It usually includes a fine-tuning of the parameter value in the app. To modify the value of those parameters, you'll need to update the app so the changes can be applied to the users.

By using the Remote Config in Firebase, you can adjust those values without an app update, which means you can change the app behavior without having to disturb your users by forcing them to download the update.

In this Codelab, you'll learn how to make the reward amount (number of letters to be disclosed after watching a Rewarded Video Ad) adjustable without an app update by using the Remote Config.

Add Firebase Remote Config SDK

  1. Download the Firebase Unity SDK 5.5.0 and unzip it somewhere convenient.
  2. Open the Awesome Drawing Quiz Unity project, navigate to Assets > Import Package > Custom Package.
  3. From the unzipped SDK, import the Remote Config SDK (dotnet4/FirebaseRemoteConfig.unitypackage).
  4. In the Import Unity package window, click Import.

Import Firebase.RemoteConfig

Modify the Main.cs to allow you to use type from the Firebase.RemoteConfig without having to use the fully qualified name.

Scenes/Main.cs

...

using AwesomeDrawingQuiz.Game;

// TODO: Import Firebase.RemoteConfig (102)
using Firebase.RemoteConfig;

namespace AwesomeDrawingQuiz.Scene {
    ...
}

Initialize & Fetch Remote Config values

Modify the InitAndFetchRemoteConfig() method in the Main.cs to initialize the Remote Config instance as follows. Note that GameSettings.KEY_REWARD_AMOUNT holds the name of the parameter in the Remote Config. (You'll declare this field soon in this Codelab)

Scenes/Main.cs

private Task InitAndFetchRemoteConfig() {
    // TODO: Initialize and Fetch values from the Remote Config (102)
    Dictionary<string, object> defaults = new Dictionary<string, object>();
    defaults.Add(GameSettings.KEY_REWARD_AMOUNT, 1);
    FirebaseRemoteConfig.SetDefaults(defaults);

    if (Debug.isDebugBuild) {
        ConfigSettings config = new ConfigSettings();
        config.IsDeveloperMode = true;
        FirebaseRemoteConfig.Settings = config;
        return FirebaseRemoteConfig.FetchAsync(System.TimeSpan.Zero);
    } else {
        return FirebaseRemoteConfig.FetchAsync();
    }
}

You'll see that the FirebaseRemoteConfig instance is configured to fetch the latest values from the server in debug mode to help the development process. (IsDeveloperMode = true and FetchAsync(System.TimeSpan.Zero))

Activate fetched Remote Config values

When you successfully fetched the Remote Config values, you should activate those values to make them available in the app. Modify the ActivateRemoteConfigValues() method as follows.

Scenes/Main.cs

private void ActivateRemoteConfigValues() {
    // TODO: Activate fetched Remote Config values (102)
    FirebaseRemoteConfig.ActivateFetched();
}

Modify the Start() method

To make the app fetches & activates the Remote Config value at the app launch, modify the Start() method in the Main.cs file as follows.

Scenes/Main.cs

void Start () {
    ...
    Firebase.FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task => {
        ...
    }).ContinueWith(task => { 
        // TODO: Call InitAndFetchRemoteConfig() (102)
        InitAndFetchRemoteConfig();
    }).ContinueWith(task => {
        // TODO: Call ActivateRemoteConfigValues() (102)
        ActivateRemoteConfigValues();

        // Enable 'Start a game' button
        UnityMainThreadDispatcher.Instance()
            .Enqueue(() => buttonStartGame.interactable = true);
    });
    #else
    QuizAnalytics.SetScreenName(QuizAnalytics.SCREEN_MAIN);

    // TODO: Call InitAndFetchRemoteConfig() (102)
    InitAndFetchRemoteConfig().ContinueWith(task => {
        // TODO: Call ActivateRemoteConfigValues() (102)
        ActivateRemoteConfigValues();
    });
    #endif
}

Fetch the reward amount from the Remote Config

Modify the GameSettings class to fetch the reward amount from the Remote Config.

Game/GameSettings.cs

// TODO: Import Firebase.RemoteConfig (102)
using Firebase.RemoteConfig;

namespace AwesomeDrawingQuiz.Game {
    public class GameSettings {

        ...
        
        // TODO: Apply reward amount from the Remote Config (102)
        public const string KEY_REWARD_AMOUNT = "reward_amount";

        public static GameSettings Instance {
            get {
                return instance;
            }
        }

        ...

        public int RewardAmount {
            get {
                // TODO: Apply reward amount from the Remote Config (102)
                return (int) FirebaseRemoteConfig.GetValue(KEY_REWARD_AMOUNT).LongValue;
            }
            private set { }
        }
    }
}

Create a Remote Config parameter from the console

Next, you'll create a new Remote Config parameter for the reward amount so you can adjust its value on the fly.

To create a new parameter, go to the Firebase console, then select the Awesome Drawing Quiz project that you have created earlier. Click Remote Config -> ADD YOUR FIRST PARAMETER button.

Name the parameter as reward_amount and set its default value to 1. Then click the Add Parameter button.

Click the Publish Changes button to make the change live to the users.

The amount of the reward in the Awesome Drawing Quiz is now can be configured on the Firebase console without having to update the app code.

In this section, you're going to change the reward amount from 1 to 2 to make the app to reveal two more characters as a hint after watching a Rewarded Ad.

Update the default value of the reward_amount parameter

Go to the Firebase console, then select the Awesome Drawing Quiz project you created earlier. Click Remote Config, and click reward_amount from the list. Next, change the default value to 2 then click the Update button.

Click the Publish changes button to make the change live to the users.

Verify the app behavior change

To confirm the app behavior change, run the project again. Once you finish watching a Rewarded Ad, you'll notice that the app now reveals two letters as a reward, as we configured in the Remote Config console.

Before watching a Rewarded Ad

Revealed two extra letters as a reward

Now you can change the amount of the reward without having to publish an app update. However, how you can determine the amount that you've changed is good for the app?

With the Firebase A/B Testing, you can run the experiments to optimize the overall user experience of the app without needing to update an app or building a separate tool to run and track the performance of each experiment.

Design the experiment

Before creating a new experiment, you should set a clear objective or goal of the experiment. Make sure to go through the following checklist before you create a new experiment.

In this Codelab, you're going to create an experiment to optimize the reward amount value to maximize the daily user engagement of the Awesome Drawing Quiz.

Create the experiment

Open the Awesome Drawing Quiz project from the Firebase console. Select A/B Testing menu, then click the Create experiment button.

Select the Remote Config to create a Remote Config experiment.

Name the experiment as ‘Amount of the Reward' as shown in the following screenshot.

Configure the targeting options. In this Codelab, you're going to target 100% of the users of the Awesome Drawing Quiz.

Since the main objective of the experiment is to find an optimal value that maximizes the daily user engagement, select the Daily user engagement as a primary metric to track.

Lastly, setup control and variant group so you can figure out which group performs better. Select reward_amount from the control group, and leave its value unchanged. For the variant group, name it as ‘Less reward,' then change the value of the reward_amount to 1.

With this configuration, people in the ‘Less reward' group will receive one letter as a reward, while the people in the Control group will receive two letters as a reward. As a result, you're going to see how the amount of reward impacts to the users.

Once you click the Review button, you'll see an overview of the experiment as follows.

Run the experiment

Click the Start experiment button to run the experiment. Note that you can't change the experiment configuration once it starts.

View the experiment progress

You can check the experiment progress from the A/B Testing menu in the Firebase console, which will look like the following screenshot. Note that you can also see the number of users who participate in the experiment in the last 30 minutes in the card.

Once you click the experiment from the list, you can see the experiment details. Until the experiment can declare a leader (i.e., the best performing variant), you'll see ‘It's too early to declare a leader' message.

Once the experiment has been running for a while, it will start to display the data collected during the experiment so far under Improvement overview section. You can compare the performance of each variant to see which one performs better. The following screenshot shows an example of the Improvement overview section.

From the table below the Improvement overview section, you can check the details of the goal metrics of the experiment as well as additional metrics being tracked in the experiment. The following screenshot shows an example of the metrics details section.

Roll out the leader to all users

After the experiment has run long that you have a leader, or winning variant, you can roll out the experiment to 100% of the users. Once the A/B Testing has found a clear leader, it will encourage you to roll out the leading variant to all users.

However, even if the experiment has not declared a clear leader, you can still choose to roll out a variant to all of the users.

On the experiment details screen, click the context menu (), and then click Roll out variant.

Choose a variant to roll out to all users, then click the Review in Remote Config button to review the changes before you make a change in the Remote Config.

After you confirm that the draft does not have any issue, click the Publish changes button to make the change live to all users.

You have completed AdMob+Firebase 102 Unity Codelab. You can find the completed code for this Codelab on android_studio_folder.png102-complete_and_103-base folder.

In the next part of the AdMob+Firebase Codelab, you'll learn how to use Firebase Predictions to change the app based on the predicted user behavior.