JavaScript

Intrinsic ads Web SDK - vanilla JavaScript integration

178KB
Open

Guide

Complete guide for integrating intrinsic in-game ads with vanilla JavaScript, without a framework or game engine.

Table of Contents

  • Quick Start

  • Basic Integration

  • 2D Canvas Example

  • WebGL Example

  • Multiple Billboards

  • Advanced Features

  • Complete Examples


Quick Start

Minimal HTML Setup


Basic Integration

1. Initialize Anzu SDK

2. Create an Ad Billboard

3. Main Game Loop


2D Canvas Example

Complete 2D Billboard Implementation


WebGL Example

Complete WebGL Billboard Implementation


Multiple Billboards

Managing Multiple Ad Placements


Advanced Features

2. URI Schema Callbacks

3. Ad Statistics and Monitoring

4. Responsive Billboards

5. Performance Optimization


Complete Examples

Example 1: Simple Billboard Game


Best Practices

1. Initialization

  • ✅ Initialize AnzuCore once at app startup

  • ✅ Wait for initialization before creating ads

  • ✅ Use appropriate log level for production (2-4)

2. Performance

  • ✅ Call AnzuCore.update() every frame

  • ✅ Reuse canvas references, don't fetch every frame

  • ✅ Update visibility only when billboard position/size changes

  • ✅ Use requestAnimationFrame for smooth rendering

3. Visibility Tracking

  • ✅ Report accurate visibility (0-1 range)

  • ✅ Set viewability: 0 when billboard is off-screen

  • ✅ Use AnzuMath utilities for complex calculations

  • ✅ Update visibility every frame or when state changes

4. Memory Management

  • ✅ Call ad.destroy() when removing billboards

  • ✅ Remove event listeners when cleaning up

  • ✅ Clear references to destroyed ads

5. Click Handling

  • ✅ Implement proper hit testing

  • ✅ Only call interact() when ad is clickable

  • ✅ Verify billboard bounds before triggering interaction


Troubleshooting

Ad not displaying

Visibility not tracking

Click not working


Resources

  • Main Documentation: README.md

  • Migration Guide: MIGRATION_GUIDE.md

  • Three.js Guide: examples/three-js/README.md

  • Pixi.js Guide: examples/pixi-js/README.md

  • Phaser Guide: examples/phaser-js/README.md

  • Anzu Dashboard: https://dashboard.anzu.io/


Support

For issues or questions:

  1. Check the main README.md

  2. Review error messages in browser console

  3. Verify all SDK files are loaded in correct order

  4. Contact Playgama support with your app key

Last updated