Skip to content

parthindia47/react-native-unity-ads

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Import the module

import UnityAdsModule from 'react-native-unity-ads-moon';

Initialize Ads - somewhere early in your app

/* Initialize Unity -> add correct ad id and mobile id here */
const unityRewardedAd = await UnityAdsModule.initializeAd('5261111', true);
console.log("INITIALIZE UNITY ADS -> " + unityRewardedAd)

Load Ads

UnityAdsModule.loadAd(); // unity ad load

Using Hooks with Unity Ads

/* this hook take care for unity ad call backs */
React.useEffect(async() => {

  const loadEventEmitter = new NativeEventEmitter();
  const showEventEmitter = new NativeEventEmitter();

  const loadEventListener = loadEventEmitter.addListener(
    'AD_LOADED', 
    (event) => {
      console.log("Unity Ad loading complete")
      console.log(event.adStatus) // "someValue"
      UnityAdsModule.showAd(); // show unity ad
  });

  const showEventListener = showEventEmitter.addListener(
    'AD_COMPLETED', 
    (event) => {
      console.log("Unity Ad showing complete")
      console.log(event.adStatus) // "someValue"

      if(event.adStatus == "fullComplete"){
        // do something once ad completes
      }
  });

  /* Unsubscribe from events on unmount */
  return () => {
    loadEventListener.remove();
    showEventListener.remove();
  };

}, []);

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Objective-C 43.3%
  • Java 42.6%
  • Kotlin 5.1%
  • TypeScript 4.6%
  • Ruby 4.4%
  • C 0.0%