-
-
Save supreez/e3c62c1c7f598d6b171a6d273f3d637d to your computer and use it in GitHub Desktop.
Setupad tag PHP based website ad unit insertion example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Insert <head> code in your header.php file or whatever file you have for <head> code output. Make sure to escape string if needed like double quotes in this example. */ | |
| <?php | |
| $head_code = " | |
| <script src=\"https://securepubads.g.doubleclick.net/tag/js/gpt.js\" async></script> | |
| <script> | |
| window.stpd = window.stpd || {}; | |
| stpd.que = stpd.que || []; | |
| window.googletag = window.googletag || {}; | |
| googletag.cmd = googletag.cmd || []; | |
| googletag.cmd.push (function () { | |
| if ( window.innerWidth >= 1024 ) { | |
| googletag.defineSlot('/123456789/example.com_billboard_desktop', [[970,250],[1000,300]], 'example_com_billboard').addService(googletag.pubads()); | |
| } else if ( window.innerWidth >= 768 ) { | |
| googletag.defineSlot('/123456789/example.com_billboard_tablet', [[728,90],[468,60]], 'example_com_billboard').addService(googletag.pubads()); | |
| } else { | |
| googletag.defineSlot('/123456789/example.com_billboard_mobile', [[300,250],[336,336]], 'example_com_billboard').addService(googletag.pubads()); | |
| } | |
| googletag.pubads().disableInitialLoad(); | |
| googletag.pubads().enableSingleRequest(); | |
| googletag.pubads().collapseEmptyDivs(); | |
| googletag.enableServices(); | |
| }); | |
| </script> | |
| <script async src=\"https://stpd.cloud/saas/1234\"></script> | |
| "; | |
| print($head_code); | |
| ?> | |
| /* Now the same process for the ad unit itself. Open your template file like single.php/page.php/etc. or page file wherever you wish to insert an ad unit. */ | |
| // Your page code here | |
| <?php | |
| $ad_unit = " | |
| <div id=\"example_com_billboard\"> | |
| <script> | |
| googletag.cmd.push(function() { googletag.display('example_com_billboard'); }); | |
| </script> | |
| </div> | |
| "; | |
| print($ad_unit); | |
| ?> | |
| // Continuation of your page code | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment