Skip to main content

Ad Format Integration

Here's how to integrate the supported ad formats on React Native. Each ad format has its own unique characteristics and implementation details.

App Open Ads

App open ads appear when the user opens your app or switches back to your app. They are displayed on the loading or splash screen.

Implementation

import { NativeModules, NativeEventEmitter } from 'react-native';
const { Yodo1MASAds } = NativeModules;

const handleEvents = ({value}) => {
switch (value) {
case 'onAppOpenAdLoaded':
// Handle the event when the ad is loaded
break;
case 'onAppOpenAdOpened':
// Handle the event when the ad is opened
break;
case 'onAppOpenAdClosed':
// Handle the event when the ad is closed
break;
case 'onAppOpenAdFailedToLoad':
// Ad failed to load, let's try again after a delay
break;
case 'onAppOpenAdFailedToOpen':
// Ad failed to open, let's try again after a delay
break;
}
};

// Register event listeners
const eventEmitter = new NativeEventEmitter(Yodo1MASAds);
const eventListener = eventEmitter.addListener('adEvent', handleEvents);

// Clean up on component unmount
useEffect(() => {
return () => {
eventListener.remove();
};
}, []);

Best Practices

  1. Event Cleanup: Always remove event listeners when components unmount to prevent memory leaks.
  2. Error Handling: Implement proper error handling for ad loading failures.
  3. Loading States: Manage loading states to provide better user experience.
  4. Component Lifecycle: Handle component lifecycle properly with React hooks.
  5. TypeScript: Use TypeScript for better type safety and development experience.