I'm trying to make a script that copies an excluded search audience from one Google Ads campaign to another. After trying several options I simply copied two codes provides in the Google Scripts examples, here:
https://developers.google.com/google-ads/scripts/docs/examples/search-audiencesbut it doesn't work. Running in a preview mode it seems to be Ok but when executing de script it return an error: Item not found (or similar, in Spanish: No se ha encontrado el elemento).
This is the code:
function main() {
var CAMPAIGN_NAME = "CAMPAIGN_NAME" ;// insert here the name of the source campaign
//Get excluded search audiences for a campaign
// Retrieve the campaign.
var campaign = AdsApp.campaigns()
.withCondition('Name = "' + CAMPAIGN_NAME + '"')
.get()
.next();
var excludedAudiences = campaign.targeting().excludedAudiences().get();
while (excludedAudiences.hasNext()) {
var audience = excludedAudiences.next();
}
// Exclude search audience from a campaign
var targetCampaign = "targetCampaign" ;// insert here the name of the output campaign
var AUDIENCE_LIST_ID = audience.getAudienceId();
// Retrieve the campaign.
var campaignDest = AdsApp.campaigns()
.withCondition('Name = "' + targetCampaign + '"')
.get()
.next();
// Create the excluded audience.
var audienceDest = campaignDest.targeting()
.newUserListBuilder()
.withAudienceId(AUDIENCE_LIST_ID)
.exclude()
.getResult();
}
Thaks for any help.