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 won't adversely affect retention of your existing users.

This guide shows you how you can accomplish both goals using Firebase Predictions and 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.

Start predicting user spending

The first step is to set up your Firebase project to start predicting your users' spending.

  1. 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 are based on an aggregation of Analytics events. These predictions will become available around 24 hours after you enable Predictions and have logged some baseline spending events.

  2. Add a Remote Config parameter that corresponds to the not_spend prediction:

    1. In the Firebase console, click Remote Config.
    2. Add a new parameter named (for example) will_not_spend. Create a new condition for this parameter that applies when not_spend is predicted. Then, set the value for the new condition to true and set the default value to false.

Create a monetization strategy experiment

Next, create an A/B testing experiment that tests three monetization strategies:

  • Never display ads (control group)
  • Always display ads
  • Display ads only to users predicted not to spend

To create the experiment:

  1. In the Firebase console, open the Remote Config section.
  2. Click the A/B testing button.
  3. Create a new experiment:

    1. 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.

    2. Define three variants: one for each monetization strategy.

      Then, create an ads_policy parameter and assign the value ads_never to the control group variant, ads_always to the second variant, and ads_nonspenders to the prediction-based variant. Your app uses this parameter to decide whether to display ads to a particular user.

    3. Choose Retention (2-3 days) from the list of goal metrics, and select any additional metrics you want to track, such as purchase revenue, app removals, and ad clicks.

      Finally, in the Advanced options section, select the ads_policy_set Analytics event, which you explicitly log in your app. Note that this event will not appear in the list until it has been logged once.

Implement your monetization strategies in your app

Now that you have set up your predictions and experiments in the Firebase console, implement the monetization strategies from each of your experiment variants.

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

    compile 'com.google.firebase:firebase-core:11.6.2'
    compile 'com.google.firebase:firebase-config:11.6.2'
    compile 'com.google.firebase:firebase-ads:11.6.2'
    
  2. Retrieve the ads policy for the current user using Remote Config.

    iOS (Swift)

    self.remoteConfig = RemoteConfig.remoteConfig()
    self.remoteConfig.setDefaults(["ads_policy": "ads_never"])
    
    // ...
    
    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()
    
        // ...
    }
    

    Android

    mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
    
    Map remoteConfigDefaults = new HashMap<String, Object>();
    remoteConfigDefaults.put("ads_policy", "ads_never");
    mFirebaseRemoteConfig.setDefaults(remoteConfigDefaults);
    
    // ...
    
    mFirebaseRemoteConfig.fetch(cacheExpiration)
        .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();
    
                // ...
            }
        });
    
  3. Finally, display or hide ads based on the ad policy you retrieved. Also, at this time, log the ads_policy_set event to indicate that user can be considered to be participating in the experiment.

    iOS (Swift)

    func executeAdsPolicy() {
        let adsPolicy = self.remoteConfig["ads_policy"].stringValue
        let willNotSpend = self.remoteConfig["will_not_spend"].booleanValue
    
        if adsPolicy == "ads_always"
                || ((adsPolicy == "ads_nonspenders") && willNotSpend) {
            bannerView.load(GADRequest())
            self.bannerView.isHidden = false
        } else {
            self.bannerView.isHidden = true
        }
    
        Analytics.logEvent("ads_policy_set", parameters: nil)
    }
    

    Android

    private void executeAdsPolicy() {
        String adsPolicy = mFirebaseRemoteConfig.getString("ads_policy");
        boolean will_not_spend = mFirebaseRemoteConfig.getBoolean("will_not_spend");
        AdView mAdView = (AdView) findViewById(R.id.adView);
    
        if (adPolicy.equals("ads_always") ||
            (adPolicy.equals("ads_nonspenders") && will_not_spend)) {
             AdRequest adRequest = new AdRequest.Builder().build();
             mAdView.loadAd(adRequest);
             mAdView.setVisibility(View.VISIBLE);
        } else {
            mAdView.setVisibility(View.GONE);
        }
    
        FirebaseAnalytics.getInstance(this).logEvent("ads_policy_set", true);
    }
    

Send feedback about...

Need help? Visit our support page.