Experiment with promotion strategies using Firebase Predictions

With Firebase Predictions, you can optimize your in-app promotions for each of your users based on the likelihood of the user making an in-app purchase. For example, you can promote your more expensive "premium" bundle to users likely to spend, and promote your less expensive basic bundle to other users.

Then, using A/B Testing, you can conduct an experiment to see how this prediction-based strategy affects in-app purchase revenue compared to simply always promoting the basic bundle and always offering the premium bundle.

Before you begin

Before you can start using predictions to determine your app's promotion strategy, 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 spend prediction:

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

Create a promotion strategy experiment

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

  • Always promote the basic bundle (control group)
  • Always promote the premium bundle
  • Promote the basic or premium bundle depending on the spending prediction

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 promotion strategy.

      Then, create an promoted_bundle parameter and assign the value basic to the control group variant, premium to the second variant, and predict to the prediction-based variant. Your app uses this parameter to which bundle to promote to a particular user.

    3. Choose Purchase revenue from the list of goal metrics, and select any additional metrics you want to track, such as retention and daily engagement.

      Finally, in the Advanced options section, select the promotion_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 promotion strategies in your app

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

For example:

  1. Import the Analytics and Remote Config SDKs:

    iOS (Swift)

    Add the SDKs to your Podfile:

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

    Then, import them:

    import Firebase
    

    Android

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

    iOS (Swift)

    self.remoteConfig = RemoteConfig.remoteConfig()
    self.remoteConfig.setDefaults(["promoted_bundle": "basic"])
    
    // ...
    
    self.remoteConfig.fetch() { (status, error) -> Void in
        if status == .success {
          self.remoteConfig.activateFetched()
        }
    
        // Act on the retrieved parameters
    
        // Set the bundle to promote based on parameters retrieved with Remote
        // Config
        self.promotedBundle = self.getPromotedBundle()
    
        // ...
    }
    

    Android

    mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
    
    Map remoteConfigDefaults = new HashMap<String, Object>();
    remoteConfigDefaults.put("promoted_bundle", "basic");
    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
    
                // Set the bundle to promote based on parameters retrieved with
                // Remote Config
                mPromotedBundle = getPromotedBundle();
    
                // ...
            }
        });
    
  3. Finally, set the bundle you will promote to the user based on the parameters you retrieved. Also, at this time, log the promotion_set event to indicate that user can be considered to be participating in the experiment.

    iOS (Swift)

    func getPromotedBundle() -> String {
        Analytics.logEvent("gift_policy_set", parameters: nil)
    
        let promotedBundle = self.remoteConfig["promoted_bundle"].stringValue
        let willSpend = self.remoteConfig["predicted_will_spend"].booleanValue
    
        if (promotedBundle == "predicted") && will_spend {
            return "premium"
        } else {
            return promotedBundle
        }
    }
    

    Android

    private String getPromotedBundle() {
        FirebaseAnalytics.getInstance(this).logEvent("promotion_set", true);
    
        String promotedBundle = mFirebaseRemoteConfig.getString("promoted_bundle");
        boolean will_spend = mFirebaseRemoteConfig.getBoolean("predicted_will_spend");
    
        if (promotedBundle.equals("predicted") && will_spend) {
            return "premium";
        } else {
            return promotedBundle;
        }
    }
    

Send feedback about...

Need help? Visit our support page.