From 82a2cdda9481c949c996dd7a8222330bdde63c8e Mon Sep 17 00:00:00 2001 From: eproasim <79989325+eproasim@users.noreply.github.com> Date: Fri, 11 Nov 2022 14:08:28 -0500 Subject: [PATCH] Provide Compatibility for Google Playable Ads - Added new config property of adOrientation for purposes of defining Google's ad.orientation and ad.size meta tags - Added inclusion of Google ExitApi script at the top of
when google CTA is selected - Added ad.size and ad.orientation meta tags after ExitApi - Wrapped existing Snapchat CTA in a switch case based on "cta_option" value - Moved Snapchat CTA code to execute after engine has been compressed and patched - Changed "snapchat_cta" to "cta_option" accepting strings of "google" or "snapchat" - Changed config.template.json to reflect new available settings (adOrientation, cta_option) --- config.template.json | 3 ++- one-page.js | 38 ++++++++++++++++++++++++++++++-------- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/config.template.json b/config.template.json index f78664f..13b64ed 100644 --- a/config.template.json +++ b/config.template.json @@ -36,7 +36,8 @@ "external_url_prefix": "" }, "mraid_support": false, - "snapchat_cta": false, + "cta_option": false, + "adOrientation": false, "compress_engine": false } } diff --git a/one-page.js b/one-page.js index c54a466..4c3d3dc 100644 --- a/one-page.js +++ b/one-page.js @@ -333,14 +333,6 @@ function inlineAssets(projectPath) { fs.writeFileSync(location, contents); })(); - // Add Snapchat CTA code if needed - (function() { - if (config.one_page.snapchat_cta) { - console.log("↪️ Adding Snapchat Ad CTA code"); - addLibraryFile('snapchat-cta.js'); - } - })(); - // 9. Compress the engine file with lz4 (function() { if (config.one_page.compress_engine) { @@ -373,6 +365,36 @@ function inlineAssets(projectPath) { } })(); + // Add Snapchat/Google CTA code if needed + (function() { + switch(config.one_page.cta_option) { + case 'snapchat': + console.log("↪️ Adding Snapchat Ad CTA code"); + addLibraryFile('snapchat-cta.js'); + break; + case 'google': + console.log("↪️ Adding Google Ad CTA code"); + var allowedValues = ["portrait", "landscape", "portrait,landscape"]; + if(config.one_page.adOrientation && allowedValues.includes(config.one_page.adOrientation)) { + var orientation = config.one_page.adOrientation; + var size = (orientation == 'portrait') ? 'width=320,height=480' : 'width=480,height=320\n'; + var googlePrimaryAssets = ` \n `; + var exitApi = `\n`; + + indexContents = indexContents.replace( + '', + `\n ${exitApi + googlePrimaryAssets}` + ); + } + + else { + console.log('Error: Invalid Google Ad Orientation supplied'); + } + + break; + } + })(); + // 10. Replace references to all scripts in index.html with contents of those files. // 11. Replace playcanvas-stable.min.js in index.html with a base64 string of the file.