Event-based ad requests

You can request ads based on events using the Google Publisher Tag library. In the example below, a new ad is not requested or rendered until the user clicks a button.

<!doctype html>
    <meta charset="utf-8">
    <title>Event-based ad requests example</title>
    <script async src="https://securepubads.g.doubleclick.net/tag/js/gpt.js"></script>
      window.googletag = window.googletag || {cmd: []};

     googletag.cmd.push(function() {
        googletag.defineSlot('/6355419/Travel',[728, 90], 'div-for-slot')
            .setTargeting('test', 'event')
    <div id="div-for-slot" style="width: 300px; height: 250px;">
        googletag.cmd.push(function() {
          // This will only register the slot.
          // Ad will be fetched only when refresh is called.
    <button onclick="googletag.cmd.push(function() { googletag.pubads().refresh(); });">
      Show/Refresh Ad