Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

feat(playable): ship the networks we could verify, each citing its own source

esenginec759e42ad2df
diff --git a/desktop/electron/exportPlayable.ts b/desktop/electron/exportPlayable.ts
index 9098440b3..7d74dabed 100644
--- a/desktop/electron/exportPlayable.ts
+++ b/desktop/electron/exportPlayable.ts
@@ -313,6 +313,7 @@ export async function exportPlayable(opts: {
+ `${(adProfile.maxBytes / 1024 / 1024).toFixed(1)}MB limit for ${adProfile.label} `
+ `(${adProfile.limitNote}).`);
}
+ if (adProfile.deliveryNote) warnings.push(adProfile.deliveryNote);
return { ok: errors.length === 0, platform: 'playable', outDir: absOut, included: cook.included.length, bytes, warnings, errors };
}
diff --git a/desktop/electron/playableAdProfile.ts b/desktop/electron/playableAdProfile.ts
index d3500a527..3e3e09a32 100644
--- a/desktop/electron/playableAdProfile.ts
+++ b/desktop/electron/playableAdProfile.ts
@@ -36,6 +36,13 @@ export interface PlayableAdProfile {
/** Where {@link maxBytes} comes from, quoted in the warning so a developer can
* check it against the network's current docs rather than trusting us. */
readonly limitNote: string;
+ /**
+ * Something the developer must still do by hand before this package can be
+ * uploaded — Google takes a ZIP, and the export writes a bare index.html.
+ * Reported as a warning, because an export that looks finished but is not
+ * uploadable is worse than one that says so.
+ */
+ readonly deliveryNote?: string;
/** Markup for `<head>`: an orientation meta tag, the network's own SDK script. */
emitHead?(ctx: PlayableAdContext): string;
/**
@@ -76,10 +83,78 @@ export const metaPlayableProfile: PlayableAdProfile = {
+ '}};',
};
-/** The networks the editor ships, by id. */
+/**
+ * Google App campaigns. Two things are unlike every other network: the store exit
+ * goes through Google's own hosted script — which the docs require as a LITERAL
+ * `<script>` in `<head>`, not one added by JS — and the upload is a ZIP, which this
+ * export does not produce, so it says so rather than looking finished.
+ * @see https://support.google.com/google-ads/answer/9981650
+ */
+export const googlePlayableProfile: PlayableAdProfile = {
+ id: 'google',
+ label: 'Google Ads (App campaigns)',
+ maxBytes: 5 * 1024 * 1024,
+ limitNote: 'Google accepts a .ZIP up to 5MB',
+ deliveryNote: 'Google uploads a .ZIP — compress this index.html before uploading.',
+ // The orientation meta tag is required alongside the exit API.
+ emitHead: (ctx) => '<script src="https://tpc.googlesyndication.com/pagead/gadgets/html5/api/exitapi.js"></script>\n'
+ + ` <meta name="ad.orientation" content="${ctx.orientation}">`,
+ emitBridge: () => 'window.__ESTELLA_PLAYABLE__={cta:function(){'
+ + 'if(typeof ExitApi!=="undefined"&&ExitApi.exit)ExitApi.exit();'
+ + '}};',
+};
+
+/**
+ * The MRAID networks. `mraid` is injected by the host webview, so nothing goes in
+ * `<head>` — and `mraid.open()` is what the spec requires for a click-through
+ * (an `<a href>` or `window.open` breaks click tracking, and some exchanges reject
+ * it outright).
+ *
+ * Note for the game: MRAID hosts expect the playable to wait for the
+ * `viewableChange` event before it starts, which is the game's call to make.
+ * @see https://mraid.io/
+ */
+const mraidBridge = (): string => 'window.__ESTELLA_PLAYABLE__={cta:function(){'
+ + 'if(typeof mraid!=="undefined"&&mraid.open)mraid.open();'
+ + '}};';
+
+export const mraidPlayableProfile: PlayableAdProfile = {
+ id: 'mraid',
+ label: 'MRAID network (generic)',
+ maxBytes: 5 * 1024 * 1024,
+ limitNote: 'MRAID networks commonly cap a single-file playable at 5MB — check yours',
+ emitBridge: mraidBridge,
+};
+
+/** @see https://docs.unity.com/acquire/en-us/manual/playable-ads-specifications */
+export const unityPlayableProfile: PlayableAdProfile = {
+ id: 'unity',
+ label: 'Unity Ads',
+ maxBytes: 5 * 1024 * 1024,
+ limitNote: 'Unity requires a single inlined index.html under 5MB',
+ emitBridge: mraidBridge,
+};
+
+/** AppLovin additionally forbids EXTERNAL resources, which a single-file playable
+ * satisfies by construction — every asset here is already inlined.
+ * @see https://support.applovin.com/en/growth/promoting-your-apps/welcome-to-applovin/creative-specs-and-guidelines */
+export const applovinPlayableProfile: PlayableAdProfile = {
+ id: 'applovin',
+ label: 'AppLovin',
+ maxBytes: 5 * 1024 * 1024,
+ limitNote: 'AppLovin caps a single HTML file at 5MB, with every resource embedded',
+ emitBridge: mraidBridge,
+};
+
+/** The networks the editor ships, by id. A network absent here is not unsupported:
+ * a project defines its own with the same contract (`kind: 'playable'`). */
export const BUILTIN_PLAYABLE_PROFILES: readonly PlayableAdProfile[] = [
genericPlayableProfile,
metaPlayableProfile,
+ googlePlayableProfile,
+ mraidPlayableProfile,
+ unityPlayableProfile,
+ applovinPlayableProfile,
];
export function builtinPlayableProfile(id: string | undefined): PlayableAdProfile | null {
diff --git a/desktop/tests/platform-catalog.test.ts b/desktop/tests/platform-catalog.test.ts
index 9720a6d07..ad9d02878 100644
--- a/desktop/tests/platform-catalog.test.ts
+++ b/desktop/tests/platform-catalog.test.ts
@@ -304,7 +304,8 @@ describe('playable ad networks', () => {
maxBytes: 3145728, limitNote: 'Acme docs say 3MB',
};`);
const rows = await listPlayableNetworks(root);
- expect(rows.filter((r) => r.source === 'builtin').map((r) => r.id)).toEqual(['generic', 'meta']);
+ expect(rows.filter((r) => r.source === 'builtin').map((r) => r.id))
+ .toEqual(['generic', 'meta', 'google', 'mraid', 'unity', 'applovin']);
expect(rows.find((r) => r.id === 'acme-ads')).toMatchObject({ label: 'Acme Ads', source: 'project' });
});
@@ -324,6 +325,21 @@ describe('playable ad networks', () => {
it('resolves the built-ins, and nothing for an unknown id', async () => {
expect((await loadPlayableProfile(root, 'meta'))!.emitBridge!({ title: 'T', orientation: 'landscape' }))
.toContain('FbPlayableAd.onCTAClick');
+ // Google's exit API must be a LITERAL head script (its docs forbid injecting it
+ // from JS), and its upload is a ZIP this export does not produce — hence the note.
+ const google = (await loadPlayableProfile(root, 'google'))!;
+ expect(google.emitHead!({ title: 'T', orientation: 'portrait' }))
+ .toContain('<script src="https://tpc.googlesyndication.com/pagead/gadgets/html5/api/exitapi.js"></script>');
+ expect(google.emitHead!({ title: 'T', orientation: 'portrait' })).toContain('content="portrait"');
+ expect(google.emitBridge!({ title: 'T', orientation: 'portrait' })).toContain('ExitApi.exit');
+ expect(google.deliveryNote).toMatch(/ZIP/);
+ // The MRAID family clicks through with mraid.open() and needs nothing in head —
+ // the host webview injects mraid itself.
+ for (const id of ['mraid', 'unity', 'applovin']) {
+ const p = (await loadPlayableProfile(root, id))!;
+ expect(p.emitBridge!({ title: 'T', orientation: 'landscape' })).toContain('mraid.open()');
+ expect(p.emitHead).toBeUndefined();
+ }
// No selection ⇒ generic, so a project that never chose still exports.
expect((await loadPlayableProfile(root, undefined))!.id).toBe('generic');
// An id naming nothing is NOT silently generic — the caller reports it.