Mediation A/B experiment

The AdMob API can create mediation A/B experiments to maximize your ads performance by testing various configurations. An A/B test lets you evaluate two variations of a mediation group to compare the results side by side and select a preferred configuration.

Here are examples of experiments you can set up:

  • Adding or removing ad sources to see their impact on your mediation group
  • Using a different waterfall order by changing the manual eCPM value of ad sources
  • Enabling or disabling optimization on waterfall ad sources
  • Changing the number of times an ad source is called

Examples

Start with an existing mediation group and create a variation of it to see which variant, A or B, performs better. The test splits your app's users between your existing mediation group setup and the variation, based on a percentage (1%, 10%, or 50%) you provide.

curl (command line)

Requests using curl

  1. Load the client secrets file and generate authorization credentials.

    The first time you perform this step, you are asked to accept an authorization prompt in your browser. Before accepting, make sure you're signed in with a Google Account that has access to the AdMob API. Your app will be authorized to access data on behalf of whichever account is currently logged in.

    For authentication and authorization, we recommend using oauth2l, a simple command-line tool for working with Google OAuth 2.0. Install oauth2l and run the command below, replacing path_to_credentials_json with a path to a credentials.json file that you download when registering your cloud app. For the first run, the command walks you through the OAuth 2.0 authorization flow. Subsequent runs refresh the token automatically.

    oauth2l header --json path_to_credentials_json --scope admob.monetization,admob.readonly
    
  2. Create a mediation A/B experiment.

    Replace pub-XXXXXXXXXXXXXXXX with your publisher ID and ZZZZZZZZZZ with your mediation group ID. The mediation group ID can be found in the AdMob UI or by using the accounts.mediationGroups:list method.

    You need to specify the treatmentMediationLines and treatmentTrafficPercentage, however, the controlMediationLines are inherited from the parent mediation group and do not need to be specified.

    The following request creates a mediation A/B experiment where the treatment variant, also known as variant B, contains a single mediation line for the AdMob network using LIVE mode.

    curl --http1.0 \
    -X POST https://admob.googleapis.com/v1beta/accounts/pub-XXXXXXXXXXXXXXXX/mediationGroups/ZZZZZZZZZZ/mediationAbExperiments \
    -H "Content-Type:application/json" \
    -H "$(oauth2l header --json path_to_credentials_json --scope admob.monetization)" \
    --data @- << EOF
    {
      "displayName":"Mediation A/B Experiment Test Name",
      "treatmentTrafficPercentage": "50",
      "treatmentMediationLines": [{
        "mediationGroupLine": {
          "displayName": "Test mediation group line",
          "adSourceId": "5450213213286189855",
          "cpm_mode": "LIVE"
        }
      }]
    }
    EOF

    See the sample response below where SSSSSSSSSSSSSSSSSSSSSS represents the created mediation A/B experiment ID and YYYYYYYYYY represents the last 10 digits of your ad unit ID, complying to the format: ca-app-pub-XXXXXXXXXXXXXXXX/YYYYYYYYYY.

    {
      "name": "accounts/pub-XXXXXXXXXXXXXXXX/mediationGroups/ZZZZZZZZZZ/mediationAbExperiments/SSSSSSSSSSSSSSSSSSSSSS",
      "displayName": "Mediation A/B Experiment Test Name",
      "experimentId": "SSSSSSSSSSSSSSSSSSSSSS",
      "treatmentTrafficPercentage": "50",
      "treatmentMediationLines": [
        {
          "mediationGroupLine": {
            "id": "11111111111111111",
            "displayName": "Test mediation group line",
            "adSourceId": "5450213213286189855",
            "cpmMode": "LIVE",
            "cpmMicros": "10000",
            "adUnitMappings": {
              "ca-app-pub-XXXXXXXXXXXXXXXX/YYYYYYYYYY": "accounts/pub-XXXXXXXXXXXXXXXX/adUnits/YYYYYYYYYY/adUnitMappings/
              "ca-app-pub-XXXXXXXXXXXXXXXX/YYYYYYYYYY": "accounts/pub-XXXXXXXXXXXXXXXX/adUnits/YYYYYYYYYY/adUnitMappings/
            },
            "state": "ENABLED"
          }
        }
      ],
      "controlMediationLines": [
        {
          "mediationGroupLine": {
            "id": "22222222222222222",
            "displayName": "AdMob Network (control)",
            "adSourceId": "5450213213286189855",
            "cpmMode": "LIVE",
            "cpmMicros": "10000",
            "adUnitMappings": {
              "ca-app-pub-XXXXXXXXXXXXXXXX/YYYYYYYYYY": "accounts/pub-XXXXXXXXXXXXXXXX/adUnits/YYYYYYYYYY/adUnitMappings/
              "ca-app-pub-XXXXXXXXXXXXXXXX/YYYYYYYYYY": "accounts/pub-XXXXXXXXXXXXXXXX/adUnits/YYYYYYYYYY/adUnitMappings/
            },
            "state": "ENABLED"
          }
        }
      ],
      "state": "RUNNING"
    }
  3. Verify the mediation A/B experiment is running.

    Call accounts.mediationGroups:list to get the mediation A/B experiment status for that mediation group. See the mediation groups guide for more details.

    The mediationAbExperimentState is set to RUNNING for active mediation A/B experiments and NOT_RUNNING if there is no experiment running in the mediation group.

    Sample request:

     curl --http1.0 \
    -X GET https://admob.googleapis.com/v1beta/accounts/pub-XXXXXXXXXXXXXXXX/mediationGroups \
    -H "$(oauth2l header --json path_to_credentials_json --scope admob.readonly)"
    
  4. Stop the mediation A/B experiment and select a variant.

    Replace pub-XXXXXXXXXXXXXXXX with your publisher ID and ZZZZZZZZZZ with your mediation group ID. The mediation group ID can be found in the AdMob UI or by using the accounts.mediationGroups:list method.

    To complete the experiment, specify the winning variant in the request:

    • VARIANT_CHOICE_A: Use the mediation lines from Variant A and complete the experiment. Variant A contains the original serving lines before the experiment creation.
    • VARIANT_CHOICE_B: Use the mediation lines form Variant B and complete the experiment. Variant B contains the newly added serving lines.

    Sample request:

     curl --http1.0 \
    -X POST https://admob.googleapis.com/v1beta/accounts/pub-XXXXXXXXXXXXXXXX/mediationGroups/ZZZZZZZZZZ/mediationAbExperiments:stop \
    -H "Content-Type:application/json" \
    -H "$(oauth2l header --json path_to_credentials_json --scope admob.monetization)" \
    --data @- << EOF
    {
    "variantChoice": "VARIANT_CHOICE_A"
    }
    

    Sample response:

    {
    "experimentId": "SSSSSSSSSSSSSSSSSSSSSS",
    "state": "EXPIRED",
    }