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.