Change targeting locations by SCRIPT

701 views
Skip to first unread message

Christopher Larkin

unread,
Jan 24, 2021, 2:36:06 PM1/24/21
to Google Ads Scripts Forum
Hi -

I can't find a method to set locations or excluded locations. Is this possible? 

I have a bunch of zip codes I want to programmatically add to campaigns - if this is possible can someone share a snippet of code to help me get started? 

Thank you -
Christopher 

Google Ads Scripts Forum Advisor

unread,
Jan 24, 2021, 11:02:18 PM1/24/21
to adwords...@googlegroups.com

Hi Christopher,

Thank you for reaching out to us.

With regard to your concern on adding/excluding campaign locations, you can check on these available campaign methods ( addLocationexcludeLocation ). With regard to adding campaign zip codes, I'm afraid that this is currently not possible with the Google Ads scripts; however, you can make use of location ranges by creating proximity targets as an alternative.

In addition, you can check the sample scripts found here (under Targeting) for your reference.

Regards,

Google Logo
Mark Kevin Albios
Google Ads Scripts Team
 


ref:_00D1U1174p._5004Q2B2z1x:ref

Christopher Larkin

unread,
Jan 25, 2021, 9:22:12 AM1/25/21
to Google Ads Scripts Forum
Can we target/exclude using the GEO IDs  (such as 9009970 instead of zip code 28202)? 

Google Ads Scripts Forum Advisor

unread,
Jan 25, 2021, 10:20:22 PM1/25/21
to adwords...@googlegroups.com

Hi Christopher,

 

Thanks for coming back. I am Harry, teammate of Mark on the Google Ads Scripts Team. If the GEO IDs you are referring to are Criteria IDs for Geotargets, then yes. You can add/create and exclude locations for Campaign Targeting using this. Kindly refer to this link for further information on creating location targets. Let me know if you have other questions.

 

Thanks,

Google Logo
Harry Cliford Rivera
Google Ads Scripts Team
 


ref:_00D1U1174p._5004Q2B2z1x:ref

Christopher Larkin

unread,
Feb 3, 2021, 9:29:50 PM2/3/21
to Google Ads Scripts Forum
Hi Harry - 

Weirdest thing → when I add locations, no problems occur, but if I use the exclude method, I get an error saying I need to use a number for the parameter. However, I'm using the same variable (with same value) for both methods. Any idea why this would happen? 

Here's a snippet of the code:
for (i = 0; i < listOfGeosArray.length; i++) {
Logger.log(listOfGeosArray[i]);
if (exclude) {
campaign.excludeLocation(listOfGeosArray[i]);
} else {
campaign.addLocation(listOfGeosArray[i]);
}

When I use the addLocation method, the value works just fine; however, if I set the value of "exclude" to true, the routine fails. 

Any suggestions? 

Google Ads Scripts Forum Advisor

unread,
Feb 3, 2021, 11:44:15 PM2/3/21
to adwords...@googlegroups.com

Hi Chris,

 

Thanks for coming back regarding this. Can you kindly provide your CID where you have created the script and the script's name so that I can take a look at this on our end? You may send them here or privately via the reply to author option. If this option is not available at your end, you may send the requested information through our email (googleadsscr...@google.com) instead.

Google Ads Scripts Forum Advisor

unread,
Feb 5, 2021, 1:07:15 AM2/5/21
to adwords...@googlegroups.com

Hi Chris,

 

Thanks for providing the requested information. Upon checking, (in line 70) you are calling the applyTargets method and passing the included variable as the third argument instead of the excluded variable that it set to true. As for the error you are encountering, "Targeting is not allowed." this is mostly likely caused by an invalid Geotarget Criterion ID (location). Kindly refer to this list of available geotargets.

 

Kindly update accordingly, then let me know how it goes.

Message has been deleted

Christopher Larkin

unread,
Feb 8, 2021, 11:49:25 PM2/8/21
to Google Ads Scripts Forum
Line 117 is where I get the error when I run with that variable as true. I get an error saying the variable isn't a number. 


On Monday, February 8, 2021 at 10:47:03 PM UTC-6 Christopher Larkin wrote:
Thank you very much - I'll make the updates and report back. 

Google Ads Scripts Forum Advisor

unread,
Feb 9, 2021, 1:56:06 AM2/9/21
to adwords...@googlegroups.com

Hi Chris,

 

Would you be able to provide a shareable link or a copy of the spreadsheet you are using so that I can take a look closer at your script? You may send it via the options I have mentioned previously.

Reply all
Reply to author
Forward
0 new messages