Experiment with monetization strategies using Firebase Predictions

Firebase Predictions makes it easy to provide your app's users a different experience depending on your users' predicted behavior. For example, you can provide an ad-free experience to users who are likely to make in-app purchases in the future, and show ads to everyone else. However, before you deploy this monetization strategy across the board, it's important to be sure that such a strategy actually improves your app's overall revenue.

This guide shows you how you can accomplish both goals using Firebase Predictions and Firebase A/B Testing: you will enable an ads-based monetization strategy for users who are predicted not to make in-app purchases, and you will verify the effectiveness of this new strategy.

Before you begin

Before you can start using predictions to determine your app's ads policy, you must be using Google Analytics for Firebase in your app. In particular, you must:

  • Enable Analytics data sharing in the Firebase console.
  • Explicitly log spending-related events that are not automatically collected, such as ecommerce_purchase. (Firebase automatically logs the in_app_purchase event for in-app purchases processed by the App Store and Play Store.) You should also generally log any other events that are relevant to your app, to maximize the data available to make classifications.
  • Have sufficient event data volume for Firebase to make meaningful predictions. Typically, 10,000 monthly active users, 500 positive examples, and 500 negative examples provide Firebase Predictions with enough data.

Make your ads remotely configurable

First, set up your app to show or hide ads depending on the value of a Remote Config parameter. In the steps that follow, you will configure Predictions and A/B Testing to set the parameter remotely based on various criteria, but for now, your app will always display ads.

For example, using AdMob for ads:

  1. Import the Analytics, Remote Config, and AdMob SDKs:

    iOS (Swift)

    Add the SDKs to your Podfile:

    pod 'Firebase/Core'
    pod 'Firebase/RemoteConfig'
    pod 'Firebase/AdMob'
    

    Then, import them:

    import Firebase
    

    Android

    implementation 'com.google.firebase:firebase-core:16.0.6'
    implementation 'com.google.firebase:firebase-config:16.1.2'
    implementation 'com.google.firebase:firebase-ads:17.1.2'
    
  2. Initialize Remote Config and set the default value of the ads_enabled variable to true. Later, you will set up Predictions and A/B Testing to set this variable remotely, but by setting a default value in your app, you ensure that your app functions correctly before remotely-configured variables are retrieved.

    iOS (Swift)

    self.remoteConfig = RemoteConfig.remoteConfig()
    self.remoteConfig.setDefaults(["ads_enabled": true])
    

    Java
    Android

    mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
    
    Map<String, Object> remoteConfigDefaults = new HashMap<>();
    remoteConfigDefaults.put("ads_enabled", "true");
    mFirebaseRemoteConfig.setDefaults(remoteConfigDefaults);

    Kotlin
    Android

    firebaseRemoteConfig = FirebaseRemoteConfig.getInstance()
    
    val remoteConfigDefaults = HashMap<String, Any>()
    remoteConfigDefaults["ads_enabled"] = "true"
    firebaseRemoteConfig.setDefaults(remoteConfigDefaults)
  3. Show or hide ads based on the value of ads_enabled. Until you set up Predictions, this value will always be true and ads will always be displayed.

    iOS (Swift)

    self.remoteConfig.fetch() { (status, error) -> Void in
        if status == .success {
          self.remoteConfig.activateFetched()
        }
    
        // Act on the retrieved parameters
    
        // Show ads based on the ad policy retrieved with Remote Config
        self.executeAdsPolicy()
    
        // ...
    }
    
    // ...
    
    func executeAdsPolicy() {
        let showAds = self.remoteConfig["ads_enabled"].booleanValue
        if showAds {
            bannerView.load(GADRequest())
            self.bannerView.isHidden = false
        } else {
            self.bannerView.isHidden = true
        }
    }
    

    Java
    Android

    mFirebaseRemoteConfig.fetch(CACHE_EXPIRATION)
            .addOnCompleteListener(this, new OnCompleteListener<Void>() {
        @Override
        public void onComplete(@NonNull Task<Void> task) {
            if (task.isSuccessful()) {
                mFirebaseRemoteConfig.activateFetched();
            }
    
            // Act on the retrieved parameters
    
            // Show ads based on the ad policy retrieved with Remote Config
            executeAdsPolicy();
    
            // ...
        }
    });
    // ...
    private void executeAdsPolicy() {
        boolean showAds = mFirebaseRemoteConfig.getBoolean("ads_enabled");
        AdView mAdView = findViewById(R.id.adView);
    
        if (showAds) {
            AdRequest adRequest = new AdRequest.Builder().build();
            mAdView.loadAd(adRequest);
            mAdView.setVisibility(View.VISIBLE);
        } else {
            mAdView.setVisibility(View.GONE);
        }
    }

    Kotlin
    Android

    firebaseRemoteConfig.fetch(CACHE_EXPIRATION)
            .addOnCompleteListener(this) { task ->
                if (task.isSuccessful) {
                    firebaseRemoteConfig.activateFetched()
                }
    
                // Act on the retrieved parameters
    
                // Show ads based on the ad policy retrieved with Remote Config
                executeAdsPolicy()
    
                // ...
            }
    // ...
    private fun executeAdsPolicy() {
        val showAds = firebaseRemoteConfig.getBoolean("ads_enabled")
        val adView = findViewById<AdView>(R.id.adView)
    
        if (showAds) {
            val adRequest = AdRequest.Builder().build()
            adView.loadAd(adRequest)
            adView.visibility = View.VISIBLE
        } else {
            adView.visibility = View.GONE
        }
    }

At this point, you can deploy your app to the App Store or Play Store. Users will get the default ads experience (ads always displayed), but because ad display is controlled by a remotely configurable variable, you can change and experiment with your ads' behavior using only the Firebase console, without having to push app updates to your users.

Start predicting user spending

Next, set up your Firebase project to start predicting your users' spending behavior.

In the Firebase console, open the Predictions section. If you haven't already agreed to the Predictions terms of service, do so.

After you have agreed to the terms of service, Predictions will be enabled for your project. The Predictions section of the Firebase console allows you to define custom predictions. However, for spending predictions, you can make use of the built-in spend and not_spend predictions, which use an aggregation of Analytics events to predict whether a user will make an in-app purchase or an ecommerce purchase (subscription purchases are not currently considered in this prediction). These predictions will become available after you enable Predictions and have logged a few weeks' worth of spending events.

Create a monetization strategy experiment

Now create an A/B Testing experiment that tests the effect of the prediction-based monetization strategy on revenue compared to always displaying ads.

It is beneficial for an experiment to have three variants—a control group, a group that unconditionally sets a parameter, and a prediction-based group—so the experiment can determine whether the prediction-based approach has a greater benefit than from simply applying the treatment to everyone.

To create the experiment:

  1. In the Firebase console, open the A/B Testing section.

  2. Create a new experiment:

    1. Click Create experiment > Remote Config.

    2. Choose your app from the list and specify how many of your users you want to include in the experiment. You can also choose to exclude certain user categories, such as high spenders, from the experiment.

    3. Choose Estimated total revenue from the list of goal metrics, and select any additional metrics you want to track, such as user engagement, retention, app removals, and ad clicks.

    4. Define three variants:

      • Control group (created automatically)
      • Never display ads
      • No ads for likely spenders

      For the Control group, create an ads_enabled parameter and set it to (no change). Users assigned to the control group will get the default behavior, which is to always see ads.

      For the Never display ads variant, set ads_enabled parameter to false. Users assigned to this variant never see ads.

      For the No ads for likely spenders variant, set ads_enabled parameter to false and set the target condition to Predict: spend (medium risk tolerance). Users assigned to this variant won't see ads on days they are predicted to spend.

Start the experiment and let it run for several days or more, until A/B Testing declares a leader. If the experiment cannot determine a leader, you might need to expand the experiment to more users.

Roll out the winning variant to all users

After A/B Testing has collected enough information to declare a leader—in this case, the variant that maximized app revenue—you can decide whether to roll out the winning variant (or another variant) to all of your users.

In the A/B Testing section of the Firebase console, open the details view of the completed experiment. From this view, you can see how each variant performed according to your goal metric and any secondary metrics you selected. With this information, you can decide whether to roll out the leading variant or another variant.

To roll out a variant to all users, click more_vert > Roll out the leader on the experiment's details page.

Send feedback about...

Need help? Visit our support page.