Sitelinks
Stay organized with collections
Save and categorize content based on your preferences.
Create a sitelink extension
function
createSitelink
()
{
//
For
full
details
on
creating
a
new
sitelink
extension
,
see
:
//
https
:
//
developers
.
google
.
com
/
google
-
ads
/
scripts
/
docs
/
reference
/
adsapp
/
adsapp_sitelinkbuilder
const
newSitelink
=
AdsApp
.
extensions
()
.
newSitelinkBuilder
()
//
Replace
the
values
below
with
your
link
link
text
,
final
url
,
and
//
mobile
preferred
.
withLinkText
(
'Music'
)
//
required
.
withFinalUrl
(
'http://www.example.com/Music'
)
//
required
.
withMobilePreferred
(
true
)
//
optional
.
build
()
.
getResult
();
//
Add
sitelink
to
a
campaign
const
campaignIterator
=
AdsApp
.
campaigns
()
.
withCondition
(
'campaign.name = "INSERT_CAMPAIGN_NAME_HERE"'
)
.
get
();
if
(
campaignIterator
.
hasNext
())
{
const
campaign
=
campaignIterator
.
next
();
campaign
.
addSitelink
(
newSitelink
);
}
//
Add
sitelink
to
an
ad
group
const
adGroupIterator
=
AdsApp
.
adGroups
()
.
withCondition
(
'campaign.name = "INSERT_CAMPAIGN_NAME_HERE"'
)
.
withCondition
(
'ad_group.name = "INSERT_AD_GROUP_NAME_HERE"'
)
.
get
();
if
(
adGroupIterator
.
hasNext
())
{
const
adGroup
=
adGroupIterator
.
next
();
adGroup
.
addSitelink
(
newSitelink
);
}
//
Add
sitelink
to
an
account
const
account
=
AdsApp
.
currentAccount
();
account
.
addSitelink
(
newSitelink
);
}
Log sitelink details for a campaign
function
logSitelinkDetails
()
{
//
Get
a
campaign
.
const
campaignIterator
=
AdsApp
.
campaigns
()
.
withCondition
(
'campaign.name = "INSERT_CAMPAIGN_NAME_HERE"'
)
.
get
();
if
(
!
campaignIterator
.
hasNext
())
{
throw
new
Error
(
'Campaign not found.'
);
}
const
campaign
=
campaignIterator
.
next
();
//
Retrieve
the
campaign
's sitelinks. Retrieving an ad group'
s
and
//
account
's sitelinks is similar.
const
sitelinkIterator
=
campaign
.
extensions
()
.
sitelinks
()
.
get
();
for
(
const
sitelink
of
sitelinkIterator
)
{
//
You
can
also
request
reports
for
pre
-
defined
date
ranges
.
See
//
https
:
//
developers
.
google
.
com
/
adwords
/
api
/
docs
/
guides
/
awql
,
//
DateRangeLiteral
section
for
possible
values
.
const
stats
=
sitelink
.
getStatsFor
(
'LAST_MONTH'
);
console
.
log
(
`
Sitelink
text
:
$
{
sitelink
.
getLinkText
()
}
`
);
console
.
log
(
`
final
URL
:
$
{
sitelink
.
urls
()
.
getFinalUrl
()
}
`
);
console
.
log
(
`
mobile
preferred
:
$
{
sitelink
.
isMobilePreferred
()
}
`
);
console
.
log
(
`
clicks
:
$
{
stats
.
getClicks
()
}
`
);
console
.
log
(
`
impressions
:
$
{
stats
.
getImpressions
()
}
`
);
console
.
log
(
'======='
);
}
console
.
log
(
`
$
{
sitelinkIterator
.
totalNumEntities
()}
sitelinks
in
the
campaign
`
);
}
Set schedule for sitelinks in a campaign
function
setSitelinkSchedule
()
{
//
Get
a
campaign
.
const
campaignIterator
=
AdsApp
.
campaigns
()
.
withCondition
(
'campaign.name = "INSERT_CAMPAIGN_NAME_HERE"'
)
.
get
();
if
(
!
campaignIterator
.
hasNext
())
{
throw
new
Error
(
'Campaign not found.'
);
}
const
campaign
=
campaignIterator
.
next
();
//
Retrieve
the
campaign
's sitelinks. Retrieving an ad group'
s
and
//
account
's saitelinks is similar.
const
sitelinkIterator
=
campaign
.
extensions
()
.
sitelinks
()
.
get
();
for
(
const
sitelink
of
sitelinkIterator
)
{
if
(
sitelink
.
getLinkText
()
===
'Music'
)
{
//
Set
sitelink
schedule
to
run
only
on
Mondays
and
Tuesdays
,
9
AM
to
//
6
PM
.
const
monday
=
{
dayOfWeek
:
'MONDAY'
,
startHour
:
9
,
startMinute
:
0
,
endHour
:
18
,
endMinute
:
0
};
const
tuesday
=
{
dayOfWeek
:
'TUESDAY'
,
startHour
:
9
,
startMinute
:
0
,
endHour
:
18
,
endMinute
:
0
};
sitelink
.
setSchedules
([
monday
,
tuesday
]);
break
;
}
}
}
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\u003eThis script provides functionality to create new sitelinks with custom link text, final URLs, and mobile preference, which can be applied at the campaign, ad group, or account level.\u003c/p\u003e\n"],["\u003cp\u003eIt allows retrieval of existing sitelink details like link text, URL, mobile preference, clicks, and impressions for a specific campaign, ad group, or account, and logs them to the console.\u003c/p\u003e\n"],["\u003cp\u003eYou can set a custom schedule for your sitelinks, specifying the days and time range during which they should be active, using the provided functions.\u003c/p\u003e\n"],["\u003cp\u003eThis script uses the Google Ads Scripts API to interact with your Google Ads account, enabling automation of sitelink management tasks.\u003c/p\u003e\n"]]],[],null,["# Sitelinks\n\nCreate a sitelink extension\n---------------------------\n\n```gdscript\nfunction createSitelink() {\n // For full details on creating a new sitelink extension, see:\n // https://developers.google.com/google-ads/scripts/docs/reference/adsapp/adsapp_sitelinkbuilder\n const newSitelink = AdsApp.extensions().newSitelinkBuilder()\n // Replace the values below with your link link text, final url, and\n // mobile preferred\n .withLinkText('Music') // required\n .withFinalUrl('http://www.example.com/Music') // required\n .withMobilePreferred(true) // optional\n .build()\n .getResult();\n\n // Add sitelink to a campaign\n const campaignIterator = AdsApp.campaigns()\n .withCondition('campaign.name = \"INSERT_CAMPAIGN_NAME_HERE\"')\n .get();\n if (campaignIterator.hasNext()) {\n const campaign = campaignIterator.next();\n campaign.addSitelink(newSitelink);\n }\n\n // Add sitelink to an ad group\n const adGroupIterator = AdsApp.adGroups()\n .withCondition('campaign.name = \"INSERT_CAMPAIGN_NAME_HERE\"')\n .withCondition('ad_group.name = \"INSERT_AD_GROUP_NAME_HERE\"')\n .get();\n if (adGroupIterator.hasNext()) {\n const adGroup = adGroupIterator.next();\n adGroup.addSitelink(newSitelink);\n }\n\n // Add sitelink to an account\n const account = AdsApp.currentAccount();\n account.addSitelink(newSitelink);\n}\n```\n\nLog sitelink details for a campaign\n-----------------------------------\n\n```gdscript\nfunction logSitelinkDetails() {\n // Get a campaign.\n const campaignIterator = AdsApp.campaigns()\n .withCondition('campaign.name = \"INSERT_CAMPAIGN_NAME_HERE\"')\n .get();\n if (!campaignIterator.hasNext()) {\n throw new Error('Campaign not found.');\n }\n const campaign = campaignIterator.next();\n\n // Retrieve the campaign's sitelinks. Retrieving an ad group's and\n // account's sitelinks is similar.\n const sitelinkIterator = campaign.extensions().sitelinks().get();\n for (const sitelink of sitelinkIterator) {\n // You can also request reports for pre-defined date ranges. See\n // https://developers.google.com/adwords/api/docs/guides/awql,\n // DateRangeLiteral section for possible values.\n const stats = sitelink.getStatsFor('LAST_MONTH');\n\n console.log(`Sitelink text : ${ sitelink.getLinkText() }`);\n console.log(`final URL : ${ sitelink.urls().getFinalUrl() }`);\n console.log(`mobile preferred : ${ sitelink.isMobilePreferred() }`);\n console.log(`clicks : ${ stats.getClicks() }`);\n console.log(`impressions : ${ stats.getImpressions() }`);\n console.log('=======');\n }\n\n console.log(`${sitelinkIterator.totalNumEntities()} sitelinks in the campaign`);\n}\n```\n\nSet schedule for sitelinks in a campaign\n----------------------------------------\n\n```gdscript\nfunction setSitelinkSchedule() {\n // Get a campaign.\n const campaignIterator = AdsApp.campaigns()\n .withCondition('campaign.name = \"INSERT_CAMPAIGN_NAME_HERE\"')\n .get();\n if (!campaignIterator.hasNext()) {\n throw new Error('Campaign not found.');\n }\n const campaign = campaignIterator.next();\n\n // Retrieve the campaign's sitelinks. Retrieving an ad group's and\n // account's saitelinks is similar.\n const sitelinkIterator = campaign.extensions().sitelinks().get();\n\n for (const sitelink of sitelinkIterator) {\n if (sitelink.getLinkText() === 'Music') {\n // Set sitelink schedule to run only on Mondays and Tuesdays, 9 AM to\n // 6 PM.\n const monday = {\n dayOfWeek: 'MONDAY',\n startHour: 9,\n startMinute: 0,\n endHour: 18,\n endMinute: 0\n };\n\n const tuesday = {\n dayOfWeek: 'TUESDAY',\n startHour: 9,\n startMinute: 0,\n endHour: 18,\n endMinute: 0\n };\n\n sitelink.setSchedules([monday, tuesday]);\n\n break;\n }\n }\n}\n```"]]