How to Retrieve Child Ad Units and Their Metrics (Name, Sizes, and More)

75 views
Skip to first unread message

sai teja

unread,
Oct 9, 2024, 5:38:44 AM10/9/24
to Google Ad Manager API Forum
Hi,

I am trying to fetch all Ad Units and their metrics, including Ad Unit sizes, along with details like name, ID, and other relevant attributes.

The issue I’m encountering is:

1. When I use the following statement:

const statement = {
  query: "WHERE status = 'ACTIVE'"
};
const adUnits = await inventoryService.getAdUnitsByStatement({ filterStatement: statement });

I receive only parent-level Ad Units, as indicated by the hasChildren attribute being set to true.

Is there a way to retrieve child Ad Units and their associated metrics (name, Ad Unit sizes, and all other available attributes)?

Thanks,
Sai Teja

Ad Manager API Forum Advisor

unread,
Oct 9, 2024, 9:55:02 AM10/9/24
to sirangi...@gmail.com, google-doubleclick...@googlegroups.com
Hi Sai,

Thank you for contacting the Ad Manager API support team.

I understand that you are looking to retrieve child Ad Units via API. You can read child ad units by filtering on parentId in InventoryService.getAdUnitsByStatement method. There is example code in each of our client libraries for similar use cases. You may check here for a sample code in Java to retrieve all child ad units. Let us know if you have further queries.
 
This message is in relation to case "ref:!00D1U01174p.!5004Q02vGcyV:ref" (ADR-00271101)

Thanks,
 
Google Logo Ad Manager API Team

 

sai teja

unread,
Oct 9, 2024, 8:28:52 PM10/9/24
to Google Ad Manager API Forum
Hi ,
Thank you for response. actually I tried similar way by giving parentid filter but no luck. Is there any permissions issue from GAM console. since I am seeing result array containing 2 elements even though in console there are many ad unit elements.

Ad Manager API Forum Advisor

unread,
Oct 10, 2024, 4:55:07 AM10/10/24
to sirangi...@gmail.com, google-doubleclick...@googlegroups.com

Hi,

Please note that the parent id refers to the id of the parent ad unit. Filtering by parent id will retrieve the child ad units associated with that parent ad unit. To retrieve the full hierarchy of ad units, I recommend using the GetAdUnitHierarchy class.  

sai teja

unread,
Oct 10, 2024, 5:23:32 AM10/10/24
to Google Ad Manager API Forum
Hi,
I am receiving only the parent-level ad units, even though they have children. I applied a filter using the parentId, but the API is returning only partial information.

Response from API:
Ad Units: {
  totalResultSetSize: 2,
  startIndex: 0,        
  results: [
    {
      id: '141680780',
      hasChildren: true,
      name: 'ca-pub-1858262200976324: Astro Awani Network SDN BHD',
      description: '',
      targetWindow: 'TOP',
      status: 'ACTIVE',
      adUnitCode: '142680780',
      isInterstitial: false,
      isNative: false,
      isFluid: false,
      explicitlyTargeted: false,
      adSenseSettings: [Object],
      adSenseSettingsSource: 'UNKNOWN',
      lastModifiedDateTime: [Object],
      smartSizeMode: 'NONE',
      isSetTopBoxEnabled: false
    },
    {
      id: '141680900',
      parentId: '141680780',
      hasChildren: true,
      name: 'ca-pub-1858262200976324',
      description: 'Astro Awani Network SDN BHD',
      targetWindow: 'BLANK',
      status: 'ACTIVE',
      adUnitCode: 'ca-pub-1858262200976324',
      isInterstitial: false,
      isNative: false,
      isFluid: false,
      explicitlyTargeted: false,
      adSenseSettings: [Object],
      adSenseSettingsSource: 'DIRECTLY_SPECIFIED',
      lastModifiedDateTime: [Object],
      smartSizeMode: 'NONE',
      isSetTopBoxEnabled: false
    }
  ]
}

    const statement = {
      query: "WHERE status = 'ACTIVE' AND parentId = ' 141680780  '"
    };
 
    try {
      // Fetch ad units using the InventoryService

      const adUnits = await inventoryService.getAdUnitsByStatement({ filterStatement: statement });

NOTE: In GAM UI I can see 21831981819 this parent id but if I apply same filter in query not receiving any response from api. (anything related to service account permissions)

Thanks,
Sai Teja

Ad Manager API Forum Advisor

unread,
Oct 10, 2024, 9:28:22 AM10/10/24
to sirangi...@gmail.com, google-doubleclick...@googlegroups.com
Hi,

To assist you further, please provide us with complete SOAP request logs from API (SOAP logging must be enabled) and UserService.getCurrentUser (if unable, you may just provide the email address used to make API call.
Reply all
Reply to author
Forward
0 new messages