Inline Passback

The Inline Passback implementation allows publishers to define and execute passback logic directly within the ad creative without requiring an externally hosted script.

This method is ideal for environments like Google Ad Manager (GAM) where the tag runs inside an ad slot and needs to seamlessly request fallback demand (e.g., AdX) if no ad is served by Mobkoi.

Unlike the hosted passback script (which is loaded via a URL), the inline version embeds the passback logic client-side inside the same creative and executes automatically when a failure condition is detected.

The following examples uses an inline function onNoAdCallback within the Tag to allow the execution of custom code on the page, the following snippet executes a GAM passback.

<script>
  (function (cs) {
    window.onNoAdCallback = function() {
      
      var passbackContent = `
        <div id="passback">
          <script>
           alert("passback fired")
          <\/script>
        <\/div>`;
      document.write(passbackContent);
    }

    var options = {
      passbackFunc: 'onNoAdCallback'
    };

    /* DO NOT TOUCH ANYTHING BELOW */
    cs.parentNode.insertBefore(
      Object.assign(document.createElement('script'), {
        type: 'application/javascript',
        async: 1,
        src:
          `https://tag.mobkoi.com/tag/boot/PLACEMENT_ID?po=` +
          encodeURIComponent(JSON.stringify(options)) +
          '&cb=' +
          Math.random() +
          '&st=' +
          Date.now(),
      }),
      cs,
    );
  })(document.currentScript);
</script>

Enabling Passback

To activate the passback feature, configure the tag with a passback option specifying the script URL. You may also enable passbackTest mode for development.

Last updated