Overlay Ads
Ads allow you to monetize your overlay, this guide will cover various utilities we provide for managing them.
Before You Begin
Before you start setting up ads, make sure to contact the Overlayed team to discuss ads on your app. We’ll discuss ad positioning, ad units, and more. It’s crucial to start this process early so that we have time to setup the ads before you start using them.
Installation
To start with ads, you’ll need to install the @overlayed/ads
package:
Setup
Electron
On the electron side, for any BrowserWindow or RenderWindow you create and intend to show ads in, you’ll need to call:
Under the hood, registerWindow does two things:
- Sets up a link handler to open ads (and block malicious behavior!)
- Sets the user agent of all requests, which removes non-standard portions of the User Agent string which may trigger IVT (invalid traffic).
Preload
Within your electron app’s preload script, you’ll need to add the following import:
This will automatically execute code that facilitates Overlayed’s communication between the electron process and rendering process.
Render Process
Within the render process, theres a few more things to setup:
Initialization
Call the init
method when your HTML/JS first loads:
You can call this function as many times as you want, it will only execute once.
Adding the ads script
This script can be added in a variety of ways, for example:
With HTML (note the defer
attribute):
or with JavaScript:
Conclusion
That concludes the required setup for ads. Check out the configuration guide for more information on how to configure ad units, conditionally disable ads, and more.