Hello wonderful people,
I am a noob in google ads scripts trying to write a script that automatically removes a sitelink when their end date lies in the past. (In my company we have a lot of promotions and we have a lot of sitelinks per campaigns).
I wrote this code and it works but it does absolutely nothing, can someone help me?
Thx a lot!
function main() {
var date = new Date();
var campaign = AdsApp.campaigns()
.withCondition("CampaignName = 'YOUR CAMPAIGN NAME HERE'")
.get()
.next();
var campaignSitelinkDate = campaign.extensions()
.sitelinks().getEndDate;
var campaignSitelinkSelector = campaign.extensions()
.sitelinks();
/*.withCondition("Status = ENABLED") */
/*.withCondition("CampaignStatus = PAUSED") */
/*.forDateRange("YESTERDAY"); */
var campaignSitelinkIterator = campaignSitelinkSelector.get();
/* var campaignSitelinkDate = campaignSitelinkSelector.getEndDate; */
if (campaignSitelinkIterator.hasNext() || (campaignSitelinkDate < date) ) {
var campaignSitelink = campaignSitelinkIterator.next()
campaignSitelinkSelector.removeSitelink;
}
}
You are not using method
and iterator
correctly.
function main() {
var date = new Date();
var campaign = AdsApp.campaigns()
.withCondition("CampaignName = 'YOUR CAMPAIGN NAME HERE'")
.get()
.next();
var campaignSitelinkSelector = campaign.extensions()
.sitelinks();
/*.withCondition("Status = ENABLED") */
/*.withCondition("CampaignStatus = PAUSED") */
/*.forDateRange("YESTERDAY"); */
var campaignSitelinkIterator = campaignSitelinkSelector.get();
if (campaignSitelinkIterator.hasNext()) {
var campaignSitelink = campaignSitelinkIterator.next()
var campaignSitelinkDate = campaignSitelink.getEndDate();
if (campaignSitelinkDate < date) {
campaign.removeSitelink(campaignSitelink);
}
}
}