What MRAID does
An HTML5 ad inside an app runs in a web view, cut off from the app around it. MRAID is the agreed set of JavaScript calls that bridges the two, so one ad can work in any SDK that supports the standard. For a playable ad it covers:
- Readiness: when the SDK has finished setting up and the ad can start.
- Visibility: whether the ad is actually on screen, so it doesn't run (or play sound) while hidden.
- Click-through:
mraid.open()opens the store or a URL the way the SDK expects, and lets the network count the click. - Size and orientation: the screen and ad size, and orientation preferences.
MRAID also defines calls for banners that expand or resize, which playables don't usually need.
What is mraid.js?
mraid.js is the script that creates the mraid object. The SDK supplies it, not you. The MRAID standard has the ad include <script src="mraid.js"></script> and the SDK answers that request with its own implementation. Some networks inject MRAID without the tag (Unity's docs don't ask for it). Never bundle your own copy, and never include the tag in a build for a network that doesn't use MRAID: several reject the file for it. Each network's page in our playable ad specs says what it expects.
The MRAID calls a playable ad uses
mraid.getState() | "loading" until the SDK is ready, then "default". "hidden" once the ad is closed. |
|---|---|
ready event | Fires once MRAID is usable. Don't call anything else before it. |
mraid.isViewable(), viewableChange | Whether the ad is on screen. Start the game when it's viewable, pause when it isn't. |
mraid.open(url) | Opens the App Store or Google Play page. The install button calls this. Liftoff wants it with no URL. |
mraid.getVersion() | The MRAID version the SDK supports, such as "2.0" or "3.0". |
stateChange event | Fires when the state changes, including to "hidden". |
exposureChange, audioVolumeChange | MRAID 3.0 only: how much of the ad is on screen, and the device volume. |
mraid.close() | Closes the ad. Playables usually leave closing to the network's own close button. |
A safe MRAID start for playable ads
Wait for MRAID, start only when the ad is on screen, and open the store only from a tap:
function start() { /* start the game */ }
function pause() { /* pause the game and mute it */ }
function onViewable(viewable) {
if (viewable) start(); else pause();
}
function onReady() {
mraid.addEventListener("viewableChange", onViewable);
if (mraid.isViewable()) start();
}
if (mraid.getState() === "loading") {
mraid.addEventListener("ready", onReady);
} else {
onReady();
}
installButton.addEventListener("click", function () {
mraid.open(STORE_URL);
});
This is the pattern Unity's best-practices guide uses, and it works on any MRAID network. Set STORE_URL to your App Store or Google Play link, or follow the network's own rule (Liftoff calls mraid.open() with no URL).
MRAID 1.0 vs 2.0 vs 3.0
| MRAID 1.0 | The core: getState, ready, stateChange, viewableChange, open, close, expand. |
|---|---|
| MRAID 2.0 | Adds resize, orientation properties, screen and max-size calls, supports() and sizeChange. The version most in-app SDKs and AppLovin use. |
| MRAID 3.0 | Adds exposureChange, audioVolumeChange and location, and deprecates useCustomClose. Unity uses 3.0. |
A playable that sticks to the calls in the table above works on 2.0 and 3.0 SDKs. Check mraid.getVersion() before using anything 3.0-only.
Which ad networks use MRAID
| Network | MRAID | Install call |
|---|---|---|
| AppLovin | 2.0 | mraid.open() |
| Unity Ads | 3.0 | mraid.open() |
| Liftoff (Vungle) | Yes | mraid.open() (no URL) |
| Chartboost | 1.0 + some 2.0 | mraid.open(url) |
| Adikteev | 1 | mraid.open(AK_CLICK_DESTINATION_URL) |
| Meta (Facebook) | No | FbPlayableAd.onCTAClick() |
| Google Ads | No | ExitApi.exit() |
| Moloco | No | FbPlayableAd.onCTAClick() |
| Mintegral | No | window.install() |
| TikTok | No | window.openAppStore() |
| Snapchat | No | ScPlayableAd.onCTAClick() |
How to test an MRAID ad
- On your desktop, with a small stand-in for the
mraidobject so the ad runs in a normal browser:
// Desktop testing only: a stand-in for the mraid object the SDK injects.
// Never ship this in a network build.
if (typeof window.mraid === "undefined") {
window.mraid = {
getState: function () { return "default"; },
getVersion: function () { return "3.0"; },
isViewable: function () { return true; },
addEventListener: function () {},
removeEventListener: function () {},
open: function (url) { console.log("mraid.open", url); },
close: function () { console.log("mraid.close"); }
};
}
- In the network's own test app, which runs the ad in the real SDK: AppLovin Playable Preview, or the Ad Testing app for Unity Ads.
- On real phones, checking that the ad waits until it's on screen, pauses when hidden, and that the install button opens the right store page.
Common MRAID mistakes
- Calling MRAID before
ready, which fails on SDKs that load it late. - Starting before the ad is viewable, so the game runs, and plays sound, while hidden.
- Using
window.openor a link instead ofmraid.open(), so the click isn't counted or the store doesn't open. - Shipping the desktop stub or your own
mraid.jsin a network build. - Leaving
mraid.jsin a build for Meta, Google, TikTok or another non-MRAID network, the most common reason a playable built for one network fails on another.
For a playable ad's full requirements beyond MRAID, see how to make a playable ad.
Common questions
What does MRAID stand for?
Mobile Rich Media Ad Interface Definitions. It's an IAB Tech Lab standard for how HTML5 ads communicate with the mobile app they run in.
What is mraid.js?
The script that creates the mraid object an HTML5 ad uses. The ad SDK supplies it; the ad references it, but you never ship your own copy.
Do I need to include the mraid.js script tag?
It depends on the network. The MRAID standard has the ad include it and the SDK supplies the file, but some networks inject MRAID without it, and non-MRAID networks such as Meta, TikTok and Moloco reject files that reference mraid.js.
Which MRAID version should a playable ad use?
Write to the calls MRAID 2.0 and 3.0 share: ready, getState, isViewable, viewableChange and open. AppLovin uses MRAID 2.0 and Unity uses 3.0.
Is MRAID required for playable ads?
Only on networks that use it: AppLovin, Unity, Liftoff, Chartboost and Adikteev. Meta, Google, Moloco, Mintegral, TikTok and Snapchat use their own APIs instead.
How do I test an MRAID ad?
Run it in a desktop browser with a small mraid stand-in, then in the network's own test app, such as AppLovin Playable Preview or the Ad Testing app for Unity Ads, and on real phones.