2

I need to pass a bunch of custom parameters into a Google DFP ad call. If the ad request is over 2,000 characters, some parameters passed into it get truncated. I would like to know how many characters the current call would take and manually truncate some of the values, instead of Google doing it for me. How can I get the length of the call?

doelleri
  • 19,232
  • 5
  • 61
  • 65
nuway
  • 2,324
  • 4
  • 27
  • 48

2 Answers2

1

I know this is a pretty old question, but I had this same problem along with several other questions about the URL a few months ago, so thought I would share.

Add the following to your code before the the display call.
What this does is:

/**
 * ##logUrl
 * Logs the ID of the ad and the length of its URL at render time.
 * @param {Event} e - GPT's slotRenderEnded event.
 */
logUrl = function(e) {
  var str = e.slot.getSlotId().getDomId() +
  ' URL length: ' + e.slot.getContentUrl().length;
  console.log(str);
}

googletag.cmd.push(function () {
  googletag.pubads().addEventListener('slotRenderEnded', logUrl);
});

Explanation

  • slotRenderEnded: This event fires just after the ad's Iframe is constructed.
  • slot: Returns everything google knows about this ad.
  • getSlotId: Returns the slot's long identifier from the googletag object.
  • getDomId: Returns the html ID of this ad's container.
  • getContentUrl: Returns the URL we want.
Richard Dillman
  • 334
  • 1
  • 9
0

A very simple way to do this with jQuery would be to do:

var dfpRequestLength = jQuery('script[src*="gampad/ads"]').attr('src').length;

This assumes a lot, but works on our DFP instance.

banderson623
  • 2,708
  • 2
  • 19
  • 13