Functionality
AdEngine supports additional ad units in the page, externally created through the googletag
object in GPT. These can be Ad Manager only units, a special campaign, etc., that are not directly set in AdEngine, but can be managed by AdEngine in pair with the other units.
To add these units to AdEngine, the adngin.cmd.setGoogletagAdSlots()
API function needs to be called as a part of AdEngine's functional configuration. Alternatively, it can be added using declarative configuration.
Syntax
function adngin.cmd.setGoogletagAdSlots(parameter, callback)
argument name | type | optional | value | description |
---|---|---|---|---|
parameter | Array<googletag.Slot> | Array holding the the | ||
callback | function | ✔️ |
| The callback function that is called with the function call result. |
CallbackResult
JSON object containing the function call result, which is passed to the provided callback function in order to execute some specific action upon the function call. The object structure is as follows:
CallbackResult = { message: "<string holding a debug log of the function call result>", data: <Array holding the slot element ids for the added units> }
The callback function will receive the above object as the first parameter and a boolean value translating the function call success status as the second parameter.
Description
Adding GPT ad-units to AdEngine will pass them to the Google Ad Server additionally to the AdEngine ad-units during the auction process. This improves page performance by using a single request to refresh all ads. It will also simplify the page code as there is no extra code required to manually call the ad server for the additional GPT ads.
This function uses the GPT slot objects directly, which implies that access to the created slots data is needed, which may not be the case at all times. Using setGoogletagAdSlotElementIds instead is recommended, as it decouples GPT structures from AdEngine by using the GPT div element id, which makes the page code simpler and improves performance by removing dependencies.
Scope
The function can be called after AdEngine loader is ready and the AdEngine queue is defined, see functional configuration for more details.
Example
Adding the googletag ad unit slots "outstream" and "sidebar" to AdEngine using the command queue and event system
Example GPT ad slots:
"outstream", placement "div-gpt-outstream"
"sidebar", placement "div-gpt-sidebar"
<script data-cfasync="false" type="text/javascript"> window.addEventListener("adnginLoaderReady", function() { googletag.cmd.push(function() { // Create the external ad-units var additionalAdSlots = []; additionalAdSlots.push(googletag.defineSlot('/12345678/outstream', [[1, 1]], 'div-gpt-outstream').addService(googletag.pubads())); additionalAdSlots.push(googletag.defineSlot('/12345678/sidebar', [[300, 250], [300, 600]], 'div-gpt-sidebar').addService(googletag.pubads())); // Add the external ad-units to AdEngine and start an auction adngin.queue.push(function(){ adngin.cmd.setGoogletagAdSlots(additionalAdSlots); adngin.cmd.startAuction(); }); }); }); </script> <script data-cfasync="false" async src="https://cdn.snigelweb.com/adengine/**site.domain**/loader.js" type="text/javascript"></script>