4. Call the Inference API

Configure the Airflux SDK to call the Inference API before displaying ads, and use the API response to determine whether to proceed with the ad display. This step may take about 15 minutes to 1 hour.


1. Call the Inference API and configure callbacks

Airflux analyzes player behavior using in-game events and player attribute data to determine the optimal timing for ad displays to maximize revenue. When calling the Inference API before showing an ad to the player, the Airflux AI will return a decision on whether to display the ad or skip it.

The InferenceShowAdInterstitial() function should be called when the ad is supposed to be shown.

If the API call is successfully processed, the onShowAd callback function is triggered to show the ad to the player, or the onSkipAd callback function is triggered to skip the ad for the player.

Airflux.InferenceShowAdInterstitial(
    onShowAd: () => { /* Show Ad */ },
    onSkipAd: () => { /* Skip Ad */ },
    onFailure: (AirfluxError error) => { /* Handle on failure */ }
);

When the API call fails, onFailure is returned. The API call may fail in the following cases:

  • The device's country is not in the countryAllowlist: API calls may fail for players in countries not supported by Airflux.

  • The inference server returns a 4XX or 5XX error response: API calls may fail due to internal server errors or invalid requests.

  • The API call times out after 3 seconds without a response: Network delays or other issues may cause the API response time to go beyond the limit.

Failure to call the InferenceShowAdInterstitial() function may lead to degraded play experience and loss of ad revenue. Therefore, it is recommended that a 3-second timeout be set and a fallback be implemented to display ads to the player in case the API call fails, to minimize potential negative effects. Retry attempts upon function call failure are not required.

Frequently Asked Questions

What is the difference between onSkipAd() and onFailure() callbacks?
  • The onSkipAd() callback function is triggered when the API call is successful, and the inference result from the Airflux AI model indicates that an ad should not be displayed to enhance the play experience and maximize ad revenue.

  • The onFailure() callback function is triggered when the API call fails. This includes situations such as the device's country not being in the allowlist (countryAllowlist), network issues, server errors, or request validation failures, where no response is received.

What is the response time of the API by country?

Airflux aims to deliver reliable service to users worldwide and typically maintains quick response times in most regions. However, minor delays may arise based on the network environment.

2. Verify implementation

Ensure that the InferenceShowAdInterstitial() function is called when the ad is supposed to be shown to the player.

Then, verify that the logic for proceeding with ad display based on the API response is properly implemented. Airflux supports testing API call response scenarios for you to verify proper implementation. The following settings should be used for verification purposes only and must be removed before deploying the app.

Test options

You can simulate specific test scenarios by setting the contexts.inferenceAttributes.forceInferenceResponse field in the Inference API request.

Value
Purpose
Expected Behavior

onShowAd

Test ad display

Always returns true → Ad is shown

onSkipAd

Test ad skip

Always returns false → Ad is skipped

onFailure

Test API failure scenario

Returns HTTP 422 → Client should handle fallback

Test setup

Airflux.SetInferenceAttribute("forceInferenceResponse", "onShowAd");
// The following call to Airflux.InferenceShowAdInterstitial() will return "onShowAd"

Airflux.SetInferenceAttribute("forceInferenceResponse", "onSkipAd");
// The following call to Airflux.InferenceShowAdInterstitial() will return "onSkipAd"

Airflux.SetInferenceAttribute("forceInferenceResponse", "onFailure");
// The following call to Airflux.InferenceShowAdInterstitial() will return "onFailure"

Confirm that when the onShowAd callback is triggered, the ad is displayed, and when the onSkipAd callback is triggered, the ad is skipped. When the onFailure callback is triggered, the fallback procedure is operated as intended.

3. Deploy the app

After completing sufficient QA and crash testing, deploy your gaming app. To ensure proper integration with Airflux, make sure the deployment follows the timeline coordinated with the Growth Manager.

Where can I get guidance for the app store review?

Click here for guidance on preparing for the Google Play and App Store reviews.

Next steps

Congratulations! If you have completed the steps above, you are all set to optimize your in-game advertising with Airflux. Click here to learn how to receive your optimization results.

Last updated