GAM Integration

This guide explains how to integrate n360ortb with Google Ad Manager (GAM) using Google Publisher Tag (GPT).

Overview

When integrating with GAM:

  1. Configure GPT with disableInitialLoad() to prevent ads from loading automatically

  2. Call n360ortb.fetchBids() to run the header bidding auction

  3. Call n360ortb.setDisplayBids() to set targeting on GPT slots

  4. Call googletag.pubads().refresh() to load ads with bid targeting

This allows Nexx360 bids to compete with your direct campaigns and Google AdX in the GAM unified auction.

Complete Example

<!DOCTYPE html>
<html>
<head>
  <title>n360ortb GAM Integration</title>

  <!-- Google Publisher Tag -->
  <script async src="https://securepubads.g.doubleclick.net/tag/js/gpt.js"></script>
  <script>
    window.googletag = window.googletag || { cmd: [] };

    googletag.cmd.push(function() {
      // Define your ad slots
      googletag.defineSlot(
        '/12345678/homepage-leaderboard',
        [[728, 90], [970, 250]],
        'div-leaderboard'
      ).addService(googletag.pubads());

      googletag.defineSlot(
        '/12345678/sidebar-mpu',
        [[300, 250], [300, 600]],
        'div-sidebar'
      ).addService(googletag.pubads());

      googletag.pubads().enableSingleRequest();
      googletag.enableServices();

      // IMPORTANT: Disable initial load to wait for header bidding
      googletag.pubads().disableInitialLoad();
    });
  </script>

  <!-- n360ortb loader -->
  <script>
  !function(){if(!window.n360ortb){window.n360ortb={init:function(){e("init",arguments)},fetchBids:function(){e("fetchBids",arguments)},setDisplayBids:function(){},targetingKeys:function(){return[]},que:[]};var n=document.createElement("script");n.async=!0,n.src="https://lib.nexx360.io/nexx360_ortb.js";var t=document.getElementsByTagName("script")[0];t.parentNode.insertBefore(n,t)}function e(n,t){window.n360ortb.que.push([n,t])}}();
  </script>

  <script>
    // Initialize n360ortb
    n360ortb.init({
      currency: 'EUR',
      gdpr: {
        cmpTimeout: 1000
      }
    });

    // Fetch bids
    n360ortb.fetchBids({
      slots: [
        {
          tagId: 'homepage-leaderboard-tag',
          divId: 'div-leaderboard',
          sizes: [[728, 90], [970, 250]]
        },
        {
          tagId: 'sidebar-mpu-tag',
          divId: 'div-sidebar',
          sizes: [[300, 250], [300, 600]]
        }
      ]
    }, function(bids) {
      // Set bid targeting on GPT slots
      n360ortb.setDisplayBids();

      // Refresh ads to trigger the GAM auction
      googletag.pubads().refresh();
    });
  </script>
</head>
<body>
  <h1>My Website</h1>

  <div id="div-leaderboard">
    <script>
      googletag.cmd.push(function() {
        googletag.display('div-leaderboard');
      });
    </script>
  </div>

  <p>Page content here...</p>

  <div id="div-sidebar">
    <script>
      googletag.cmd.push(function() {
        googletag.display('div-sidebar');
      });
    </script>
  </div>
</body>
</html>

Targeting Keys

When setDisplayBids() is called, the following targeting keys are set on each GPT slot:

Key
Description
Example Value

n360_bid

Unique bid identifier

"abc123def456"

n360_pb

Price bucket

"2.50"

n360_sz

Ad size

"300x250"

n360_crid

Creative ID

"creative_789"

n360_ssp

SSP identifier

"appnexus"

These keys are used by the line items in GAM to target winning bids and render the correct creative.

Key Configuration Points

1. Disable Initial Load

This is essential. It prevents GPT from loading ads before the header bidding auction completes.

2. Match divId to GPT Slot ID

The divId in your n360ortb slot configuration must match the element ID used in googletag.defineSlot():

3. Matching Sizes

The sizes in your n360ortb configuration should match those in your GPT slot definition:

Automatic Targeting Cleanup

The setDisplayBids() method automatically registers an event listener on slotRenderEnded to clear n360ortb targeting after each slot renders. This prevents stale targeting from affecting subsequent ad refreshes.

Refreshing Specific Slots

To refresh only specific slots:

Setup Requirements

Before using the GAM integration, you need to:

  1. Connect your GAM account - Grant Nexx360 access to create line items

  2. Set up GAM creatives - Configure the creative template to render bids

Next Steps

Last updated

Was this helpful?