Ads
Stay organized with collections
Save and categorize content based on your preferences.
Add an expanded text ad
function
addExpandedTextAd
(
adGroupName
,
campaignName
)
{
const
campaignIterator
=
AdsApp
.
campaigns
()
.
withCondition
(
`
campaign
.
name
=
"${campaignName}"
`
)
.
get
();
if
(
!
campaignIterator
.
hasNext
()){
throw
new
error
(
`
No
campaign
found
with
name
:
"${campaignname}"
`
);
}
const
adGroupIterator
=
AdsApp
.
adGroups
()
.
withCondition
(
`
ad_group
.
name
=
"${adGroupName}"
`
)
.
get
();
if
(
!
adGroupIterator
.
hasNext
()){
throw
new
error
(
`
No
ad
group
found
with
name
:
"${adGroupName}"
`
);
}
const
adGroup
=
adGroupIterator
.
next
();
adGroup
.
newAd
()
.
expandedTextAdBuilder
()
.
withHeadlinePart1
(
'First headline of ad'
)
.
withHeadlinePart2
(
'Second headline of ad'
)
.
withHeadlinePart3
(
'Third headline of ad'
)
.
withDescription
(
'First Ad description'
)
.
withDescription2
(
'Second Ad description'
)
.
withPath1
(
'path1'
)
.
withPath2
(
'path2'
)
.
withFinalUrl
(
'http://www.example.com'
)
.
build
();
//
ExpandedTextAdBuilder
has
additional
options
.
//
For
more
details
,
see
//
https
:
//
developers
.
google
.
com
/
google
-
ads
/
scripts
/
docs
/
reference
/
adsapp
/
adsapp_expandedtextadbuilder
}
Add an image ad
function
addImageAd
(
adGroupName
,
imageUrl
,
imageName
)
{
const
imageBlob
=
UrlFetchApp
.
fetch
(
imageUrl
)
.
getBlob
();
const
mediaOperation
=
AdsApp
.
adMedia
()
.
newImageBuilder
()
.
withName
(
`
$
{
imageName
}
`
)
.
withData
(
imageBlob
)
.
build
();
const
image
=
mediaOperation
.
getResult
();
if
(
!
image
.
isSuccessful
())
{
throw
new
Error
(
`
Media
could
not
be
created
from
url
:
"${imageUrl}"
`
)
}
const
adGroupIterator
=
AdsApp
.
adGroups
()
.
withCondition
(
`
ad_group
.
name
=
"${adGroupName}"
`
)
.
get
();
if
(
!
adGroupIterator
.
hasNext
())
{
throw
new
Error
(
`
No
ad
group
found
with
name
:
"${adGroupName}"
`
);
}
if
(
adGroupIterator
.
totalNumEntities
()
>
1
)
{
console
.
warn
(
`
Multiple
ad
groups
named
"${name}"
found
.
Using
the
one
from
campaign
"${adGroup.getCampaign().getName()}"
.
`
);
}
const
mediaIterator
=
AdsApp
.
adMedia
()
.
media
()
.
withCondition
(
`
media_file
.
name
=
"${imageName}"
`
)
.
get
();
if
(
!
mediaIterator
.
hasNext
())
{
throw
new
Error
(
`
No
media
found
with
name
:
"${imageName}"
`
);
}
const
adGroup
=
adGroupIterator
.
next
();
const
image2
=
mediaIterator
.
next
();
adGroup
.
newAd
()
.
imageAdBuilder
()
.
withName
(
'Ad name'
)
.
withImage
(
image2
)
.
withDisplayUrl
(
'http://www.example.com'
)
.
withFinalUrl
(
'http://www.example.com'
)
.
build
();
//
ImageAdBuilder
has
additional
options
.
//
For
more
details
,
see
//
https
:
//
developers
.
google
.
com
/
google
-
ads
/
scripts
/
docs
/
reference
/
adsapp
/
adsapp_imageadbuilder
}
Add a responsive display ad
//
You
create
responsive
display
ads
in
two
steps
:
//
1.
Create
or
retrieve
assets
(
marketing
images
,
square
marketing
images
,
//
optional
logos
,
optional
landscape
logos
,
and
optional
YouTube
videos
)
//
2.
Create
the
ad
.
//
//
The
following
function
assumes
you
have
not
already
created
named
assets
.
function
addResponsiveDisplayAd
(
campaignName
,
adGroupName
)
{
//
If
you
have
multiple
adGroups
with
the
same
name
,
this
snippet
will
//
pick
an
arbitrary
matching
ad
group
each
time
.
In
such
cases
,
just
//
filter
on
the
campaign
name
as
well
:
//
//
AdsApp
.
adGroups
()
//
.
withCondition
(
`
ad_group
.
name
=
"${adGroupName}"
`
)
//
.
withCondition
(
`
campaign
.
name
=
"${campaignName}"
`
)
const
adGroupIterator
=
AdsApp
.
adGroups
()
.
withCondition
(
`
ad_group
.
name
=
"${adGroupName}"
`
)
.
get
();
if
(
!
adGroupIterator
.
hasNext
())
{
throw
new
Error
(
`
No
ad
group
found
with
name
:
$
{
adGroupName
}
`
);
}
//
If
you
have
already
created
named
image
assets
,
select
them
like
this
:
//
//
const
marketingImages
=
[];
//
const
marketingImageIterator
=
AdsApp
.
adAssets
()
//
.
assets
()
//
.
withCondition
(
`
ad_group_ad
.
ad
.
name
IN
(
"INSERT_FIRST_ASSET_NAME_HERE"
,
//
"INSERT_SECOND_ASSET_NAME_HERE"
)
`
)
//
.
get
();
//
while
(
marketingImageIterator
.
hasNext
())
{
//
marketingImages
.
push
(
marketingImageIterator
.
next
());
//
}
const
adGroup
=
adGroupIterator
.
next
();
const
adGroupBuilder
=
adGroup
.
newAd
()
.
responsiveDisplayAdBuilder
()
.
withBusinessName
(
'Your business name'
)
.
withFinalUrl
(
'http://www.example.com'
)
.
withHeadlines
([
'First headline'
,
'Second headline'
])
.
withLongHeadline
(
'Long Headline'
)
.
withDescriptions
(
[
'First description'
,
'Second description'
,
'Third description'
]);
//
If
you
selected
assets
with
a
snippet
as
shown
above
,
then
provide
those
//
assets
here
like
this
:
//
//
adGroupBuilder
=
adGroupBuilder
.
withMarketingImages
(
marketingImages
);
adGroupBuilder
.
addMarketingImage
(
buildImageAsset
(
"rectangular image asset"
,
"https://goo.gl/3b9Wfh"
))
.
addSquareMarketingImage
(
buildImageAsset
(
"square image asset"
,
"https://goo.gl/mtt54n"
))
.
build
();
//
ResponsiveDisplayAdBuilder
has
additional
options
.
//
For
more
details
,
see
//
https
:
//
developers
.
google
.
com
/
google
-
ads
/
scripts
/
docs
/
reference
/
adsapp
/
adsapp_responsivedisplayadbuilder
}
function
buildImageAsset
(
assetName
,
imageUrl
)
{
const
imageBlob
=
UrlFetchApp
.
fetch
(
imageUrl
)
.
getBlob
();
return
AdsApp
.
adAssets
()
.
newImageAssetBuilder
()
.
withData
(
imageBlob
)
.
withName
(
assetName
)
.
build
()
.
getResult
();
}
Pause ad in an ad group
function
pauseAdInAdGroup
(
adGroupName
)
{
const
adGroupIterator
=
AdsApp
.
adGroups
()
.
withCondition
(
`
ad_group
.
name
=
"${adGroupName}"
`
)
.
get
();
if
(
!
adGroupIterator
.
hasNext
())
{
throw
new
Error
(
`
No
ad
group
found
with
name
:
"${adGroupName}"
`
);
}
const
adGroup
=
adGroupIterator
.
next
();
const
adsIterator
=
adGroup
.
ads
()
.
get
();
if
(
!
adsIterator
.
hasNext
())
{
throw
new
Error
(
`
No
ads
found
in
ad
group
:
"${adGroupName}"
`
);
}
const
ad
=
adsIterator
.
next
();
ad
.
pause
();
}
Get expanded text ads iterator in an ad group
function
getExpandedTextAdsIteratorInAdGroup
(
adGroupName
)
{
const
adGroupIterator
=
AdsApp
.
adGroups
()
.
withCondition
(
`
ad_group
.
name
=
"${adGroupName}"
`
)
.
get
();
if
(
!
adGroupIterator
.
hasNext
())
{
throw
new
Error
(
`
No
ad
group
found
with
name
:
"${adGroupName}"
`
);
}
const
adGroup
=
adGroupIterator
.
next
();
//
You
can
filter
for
ads
of
a
particular
type
,
using
the
AdType
selector
.
//
See
https
:
//
developers
.
google
.
com
/
google
-
ads
/
scripts
/
docs
/
reference
/
adsapp
/
adsapp_ad
#getType_0
//
for
possible
values
.
const
expandedTextAdsIterator
=
adGroup
.
ads
()
.
withCondition
(
`
ad_group_ad
.
ad
.
type
=
"EXPANDED_TEXT_AD"
`
)
.
get
();
if
(
!
expandedTextAdsIterator
.
hasNext
())
{
throw
new
Error
(
`
No
expanded
text
ads
found
in
ad
group
:
"${adGroupName}"
`
);
}
return
expandedTextAdsIterator
;
}
Get text ads iterator in an ad group
function
getTextAdsIteratorInAdGroup
(
adGroupName
)
{
const
adGroupIterator
=
AdsApp
.
adGroups
()
.
withCondition
(
`
ad_group
.
name
=
"${adGroupName}"
`
)
.
get
();
if
(
!
adGroupIterator
.
hasNext
())
{
throw
new
Error
(
`
No
ad
group
found
with
name
:
"${adGroupName}"
`
);
}
const
adGroup
=
adGroupIterator
.
next
();
//
You
can
filter
for
ads
of
a
particular
type
,
using
the
AdType
selector
.
//
See
https
:
//
developers
.
google
.
com
/
google
-
ads
/
scripts
/
docs
/
reference
/
adsapp
/
adsapp_ad
#getType_0
//
for
possible
values
.
const
textAdsIterator
=
adGroup
.
ads
()
.
withCondition
(
`
ad_group_ad
.
ad
.
type
=
"TEXT_AD"
`
)
.
get
();
if
(
!
textAdsIterator
.
hasNext
())
{
throw
new
Error
(
`
No
text
ads
found
in
ad
group
:
"${adGroupName}"
`
);
}
return
textAdsIterator
;
}
Get stats for ads in an ad group
function
getAdGroupAdStats
(
adGroupName
)
{
const
adGroupIterator
=
AdsApp
.
adGroups
()
.
withCondition
(
`
ad_group
.
name
=
"${adGroupName}"
`
)
.
get
();
if
(
!
adGroupIterator
.
hasNext
())
{
throw
new
Error
(
`
No
ad
group
found
with
name
:
"${adGroupName}"
`
);
}
const
adGroup
=
adGroupIterator
.
next
();
//
If
you
want
to
restrict
your
search
to
some
ads
only
,
then
you
could
//
apply
a
label
and
retrieve
ads
as
//
//
const
label
=
AdsApp
.
labels
()
//
.
withCondition
(
`
ad_group_ad_label
.
name
=
"INSERT_LABEL_NAME_HERE"
`
)
//
.
get
()
//
.
next
();
//
const
adsIterator
=
label
.
ads
()
.
get
();
const
adsIterator
=
adGroup
.
ads
()
.
get
();
if
(
!
adsIterator
.
hasNext
())
{
throw
new
Error
(
`
No
ads
found
in
ad
group
:
"${adGroupName}"
`
);
}
const
ad
=
adsIterator
.
next
();
//
You
can
also
request
reports
for
pre
-
defined
date
ranges
.
See
//
https
:
//
developers
.
google
.
com
/
google
-
ads
/
api
/
docs
/
query
/
date
-
ranges
//
DateRangeLiteral
section
for
possible
values
.
const
stats
=
ad
.
getStatsFor
(
'LAST_MONTH'
);
console
.
log
(
`
$
{
adGroup
.
getName
()},
$
{
stats
.
getClicks
()},
$
{
stats
.
getImpressions
()}
`
);
}
Get responsive display ads in an ad group
function
getResponsiveDisplayAdIteratorInAdGroup
(
adGroupName
)
{
const
adGroupIterator
=
AdsApp
.
adGroups
()
.
withCondition
(
`
ad_group
.
name
=
"${adGroupName}"
`
)
.
get
();
if
(
!
adGroupIterator
.
hasNext
())
{
throw
new
Error
(
`
No
ad
group
found
with
name
:
$
{
adGroupName
}
`
);
}
const
adGroup
=
adGroupIterator
.
next
();
const
responsiveDisplayAdsIterator
=
adGroup
.
ads
()
.
withCondition
(
`
ad_group_ad
.
ad
.
type
IN
(
"RESPONSIVE_DISPLAY_AD"
,
"LEGACY_RESPONSIVE_DISPLAY_AD"
)
`
)
.
get
();
if
(
!
responsiveDisplayAdsIterator
.
hasNext
())
{
throw
new
Error
(
`
No
Responsive
Display
ads
found
in
ad
group
:
"${adGroupName}"
`
);
}
return
responsiveDisplayAdsIterator
;
}
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License
, and code samples are licensed under the Apache 2.0 License
. For details, see the Google Developers Site Policies
. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-20 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-20 UTC."],[[["\u003cp\u003eThe provided Google Ads scripts demonstrate how to manage ads, including creating various ad types like Expanded Text Ads, Image Ads, and Responsive Display Ads within specified ad groups and campaigns.\u003c/p\u003e\n"],["\u003cp\u003eThe scripts enable functionalities such as pausing ads, retrieving iterators for different ad types (Expanded Text Ads, Text Ads, Responsive Display Ads), and fetching performance statistics for ads within a given ad group.\u003c/p\u003e\n"],["\u003cp\u003eThe scripts use error handling to ensure smooth execution and provide informative messages when issues like missing campaigns, ad groups, or ads are encountered.\u003c/p\u003e\n"],["\u003cp\u003eThe scripts leverage Google Ads API functionalities for managing ad assets, building ads with specific attributes, and accessing performance data for reporting purposes.\u003c/p\u003e\n"],["\u003cp\u003eThe scripts are designed to be modular and reusable, allowing for customization and integration into larger Google Ads management workflows.\u003c/p\u003e\n"]]],[],null,["# Ads\n\nAdd an expanded text ad\n-----------------------\n\n```gdscript\nfunction addExpandedTextAd(adGroupName,campaignName) {\n const campaignIterator = AdsApp.campaigns()\n .withCondition(`campaign.name = \"${campaignName}\"`)\n .get();\n if (!campaignIterator.hasNext()){\n throw new error (`No campaign found with name: \"${campaignname}\"`);\n }\n\n const adGroupIterator = AdsApp.adGroups()\n .withCondition(`ad_group.name = \"${adGroupName}\"`)\n .get();\n if (!adGroupIterator.hasNext()){\n throw new error (`No ad group found with name: \"${adGroupName}\"`);\n }\n\n const adGroup = adGroupIterator.next();\n adGroup.newAd().expandedTextAdBuilder()\n .withHeadlinePart1('First headline of ad')\n .withHeadlinePart2('Second headline of ad')\n .withHeadlinePart3('Third headline of ad')\n .withDescription('First Ad description')\n .withDescription2('Second Ad description')\n .withPath1('path1')\n .withPath2('path2')\n .withFinalUrl('http://www.example.com')\n .build();\n // ExpandedTextAdBuilder has additional options.\n // For more details, see\n // https://developers.google.com/google-ads/scripts/docs/reference/adsapp/adsapp_expandedtextadbuilder\n}\n```\n\nAdd an image ad\n---------------\n\n```gdscript\nfunction addImageAd(adGroupName,imageUrl,imageName) {\n const imageBlob = UrlFetchApp.fetch(imageUrl).getBlob();\n const mediaOperation = AdsApp.adMedia().newImageBuilder()\n .withName(`${imageName}`)\n .withData(imageBlob)\n .build();\n const image = mediaOperation.getResult();\n if (!image.isSuccessful()) {\n throw new Error(`Media could not be created from url: \"${imageUrl}\"`)\n }\n\n const adGroupIterator = AdsApp.adGroups()\n .withCondition(`ad_group.name = \"${adGroupName}\"`)\n .get();\n if (!adGroupIterator.hasNext()) {\n throw new Error(`No ad group found with name: \"${adGroupName}\"`);\n }\n if (adGroupIterator.totalNumEntities() \u003e 1) {\n console.warn(`Multiple ad groups named \"${name}\" found. Using the one\n from campaign \"${adGroup.getCampaign().getName()}\".`);\n }\n\n const mediaIterator = AdsApp.adMedia().media()\n .withCondition(`media_file.name = \"${imageName}\"`)\n .get();\n if (!mediaIterator.hasNext()) {\n throw new Error(`No media found with name: \"${imageName}\"`);\n }\n\n const adGroup = adGroupIterator.next();\n const image2 = mediaIterator.next();\n adGroup.newAd().imageAdBuilder()\n .withName('Ad name')\n .withImage(image2)\n .withDisplayUrl('http://www.example.com')\n .withFinalUrl('http://www.example.com')\n .build();\n // ImageAdBuilder has additional options.\n // For more details, see\n // https://developers.google.com/google-ads/scripts/docs/reference/adsapp/adsapp_imageadbuilder\n}\n```\n\nAdd a responsive display ad\n---------------------------\n\n```gdscript\n// You create responsive display ads in two steps:\n// 1. Create or retrieve assets (marketing images, square marketing images,\n// optional logos, optional landscape logos, and optional YouTube videos)\n// 2. Create the ad.\n//\n// The following function assumes you have not already created named assets.\nfunction addResponsiveDisplayAd(campaignName,adGroupName) {\n // If you have multiple adGroups with the same name, this snippet will\n // pick an arbitrary matching ad group each time. In such cases, just\n // filter on the campaign name as well:\n //\n // AdsApp.adGroups()\n // .withCondition(`ad_group.name = \"${adGroupName}\"`)\n // .withCondition(`campaign.name = \"${campaignName}\"`)\n const adGroupIterator = AdsApp.adGroups()\n .withCondition(`ad_group.name = \"${adGroupName}\"`)\n .get();\n if (!adGroupIterator.hasNext()) {\n throw new Error(`No ad group found with name: ${adGroupName}`);\n }\n\n // If you have already created named image assets, select them like this:\n //\n // const marketingImages = [];\n // const marketingImageIterator = AdsApp.adAssets()\n // .assets()\n // .withCondition(`ad_group_ad.ad.name IN (\"INSERT_FIRST_ASSET_NAME_HERE\",\n // \"INSERT_SECOND_ASSET_NAME_HERE\")`)\n // .get();\n // while (marketingImageIterator.hasNext()) {\n // marketingImages.push(marketingImageIterator.next());\n // }\n\n const adGroup = adGroupIterator.next();\n const adGroupBuilder = adGroup.newAd()\n .responsiveDisplayAdBuilder()\n .withBusinessName('Your business name')\n .withFinalUrl('http://www.example.com')\n .withHeadlines(['First headline', 'Second headline'])\n .withLongHeadline('Long Headline')\n .withDescriptions(\n ['First description', 'Second description', 'Third description']);\n\n // If you selected assets with a snippet as shown above, then provide those\n // assets here like this:\n //\n // adGroupBuilder = adGroupBuilder.withMarketingImages(marketingImages);\n\n adGroupBuilder\n .addMarketingImage(\n buildImageAsset(\"rectangular image asset\", \"https://goo.gl/3b9Wfh\"))\n .addSquareMarketingImage(\n buildImageAsset(\"square image asset\", \"https://goo.gl/mtt54n\"))\n .build();\n\n // ResponsiveDisplayAdBuilder has additional options.\n // For more details, see\n // https://developers.google.com/google-ads/scripts/docs/reference/adsapp/adsapp_responsivedisplayadbuilder\n}\n\nfunction buildImageAsset(assetName, imageUrl) {\n const imageBlob = UrlFetchApp.fetch(imageUrl).getBlob();\n return AdsApp.adAssets().newImageAssetBuilder()\n .withData(imageBlob)\n .withName(assetName)\n .build()\n .getResult();\n}\n```\n\nPause ad in an ad group\n-----------------------\n\n```gdscript\nfunction pauseAdInAdGroup(adGroupName) {\n const adGroupIterator = AdsApp.adGroups()\n .withCondition(`ad_group.name = \"${adGroupName}\"`)\n .get();\n if (!adGroupIterator.hasNext()) {\n throw new Error(`No ad group found with name: \"${adGroupName}\"`);\n }\n const adGroup = adGroupIterator.next();\n const adsIterator = adGroup.ads().get();\n if (!adsIterator.hasNext()) {\n throw new Error(`No ads found in ad group: \"${adGroupName}\"`);\n }\n const ad = adsIterator.next();\n ad.pause();\n}\n```\n\nGet expanded text ads iterator in an ad group\n---------------------------------------------\n\n```gdscript\nfunction getExpandedTextAdsIteratorInAdGroup(adGroupName) {\n const adGroupIterator = AdsApp.adGroups()\n .withCondition(`ad_group.name = \"${adGroupName}\"`)\n .get();\n if (!adGroupIterator.hasNext()) {\n throw new Error(`No ad group found with name: \"${adGroupName}\"`);\n }\n const adGroup = adGroupIterator.next();\n // You can filter for ads of a particular type, using the AdType selector.\n // See https://developers.google.com/google-ads/scripts/docs/reference/adsapp/adsapp_ad#getType_0\n // for possible values.\n const expandedTextAdsIterator = adGroup.ads()\n .withCondition(`ad_group_ad.ad.type = \"EXPANDED_TEXT_AD\"`)\n .get();\n if (!expandedTextAdsIterator.hasNext()) {\n throw new Error(`No expanded text ads found in ad group: \"${adGroupName}\"`);\n }\n return expandedTextAdsIterator;\n}\n```\n\nGet text ads iterator in an ad group\n------------------------------------\n\n```gdscript\nfunction getTextAdsIteratorInAdGroup(adGroupName) {\n const adGroupIterator = AdsApp.adGroups()\n .withCondition(`ad_group.name = \"${adGroupName}\"`)\n .get();\n if (!adGroupIterator.hasNext()) {\n throw new Error(`No ad group found with name: \"${adGroupName}\"`);\n }\n const adGroup = adGroupIterator.next();\n // You can filter for ads of a particular type, using the AdType selector.\n // See https://developers.google.com/google-ads/scripts/docs/reference/adsapp/adsapp_ad#getType_0\n // for possible values.\n\n const textAdsIterator = adGroup.ads()\n .withCondition(`ad_group_ad.ad.type = \"TEXT_AD\"`)\n .get();\n if (!textAdsIterator.hasNext()) {\n throw new Error(`No text ads found in ad group: \"${adGroupName}\"`);\n }\n return textAdsIterator;\n}\n```\n\nGet stats for ads in an ad group\n--------------------------------\n\n```gdscript\nfunction getAdGroupAdStats(adGroupName) {\n const adGroupIterator = AdsApp.adGroups()\n .withCondition(`ad_group.name = \"${adGroupName}\"`)\n .get();\n if (!adGroupIterator.hasNext()) {\n throw new Error(`No ad group found with name: \"${adGroupName}\"`);\n }\n const adGroup = adGroupIterator.next();\n // If you want to restrict your search to some ads only, then you could\n // apply a label and retrieve ads as\n //\n // const label = AdsApp.labels()\n // .withCondition(`ad_group_ad_label.name =\"INSERT_LABEL_NAME_HERE\"`)\n // .get()\n // .next();\n // const adsIterator = label.ads().get();\n\n const adsIterator = adGroup.ads().get();\n if (!adsIterator.hasNext()) {\n throw new Error(`No ads found in ad group: \"${adGroupName}\"`);\n }\n const ad = adsIterator.next();\n // You can also request reports for pre-defined date ranges. See\n // https://developers.google.com/google-ads/api/docs/query/date-ranges\n // DateRangeLiteral section for possible values.\n const stats = ad.getStatsFor('LAST_MONTH');\n console.log(`${adGroup.getName()},\n ${stats.getClicks()},\n ${stats.getImpressions()}`);\n}\n```\n\nGet responsive display ads in an ad group\n-----------------------------------------\n\n```gdscript\nfunction getResponsiveDisplayAdIteratorInAdGroup(adGroupName) {\n const adGroupIterator = AdsApp.adGroups()\n .withCondition(`ad_group.name = \"${adGroupName}\"`)\n .get();\n if (!adGroupIterator.hasNext()) {\n throw new Error(`No ad group found with name: ${adGroupName}`);\n }\n const adGroup = adGroupIterator.next();\n const responsiveDisplayAdsIterator = adGroup.ads()\n .withCondition(`ad_group_ad.ad.type IN (\"RESPONSIVE_DISPLAY_AD\",\n \"LEGACY_RESPONSIVE_DISPLAY_AD\")`)\n .get();\n if (!responsiveDisplayAdsIterator.hasNext()) {\n throw new Error(`No Responsive Display ads found in ad group:\n \"${adGroupName}\"`);\n }\n return responsiveDisplayAdsIterator;\n}\n```"]]