skip to Main Content

Recently, I start getting this error from my google admanager ad unit. The error is for multisize mapping only for singlesize has no error.

[GPT] Invalid arguments: SizeMappingBuilder.addSize([356, 0], [[336,
280], [300, 250]]). All zero-area slot sizes were removed.

Following is my sizeMapping.

<script>
   googletag.cmd.push(function(){
    var adCode = { "top":'/21762728/top'};
    var adSize = {"top":[[336,280],[300,250]]};
    var TopAdMap = googletag.sizeMapping().addSize([356, 0], [[336,280],[300,250]]).addSize([0, 0], [300,250]).build();
    googletag.defineSlot(adCode.top, adSize.top, 'ad-top-slot').defineSizeMapping(TopAdMap).addService(googletag.pubads());
   });
</script>

3

Answers


  1. This is a JavaScript code that defines and sets up an ad slot using Google Ad Manager (GAM) API. Here’s a breakdown of what each line does:

    Defines a JavaScript variable called adCode which holds an object with a key-value pair of top and ‘/21762728/top’ respectively. This variable is used to specify the code for the ad slot.
    Defines a JavaScript variable called adSize which holds an object with a key-value pair of top and [[336,280],[300,250]] respectively. This variable is used to specify the sizes of the ad slot.
    Defines a JavaScript variable called TopAdMap which uses the googletag.sizeMapping() method to create a size mapping for the ad slot. The size mapping specifies which ad sizes should be displayed based on the width of the browser window. In this case, it maps ad sizes [[336,280],[300,250]] to a browser window width of at least 356px, and [[300,250]] to any smaller width. This variable is used to define the size mapping for the ad slot.
    Defines a Google Ad Manager ad slot using the googletag.defineSlot() method. The method takes three arguments – the ad code, the ad sizes, and the ID of the div element where the ad should be displayed. The adCode.top and adSize.top variables are used to specify the code and sizes of the ad slot respectively. The ID of the div element where the ad should be displayed is ‘ad-top-slot’. The defineSizeMapping() method is used to specify the size mapping for the ad slot, and the addService() method is used to add the ad slot to Google Ad Manager’s ad server.
    This JavaScript code sets up a responsive ad slot that can display two different ad sizes based on the width of the browser window. It also defines a size mapping for the ad slot to ensure that the appropriate ad sizes are displayed to users.

    Login or Signup to reply.
  2. According to the official documentation, your sizemapping code is correct. Here is what it says about this error (here) :

    The SizeMapping ($ARGS) provided to the specified GPT method ($METHODNAME) was invalid and automatically removed.

    I ran few test, and it looks like the origin of the error is the viewport’s height value of zero as the following does not throw any error :

    googletag.cmd.push(function(){
      var adCode = { "top":'/21762728/top'};
      var adCode = { "top":'/21762728/top'};
      var adSize = {"top":[[336,280],[300,250]]};
      var TopAdMap = googletag.sizeMapping().addSize([356, 1], [[336,280],[300,250]]).addSize([0, 0], [300,250]).build();
      googletag.defineSlot(adCode.top, adSize.top, 'ad-top-slot').defineSizeMapping(TopAdMap).addService(googletag.pubads());
    });
    

    Thing is you don’t want the user’s viewportHeight to impact your sizeMapping… So to avoid the thrown warning, here is a workaround : use the sizeMappingArray method instead of the sizeMappingBuilder :

    googletag.cmd.push(function(){
     var adCode = { "top":'/21762728/top'};
     var adSize = {"top":[[336,280],[300,250]]};      
     var TopAdMap = [
      [[356, 0], [[336,280],[300,250]]],
      [[0,0], [[300, 250]]]
     ]; 
     googletag.defineSlot(adCode.top, adSize.top, 'ad-top-slot').defineSizeMapping(TopAdMap).addService(googletag.pubads());
    
    Login or Signup to reply.
  3. I’ve seen the same error appear recently, when it was not problem before.

    Seems like an incorrect warning from GPT code.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search