Playable Ads made with Defold? For Facebook Ads?

With Defold you can produce very lightweight and well-optimised builds, both mobile and HTML5 from the same sources.

One idea tickles my brain for the past few days - is it possible to produce Playable Ads with Defold? Playable Ads have self-explaining name - the ad you can play, technically they are tiny HTML5 games. I heard such ads have very good conversions rates, so just imagine - you build iOS/Android game and with cost of pressing few buttons also build a Playable Ad for it, from the same sources. Sounds intriguing!

And not so long ago Facebook added the ability to upload playables to their system. Here are requirements, some important points:

  • Playable should not require mraid.js.
  • A single file for playable ad that contains all assets as part of that single HTML file and assets should be data URI compressed. (Javascript, CSS, images, sounds).
  • Playable asset size should be less than 2 MB.
  • No dynamic asset loading through external network is permitted.
  • Tips for combining into one file-encode image into base64 string, integrate js into index.html.
  • Playable HTML5 should not contain any JS redirect.
  • Playable should not make any HTTP request.

I’m not very familiar with Defold’s HTML5 tech stack, is there any requirement impossible to reach with Defold?

1 Like

A single file for playable ad that contains all assets as part of that single HTML file

Might be a little annoying to do manually if it is possible to do. Assuming it is you would probably also want to manually exclude WASM runtime.

1 Like

Manual job is not a big issue and any manual routines can be automated, the main question is if it’s possible at all.

Sure, it’s possible. You need to strip the engine from anything you don’t need, use texture compression and in general be very smart with the assets you use. And create a script that takes care of packaging the whole thing in a single .html file.

2 Likes

I’m back on this again. Ok, I see how to inline css and js into html-file, need to rework such pieces of code:

    function load_engine() {
		var engineJS = document.createElement('script');
		engineJS.type = 'text/javascript';
		if (Module['isWASMSupported']) {
		    engineJS.src = 'PlayableAd_wasm.js';
		} else {
		    engineJS.src = 'PlayableAd_asmjs.js';
		}
		document.head.appendChild(engineJS);
	}

That’s clear. But I don’t fully understand how Defold packs assets for HTML5, like images, fonts, sounds etc? Can’t find anything related in the docs. As I see there is archive folder:


and there is some JS code in index.html:

var extra_params = {
		archive_location_filter: function( path ) {
			return ("archive" + path + "");
		},
		
		splash_image: "splash_image.png",
		custom_heap_size: 268435456,
		disable_context_menu: true
	}

And I’m not 100% sure what it does… gives the reference to function returning path to file in archive… so, how can I inline this stuff into my resulting HTML? is it ever possible?

I’m not 100% sure of the process but I guess the code in dmloader.js needs to be modified to support loading from an embedded string.

We should add this as a bundle option.

2 Likes

Aha, I found where this path-function parameter is used in dmloader.js, later archive-files seem to be loaded via HTTPRequest. Code is not obfuscated or minified here, so I believe I can rewrite it to work as I need. I’ll put updates with the progress here, thanks!

3 Likes

Updated 2021-06-22: look at this topic.

Defold is too heavy for playable ad (in my opinion). PixiJS and any other lightweight JS engine are much better for this.

But I made the project as a demonstration that Defold can fit into one HTML file that less than 2mb.

Now you just need to do a playable ad and submit it to Facebook for approval :grinning:

If you succeed, I’ll make a complete asset out of this project.

10 Likes

Wow! It works! I’ve used it on “Linker” sample project, there is a resulting one-html-file http://anvil-games.com/defold/ad/playable_ad.html, it weights 2.4mb and canvas scaling need to be fixed, but in common script worked like a charm, thanks!

The only thing was to change “projectTitle” in “gulp file.js”

2 Likes

Update: I’ve missed two additional things:

  • add embed=“compressed” in html template (already fixed in repo by @aglitchman)
  • set app manifest in project settings

So after doing this the resulting html is 1.85mb! success! http://anvil-games.com/defold/ad/playable_ads.html

Now going to try it on my “real” game…

4 Likes

Great! Very nice work on this! What if you apply texture compression on the assets as well?

2 Likes

I’ve removed all sounds and music, throw away some sprites to reduce the size of atlas and came up with 2.4mb build size. Then played around with compression settings in texture_profile but this did not show a significant changes, but limiting the “Max Texture Size” did the trick (and as for 2mb ad the resulting quality is ok imo) - 1.99mb :grinning:

Here is the link: http://anvil-games.com/defold/ad/BouncyCatapult.html - it’s a full game currently, just without sounds. So as for ad there is still some assets to be stripped.

And Facebook Ads manager “eats” the resulting HTML:

10 Likes

I’ve updated the project:

  • Added info on how to use it in your game
  • Added comments in the html5 template
  • Added compression for archive data
  • Now 7-zip is used for deflate compression
  • And so on…
10 Likes

Hey-hey, first playable ad is approved and live!

You can check it in the Facebook Feed by this link: https://fb.me/1F1L1cv4wlv0TPM (seems to be working only in FB mobile app; and I don’t know for how long the link will be working)

But I’ve noticed some major FPS drops in it and probably right now the ad does not provide a good user experience because of lags. So I need to check this.

UPD: fixed lags by setting “Contact Impulse Limit” in physics settings

9 Likes

The first test with Playable Ad finished, so, just want to confirm, that it was not banned or reported by users or something else, and for sure it was successful for the game:

“Results” here are “App Installs”, on iOS, in USA. You can see, that Cost Per Install was TWICE lower in comparison with a simple video on the same audience and placements! Well, my best CPI with video ad was around $0.7, so if be more precise, the win from playable ad was “only” 50% and not 100%. But still - very promising and inspiring!

11 Likes

You should make a post for this as its own thread as I was trying to find it and could not on my own! (Thank you to @d954mas for linking)

Using something like this also has other benefits…

3 Likes

Just in case - this still works with Editor 1.2.167.
But few minor changes to the engine_template.html required, as it changed during past year.

2 Likes

HI! Still works? Can you share the engine_template.html?

Has anyone managed to make this work: GitHub - aglitchman/defold-playable-ads: A project with Gulp tasks to bundle the Defold game into one HTML file. ?

I’m running the following commands:

git clone https://github.com/aglitchman/defold-playable-ads.git
cd defold-playable-ads
npm install
gulp

Everything works, then I start a local http
python -s SimpleHTTPServer 8080

I get a blank page and an error console:

Uncaught TypeError: Cannot read property 'parentElement' of undefined
    at Object.removeProgress (dmloader.js:450)
    at Object._preloadAndCallMain (dmloader.js:824)
    at Array.onArchiveLoaded (dmloader.js:720)
    at Object.notifyListeners (dmloader.js:213)
    at Object.notifyArchiveLoaded (dmloader.js:235)
    at Object.onArchiveLoaded (dmloader.js:406)
    at Object.onFileLoaded (dmloader.js:398)
    at Object.onPieceLoaded (dmloader.js:346)
    at dmloader.js:318
    at request.onload (dmloader.js:91)

Anyone experience the same issue?

1 Like