The useReneVerse hooks provide a set of functions that seamlessly interact with ReneVerse API services.
These hooks enable ad serving, retrieval of ad surfaces, and ad tracking, simplifying the integration of advertising features into your projects.
getAdSurfaces()
This function allows you to get all the ad surfaces you have defined for your game.
import { PhaserHooks } from"@reneverse/rene-sdk-phaser";functionApp() {// Initialize PhaserHooks with API Key and Private Key for ReneVerseconstphaserHooks=newPhaserHooks({ apiKey:'<YOUR API KEY>', privateKey:'<YOUR PRIVATE KEY>', });constgetAdSurfaces=async () => {// Fetch all Ad surfaces configured in your game on the ReneVerse portalconstadSurfaces=awaitphaserHooks.useReneVerse().getAdSurfaces();console.log(adSurfaces); }// Creating a button to call the getAdSurfaces functionreturn ( <div><button onClick={getAdSurfaces}> Get Ad Surfaces</button></div> );}exportdefault App;
This function allows you to serve Ad in the requested ad surface.
Params
adSurfaceId : string
import { PhaserHooks } from"@reneverse/rene-sdk-phaser";functionApp() {// Initialize PhaserHooks with API Key and Private Key for ReneVerseconstphaserHooks=newPhaserHooks({ apiKey:'<YOUR API KEY>', privateKey:'<YOUR PRIVATE KEY>', });constserveAd=async () => {// Fetch all Ad surfaces configured in your game on the ReneVerse portalconstadSurfaces=awaitphaserHooks.useReneVerse().getAdSurfaces();// Check if there are any ad surfaces configured in the ReneVerse portalif (!adSurfaces.items.length) {console.log("No ad surfaces found");return; }// Fetch Ad from ReneVerseconstad=await phaserHooks.useReneVerse().getAd(adSurfaces.items[0].adSurfaceId);console.log(ad); }// Creating a button to call the serveAd functionreturn ( <div> <buttononClick={serveAd}> Serve Ad </button> </div> );}exportdefault App;
This function allows you to record impressions for served Ads.
Params
ad : type ServeAd
screenCoveragePercentage: number
timeInMilliseconds: number
angleView?: number
import { PhaserHooks } from"@reneverse/rene-sdk-phaser";functionApp() {// Initialize PhaserHooks with API Key and Private Key for ReneVerseconstphaserHooks=newPhaserHooks({ apiKey:'<YOUR API KEY>', privateKey:'<YOUR PRIVATE KEY>', });consttrackAd=async () => {// Fetch all Ad surfaces configured in your game on the ReneVerse portalconstadSurfaces=awaitphaserHooks.useReneVerse().getAdSurfaces();// Check if there are any ad surfaces configured in the ReneVerse portalif (!adSurfaces.items.length) {console.log("No ad surfaces found");return; }// Fetch Ad from ReneVerseconstad=await phaserHooks.useReneVerse().getAd(adSurfaces.items[0].adSurfaceId);// Let's say the ad is covering 20% of the screen.constscreenCoveragePercentage=20;// Setting a 1 second delay before tracking AdssetTimeout(() => {consttrackAds=await phaserHooks.useReneVerse().trackAdSingle( ad, screenCoveragePercentage,1000,// 1 seconds = 1000 milliseconds0// For 2d, The angle is always 0 );console.log(trackAds); },1000); }// Creating a button to call the trackAd functionreturn ( <div><button onClick={trackAd}> Track Ad</button></div> );}exportdefault App;
Returns
returns boolean
trackAdMultiple()
This function allows you to aggregate and record impressions for several served ads concurrently, reducing individual tracking overhead and streamlining analytics collection.
Params
adDataList : [{
ad : type ServeAd
screenCoveragePercentage: number
timeInMilliseconds: number
angleView?: number
}]
import { PhaserHooks } from"@reneverse/rene-sdk-phaser";functionApp() {// Initialize PhaserHooks with API Key and Private Key for ReneVerseconstphaserHooks=newPhaserHooks({ apiKey:'<YOUR API KEY>', privateKey:'<YOUR PRIVATE KEY>', });consttrackAds=async () => {// Fetch all Ad surfaces configured in your game on the ReneVerse portalconstadSurfaces=awaitphaserHooks.useReneVerse().getAdSurfaces();// Check if there are more than 1 ad surfacesif (adSurfaces.items.length<2) {console.log("Create more ad Surfaces");return; }// Fetch Ad from ReneVerseconstad=await phaserHooks.useReneVerse().getAd(adSurfaces.items[0].adSurfaceId);// Fetch Second Ad from ReneVerseconstad2=await phaserHooks.useReneVerse().getAd(adSurfaces.items[1].adSurfaceId);// Let's say the first ad is covering 20% of the screen.constfirstScreenCoveragePercentage=20;// Let's say the second ad is covering 40% of the screen.constsecondScreenCoveragePercentage=40;// Setting a 1 second delay before tracking AdssetTimeout(() => {consttrackAds=await phaserHooks.useReneVerse().trackAdMultiple( [{ ad: ad, screenCoveragePercentage: firstScreenCoveragePercentage, timeInMilliseconds:1000,// 1 seconds = 1000 milliseconds angleView:0// For 2d, The angle is always 0 }, { ad: ad2, screenCoveragePercentage: secondScreenCoveragePercentage, timeInMilliseconds:1000,// 1 seconds = 1000 milliseconds angleView:0// For 2d, The angle is always 0 }] );console.log(trackAds); },1000); }// Creating a button to call the trackAds functionreturn ( <div><button onClick={trackAds}> Track Ads</button></div> );}exportdefault App;