Campaigns
Stay organized with collections
Save and categorize content based on your preferences.
Get campaigns
function
getCampaigns
()
{
//
AdsApp
.
campaigns
()
will
return
all
Display
and
Search
campaigns
//
that
are
not
removed
by
default
.
Other
campaign
types
can
be
retrieved
//
by
using
their
respective
campaign
selector
methods
.
const
campaignIterator
=
AdsApp
.
campaigns
()
.
get
();
console
.
log
(
`
Total
campaigns
found
:
$
{
campaignIterator
.
totalNumEntities
()}
`
);
return
campaignIterator
;
}
Get a campaign by name
function
getCampaignByName
(
name
)
{
const
campaignIterator
=
AdsApp
.
campaigns
()
.
withCondition
(
`
campaign
.
name
=
"${name}"
`
)
.
get
();
if
(
campaignIterator
.
hasNext
())
{
const
campaign
=
campaignIterator
.
next
();
console
.
log
(
`
Campaign
Name
:
$
{
campaign
.
getName
()}
`
);
console
.
log
(
`
Enabled
:
$
{
campaign
.
isEnabled
()}
`
);
console
.
log
(
`
Bidding
strategy
:
$
{
campaign
.
getBiddingStrategyType
()}
`
);
console
.
log
(
`
Ad
rotation
:
$
{
campaign
.
getAdRotationType
()}
`
);
console
.
log
(
`
Start
date
:
$
{
formatDate
(
campaign
.
getStartDate
())}
`
);
console
.
log
(
`
End
date
:
$
{
formatDate
(
campaign
.
getEndDate
())}
`
);
return
campaign
;
}
else
{
throw
new
Error
(
`
No
campaign
named
"${name}"
found
`
);
}
}
function
formatDate
(
date
)
{
function
zeroPad
(
number
)
{
return
Utilities
.
formatString
(
'
%02d
'
,
number
);
}
return
(
date
==
null
)
?
'None'
:
zeroPad
(
date
.
year
)
+
zeroPad
(
date
.
month
)
+
zeroPad
(
date
.
day
);
}
Get a campaign's stats
function
getCampaignStats
(
name
)
{
const
campaignIterator
=
AdsApp
.
campaigns
()
.
withCondition
(
`
campaign
.
name
=
"${name}"
`
)
.
get
();
if
(
campaignIterator
.
hasNext
())
{
const
campaign
=
campaignIterator
.
next
();
//
You
can
also
request
reports
for
pre
-
defined
date
ranges
.
See
//
https
:
//
developers
.
google
.
com
/
google
-
ads
/
scripts
/
docs
/
reference
/
adsapp
/
adsapp_campaign
#getStatsFor_1,
//
DateRangeLiteral
section
for
possible
values
.
const
stats
=
campaign
.
getStatsFor
(
'LAST_MONTH'
);
console
.
log
(
`
$
{
campaign
.
getName
()}:
$
{
stats
.
getClicks
()}
clicks
,
$
{
stats
.
getImpressions
()}
impressions
`
);
return
stats
;
}
else
{
throw
new
Error
(
`
No
campaign
named
"${name}"
found
`
);
}
}
Pause a campaign
function
pauseCampaign
(
name
)
{
const
campaignIterator
=
AdsApp
.
campaigns
()
.
withCondition
(
`
campaign
.
name
=
"${name}"
`
)
.
get
();
if
(
campaignIterator
.
hasNext
())
{
const
campaign
=
campaignIterator
.
next
();
campaign
.
pause
();
}
else
{
throw
new
Error
(
`
No
campaign
named
"${name}"
found
`
);
}
}
Get a campaign's device bid modifiers
function
getCampaignBidModifiers
(
name
)
{
const
campaignIterator
=
AdsApp
.
campaigns
()
.
withCondition
(
`
campaign
.
name
=
"${name}"
`
)
.
get
();
if
(
campaignIterator
.
hasNext
())
{
const
campaign
=
campaignIterator
.
next
();
console
.
log
(
'Campaign name: '
+
campaign
.
getName
());
const
platforms
=
{};
for
(
const
platform
of
campaign
.
targeting
()
.
platforms
())
{
console
.
log
(
`
$
{
platform
.
getName
()}
bid
modifier
:
$
{
platform
.
getBidModifier
()}
`
);
platforms
[
platform
.
getName
()]
=
platform
.
getBidModifier
();
}
return
platforms
;
}
else
{
throw
new
Error
(
`
No
campaign
named
"${name}"
found
`
);
}
}
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 code snippets demonstrate how to interact with Google Ads campaigns programmatically using Google Ads Scripts.\u003c/p\u003e\n"],["\u003cp\u003eFunctionality includes retrieving all campaigns, getting a specific campaign by name, and accessing campaign statistics.\u003c/p\u003e\n"],["\u003cp\u003eYou can also pause campaigns and retrieve device bid modifiers for specific campaigns using the provided functions.\u003c/p\u003e\n"],["\u003cp\u003eEach function utilizes the \u003ccode\u003eAdsApp.campaigns()\u003c/code\u003e method to access and manipulate campaign data within your Google Ads account.\u003c/p\u003e\n"],["\u003cp\u003eError handling is implemented to ensure smooth execution and inform users when a specified campaign is not found.\u003c/p\u003e\n"]]],[],null,["# Campaigns\n\nGet campaigns\n-------------\n\n```gdscript\nfunction getCampaigns() {\n // AdsApp.campaigns() will return all Display and Search campaigns\n // that are not removed by default. Other campaign types can be retrieved\n // by using their respective campaign selector methods.\n const campaignIterator = AdsApp.campaigns().get();\n console.log(`Total campaigns found : ${campaignIterator.totalNumEntities()}`);\n return campaignIterator;\n}\n```\n\nGet a campaign by name\n----------------------\n\n```gdscript\nfunction getCampaignByName(name) {\n const campaignIterator = AdsApp.campaigns()\n .withCondition(`campaign.name = \"${name}\"`)\n .get();\n if (campaignIterator.hasNext()) {\n const campaign = campaignIterator.next();\n console.log(`Campaign Name: ${campaign.getName()}`);\n console.log(`Enabled: ${campaign.isEnabled()}`);\n console.log(`Bidding strategy: ${campaign.getBiddingStrategyType()}`);\n console.log(`Ad rotation: ${campaign.getAdRotationType()}`);\n console.log(`Start date: ${formatDate(campaign.getStartDate())}`);\n console.log(`End date: ${formatDate(campaign.getEndDate())}`);\n return campaign;\n } else {\n throw new Error(`No campaign named \"${name}\" found`);\n }\n}\nfunction formatDate(date) {\n function zeroPad(number) { return Utilities.formatString('%02d', number); }\n return (date == null) ? 'None' : zeroPad(date.year) + zeroPad(date.month) +\n zeroPad(date.day);\n}\n```\n\nGet a campaign's stats\n----------------------\n\n```gdscript\nfunction getCampaignStats(name) {\n const campaignIterator = AdsApp.campaigns()\n .withCondition(`campaign.name = \"${name}\"`)\n .get();\n if (campaignIterator.hasNext()) {\n const campaign = campaignIterator.next();\n // You can also request reports for pre-defined date ranges. See\n // https://developers.google.com/google-ads/scripts/docs/reference/adsapp/adsapp_campaign#getStatsFor_1,\n // DateRangeLiteral section for possible values.\n const stats = campaign.getStatsFor('LAST_MONTH');\n console.log(`${campaign.getName()}: ${stats.getClicks()} clicks, ${stats.getImpressions()} impressions`);\n return stats;\n } else {\n throw new Error(`No campaign named \"${name}\" found`);\n }\n}\n```\n\nPause a campaign\n----------------\n\n```gdscript\nfunction pauseCampaign(name) {\n const campaignIterator = AdsApp.campaigns()\n .withCondition(`campaign.name = \"${name}\"`)\n .get();\n if (campaignIterator.hasNext()) {\n const campaign = campaignIterator.next();\n campaign.pause();\n } else {\n throw new Error(`No campaign named \"${name}\" found`);\n }\n}\n```\n\nGet a campaign's device bid modifiers\n-------------------------------------\n\n```gdscript\nfunction getCampaignBidModifiers(name) {\n const campaignIterator = AdsApp.campaigns()\n .withCondition(`campaign.name = \"${name}\"`)\n .get();\n if (campaignIterator.hasNext()) {\n const campaign = campaignIterator.next();\n console.log('Campaign name: ' + campaign.getName());\n\n const platforms = {};\n for (const platform of campaign.targeting().platforms()) {\n console.log(`${platform.getName()} bid modifier: ${platform.getBidModifier()}`);\n platforms[platform.getName()] = platform.getBidModifier();\n }\n return platforms;\n } else {\n throw new Error(`No campaign named \"${name}\" found`);\n }\n}\n```"]]