LogoLogo
  • ReneVerse Tour
    • ๐Ÿ‘‹Welcome to ReneVerse
      • ๐Ÿง Smart Ads & Branded Objects
      • ๐Ÿ“ˆAdvertising Demand via ReneVerse
      • ๐Ÿ”ฎThe Portal
      • ๐ŸงฐThe SDKs
  • Getting Started
    • ๐Ÿš€Getting Started with ReneVerse
    • ๐Ÿ“Registering as a New User
    • ๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆCreating a New Organization
    • ๐Ÿ‘ฅInvite Members to Your Team
  • Publisher Flow
    • ๐Ÿ•น๏ธPublisher Overview
    • โšกQuick Start Guide
    • ๐Ÿ’พRegistering Your Game & Generating API Keys
    • ๐ŸงฉSDK Integration
      • ๐Ÿ› ๏ธUnity
        • ๐Ÿ”งUnity SDK Setup
        • ๐Ÿ”จ[WIP] Using the Unity SDK
          • ๐ŸฅžBatch Serve Ad
      • ๐ŸŽฎUnreal Engine
        • โš™๏ธUE SDK Setup
        • ๐Ÿ”ฉUsing the UE SDK
      • ๐ŸŒPhaser 3
        • ๐Ÿ’ซPhaser Quick Start
        • ๐ŸงชAPI Reference
          • ๐ŸชuseReneVerse
          • ๐Ÿ“ŠuseTracking
        • ๐Ÿ’ปFull Implementation (Code)
    • ๐ŸŽฏDefining Placeholders in the Portal
      • ๐Ÿ–ผ๏ธCreating Ad Surfaces in the Portal
      • ๐ŸŽ๏ธCreating Branded Object Placements in the Portal
    • ๐Ÿ“ฒAds.txt
  • Advertiser Flow
    • Advertiser Overview
    • Creating Ad Campaign
    • Managing Brands
      • Creating Branded Collections
      • Brand Creation
      • Asset Creation
    • Adding Ads to Campaign
    • Creating Branded Assets
  • Download
    • Unity SDK
    • Unreal Engine SDK
    • Phaser NPM Package
Powered by GitBook
LogoLogo

ReneVerse

  • Website
  • Sign Up
  • Book a demo

Download

  • Unity SDK
  • Unreal Engine SDK
  • Phaser NPM

Links

  • Blog
  • About
  • Play Demo
  • FAQs

Socials

  • LinkedIn
  • X (Twitter)
  • YouTube

ยฉ 2025 ReneVerse

On this page
  • checkAdFullVisibility()
  • calculateAdCoverage()
  1. Publisher Flow
  2. SDK Integration
  3. Phaser 3
  4. API Reference

useTracking

The useTracking hooks help you measure ad visibility and interaction in your Phaser game.

PrevioususeReneVerseNextFull Implementation (Code)

Last updated 1 month ago

The useTracking hooks monitor visibility and screen coverage of served Ads, ensuring accurate impression counting based on ReneVerse viewability standards.


checkAdFullVisibility()

Description: Determines whether a specific ad is fully visible in the current scene and whether itโ€™s being blocked by any other objects.

Params

  • adSprite : Phaser Sprite Object

  • scene: Phaser Scene Object

import { PhaserHooks } from "@reneverse/rene-sdk-phaser";
import { IRefPhaserGame, PhaserGame } from "./game/PhaserGame";
import { useRef } from "react";

function App() {
  
  //  References to the PhaserGame component (game and scene are exposed)
  const phaserRef = useRef<IRefPhaserGame | null>(null);
  
  // Initialize PhaserHooks with API Key and Private Key for ReneVerse
  const phaserHooks = new PhaserHooks({
    apiKey: '<YOUR API KEY>',
    privateKey: '<YOUR PRIVATE KEY>',
  });
  
  const checkVisibility = async () => {
    if (phaserRef.current) {
      const scene = phaserRef.current.scene;

      if (scene) {
  
        // Fetch Ad surfaces configured in the ReneVerse portal
        const adSurfaces = await phaserHooks.useReneVerse().getAdSurfaces();
    
        // Check if there are any ad surfaces configured in the ReneVerse portal
        if (!adSurfaces.items.length) {
          console.log("No ad surfaces found");
          return;
        }
    
        // Fetch Ad from ReneVerse
        const ad = await phaserHooks
          .useReneVerse()
          .getAd(adSurfaces.items[0].adSurfaceId);
      
        // Load Ad image
        if (ad.adId) {
          scene.load.image("dynamicAd", ad.url as string);
          
          scene.load.once("complete", () => {
          
            // Get Random Position
            const x = Phaser.Math.Between(100, 900);
            const y = Phaser.Math.Between(100, 600);
          
            //  `add.sprite` is a Phaser GameObjectFactory method and it returns a Sprite Game Object instance
            const adSurface = scene.add.sprite(x, y, "dynamicAd");

            // Set display size
            adSurface.setDisplaySize(300, 200);
            
            // Check if the Ad is visible or not
            const visibilityCheck = phaserHooks
                .useTracking()
                .checkAdFullVisibility(adSurface, scene);
                
            if (visibilityCheck.isFullyVisible) {
              console.log("Ad is Fully Visible");
            } else {
              console.log("Ad is blocked");
            }
            
          };
          
          scene.load.start();
        }
      }
    }
  }
  
  // Creating a button to call the serveAd function
  return (
      <div>
        <PhaserGame ref={phaserRef} />
        <button onClick={checkVisibility}>
          Check Visibility
        </button>
      </div>
  );
}

export default App;

Returns

interface CheckAdFullVisibility {
 isFullyVisible : Boolean
 blockingSprites : [Phaser Sprite Object]
}

Description: Calculates how much of the ad is visible to the player based on the current camera view. Useful for impression tracking and engagement analysis.

Params

  • adSprite : Phaser Sprite Object

  • camera : Phaser Camera Object

import { IRefPhaserGame, PhaserGame } from "./game/PhaserGame";
import { useRef } from "react";

function App() {
  
  //  References to the PhaserGame component (game and scene are exposed)
  const phaserRef = useRef<IRefPhaserGame | null>(null);
  
  // Initialize PhaserHooks with API Key and Private Key for ReneVerse
  const phaserHooks = new PhaserHooks({
    apiKey: '<YOUR API KEY>',
    privateKey: '<YOUR PRIVATE KEY>',
  });
  
  const checkVisibility = async () => {
    if (phaserRef.current) {
      const scene = phaserRef.current.scene;

      if (scene) {
  
        // Fetch Ad surfaces configured in the ReneVerse portal
        const adSurfaces = await phaserHooks.useReneVerse().getAdSurfaces();
    
        // Check if there are any ad surfaces configured in the ReneVerse portal
        if (!adSurfaces.items.length) {
          console.log("No ad surfaces found");
          return;
        }
    
        // Fetch Ad from ReneVerse
        const ad = await phaserHooks
          .useReneVerse()
          .getAd(adSurfaces.items[0].adSurfaceId);
      
        // Load Ad image
        if (ad.adId) {
          scene.load.image("dynamicAd", ad.url as string);
          
          scene.load.once("complete", () => {
          
            // Get Random Position
            const x = Phaser.Math.Between(100, 900);
            const y = Phaser.Math.Between(100, 600);
          
            //  `add.sprite` is a Phaser GameObjectFactory method and it returns a Sprite Game Object instance
            const adSurface = scene.add.sprite(x, y, "dynamicAd");

            // Set display size
            adSurface.setDisplaySize(300, 200);
            
            // Check if the Ad is visible or not
            const visibilityCheck = phaserHooks
                .useTracking()
                .checkAdFullVisibility(adSurface, scene);
                
            if (visibilityCheck.isFullyVisible) {
              // if Fully visible, calculate ad coverage
              const adCoverage = phaserHooks
                .useTracking()
                .calculateAdCoverage(adSurface, scene.cameras.main);
              
              console.log(adCoverage);
            } else {
              console.log("Ad is blocked");
            }
            
          };
          
          scene.load.start();
        }
      }
    }
  }
  
  // Creating a button to call the serveAd function
  return (
      <div>
        <PhaserGame ref={phaserRef} />
        <button onClick={checkVisibility}>
          Check Visibility
        </button>
      </div>
  );
}

export default App;

Returns

interface CalculateAdCoverage {
  isVisible: Boolean
  screenCoveragePercentage: Number
  visibleArea: Number
  totalArea: Number
}

calculateAdCoverage()

๐Ÿงฉ
๐ŸŒ
๐Ÿงช
๐Ÿ“Š
๐Ÿ”ญ
๐Ÿ“