Skip to content

MiniGameInterstitial

Full-screen ad that drops in at natural transition points — after a conversation ends, between sessions, or after a message threshold. Users play a sponsored mini-game with an AI character.

Interstitial mini-game ad displayed full-screen on mobile

Basic Usage

jsx
import { useEffect, useRef, useState } from 'react';
import { SimulaMiniGameInterstitial, SimulaEventType } from '@simula/ads-react-native';

function ChatScreen() {
  const [loaded, setLoaded] = useState(false);
  const retryAttempt = useRef(0);
  const interstitial = useRef(null);

  useEffect(() => {
    interstitial.current = SimulaMiniGameInterstitial.init({
      adUnitId: 'simula-xxxx-interstitial', // Optional: provided by Simula for tracking and measurement
    });

    const subs = [
      interstitial.current.addAdEventListener(SimulaEventType.LOADED, () => {
        retryAttempt.current = 0;
        setLoaded(true);
      }),
      interstitial.current.addAdEventListener(SimulaEventType.LOAD_FAILED, () => {
        retryAttempt.current += 1;
        if (retryAttempt.current > 6) return;
        const delay = Math.pow(2, retryAttempt.current);
        setTimeout(() => interstitial.current.load(), delay * 1000);
      }),
      interstitial.current.addAdEventListener(SimulaEventType.CLOSED, () => {
        setLoaded(false);
        interstitial.current.load();
      }),
    ];

    interstitial.current.load();

    return () => subs.forEach(sub => sub.remove());
  }, []);

  const handleMessageSent = () => {
    if (messageCount % 20 === 0 && loaded) {
      interstitial.current.show({
        charID: 'luna-123',    // Optional: current character, CharacterSelector pick, or omit for Simula default
        charName: 'Luna',
        charImage: 'https://cdn.example.com/avatars/luna.png',
      });
    }
  };

  return <ChatInterface onMessageSent={handleMessageSent} />;
}

Init Config

ParameterTypeRequiredDefaultDescription
adUnitIdstringNoAd unit ID provided by Simula. Used for measurement and improved targeting.
minPlayThresholdnumberNo10Minimum play time in seconds. Clamped to [10, 30].
delegateCharbooleanNotrueWhether Simula displays AI character messages inside the game iframe

Show Config

The character info personalizes the game experience — the AI companion reacts to gameplay, sends messages, and is present throughout. Pass in the character the user is currently talking to, a character from CharacterSelector, or omit to use a Simula default.

ParameterTypeRequiredDescription
charIDstringNoCharacter identifier
charNamestringNoCharacter name displayed in header
charImagestringNoCharacter avatar URL
charDescstringNoCharacter description

Event Types

EventPayloadDescription
SimulaEventType.LOADEDAd loaded and ready to show
SimulaEventType.LOAD_FAILEDerrorInfoAd failed to load. Retry with exponential backoff.
SimulaEventType.DISPLAYEDadInfoAd displayed on screen
SimulaEventType.DISPLAY_FAILEDerrorInfoAd failed to display. Load next ad.
SimulaEventType.CLICKEDadInfoUser tapped the ad
SimulaEventType.CLOSEDadInfoUser closed the ad. Load next ad.

Preload after close

Re-call .load() after CLOSED or DISPLAY_FAILED to preload and keep a fresh ad ready.