AdWords is now Google Ads. Our new name reflects the full range of advertising options we offer across Search, Display, YouTube, and more. Learn more

4.4K members online now
4.4K members online now
Dive into advanced features like Remarketing, Flexible Bid Strategies, AdWords Editor, and AdWords Scripts
Guide Me

AdWords Script: Bulk Remarketing Audiences Creation

Not applicable
# 1
Not applicable


PPC experts have lacked remarketing audience creation function for a while. After Remarketing with Analytics was released from a beta testing in Managment Analytics API such an opportunity has appeared. Earlier, experts needed a huge amount of time to create a big number of audiences. The new API function has changed a lot, so today Internet marketers can upload new audiences in a bulk.


Dmitry Tonkikh, a contextual advertising specialist in Promodo, introduces the script that gets all the input data from the Google Spreadsheet file. Then, it accesses Analytics directly and creates a remarketing audience. It is possible to make dozens and hundreds of audiences with a various number of days of collection of cookie files and different conditions.

This script is configured to create a simple audience, according to the type of the visited pages. It is based on the principle of sending requests to Analytics. There is a quota for the creation of audiences which is rather small. If you need to make a lot of audiences, you can simply do a series of projects. To start making your audiences with ease, follow the steps below.


1. Activate Analytics in the extended API.
2. Activate Analytics in the developer console using the link showed in the script’s logs.
3. Prepare a Google Spreadsheet, for example click here.
4. Name the first column, so you will title your future audience.
Expert Tip: add for how long the cookie files should be stored in the name of the column.
5. Name the second column that is responsible for the address or the path of the page that will be created for the audience.
6. Determine the time of storage: enter the period over which the audience will be collected over, e.g. try 7 so that you will collect audiences over the last 7 days and further in Google Analytics.
7. Add information about the Google Analytics and Adwords account.
8. Use Account Explorer service to determine ID Analytics.

This script allows you to complete up to 500 audiences:


*Remarketing Audiences Creator
*Created by Dmytro Tonkikh

function main() { var settings = {'linkedView':"XXXXXXXX", 'linkedAccountId':"XXX-XXX-XXXX", 'accountId':'XXXXXXX', 'propertyID':'UA-XXXXXXX-X'}; var spreadsheet = SpreadsheetApp.openByUrl(''); var sheet = spreadsheet.getSheetByName('Sheet1'); var range = sheet.getRange(1, 2, sheet.getLastRow(), 3); var values = range.getValues(); Logger.log(values.length); for(var i = 0; i < values.length; i++) { var name = values[i][0]; var categoryUrl = values[i][1]; var duration = values[i][2]; var newAudience = Analytics.Management.RemarketingAudience.insert( { 'name': name, 'linkedViews': [settings.linkedView], 'linkedAdAccounts': [{ 'type': 'ADWORDS_LINKS', 'linkedAccountId': settings.linkedAccountId, }], 'audienceType': 'SIMPLE', 'audienceDefinition': { 'includeConditions': { 'daysToLookBack': 7, 'segment': 'sessions::condition::ga:pagePath=@' + categoryUrl, 'membershipDurationDays': duration, 'isSmartList': false } } }, settings.accountId, settings.propertyID); Logger.log(i + ' Audience ' + name + ' has been created'); }; }


As a result, we get remarketing audiences created in bulk. They can be used as templates for remarketing, search, etc.


The script is simple, yet it allows to create many remarketing audiences, e.g. people who visited a particular website page, in minutes.
For more complex audiences, it is necessary to build segments using conditions. For further information, refer to Query Explorer service, pay your attention to the segments.
Make remarketing audiences without a hitch!


1 Expert replyverified_user

Re: AdWords Script: Bulk Remarketing Audiences Creation

Community Manager
# 2
Community Manager
Thanks for sharing.

Re: AdWords Script: Bulk Remarketing Audiences Creation

[ Edited ]
Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

I've followed all the steps but still get error: 

Invalid value for Integer:  (line 26)

Any idea what might be wrong? I tried removing dashes from id's and so on.


Solved it. Just needed to cast duration to number like that: Number(duration).

+ Everything should be moved 1 column to the right. And you shouldn't have headlines in your columns.

Other than that everything works perfect. Thanks

AdWords Script: Bulk Remarketing Audiences Creation

Not applicable
# 4
Not applicable

Hi @Igor C,

try to use this syntax parseInt(duration, 10);

AdWords Script: Bulk Remarketing Audiences Creation

Visitor ✭ ✭ ✭
# 5
Visitor ✭ ✭ ✭


I am trying to use this script, but we have issues with it. It seems to me, that there is problem with gaSmiley TongueagePath condition in includeSegment creation.


Audiences are being created via API, but it seem they are empty (do nothing).


I was looking into Googles documentation and it seems, that gaSmiley TongueagePath condition is not there. I did try users::condition and sessions::condition too.


Can you please give me some advice or a hint how to make it work?


AdWords Script: Bulk Remarketing Audiences Creation

Visitor ✭ ✭ ✭
# 6
Visitor ✭ ✭ ✭

@Martin K I have answered on stackoverflow. Please let me know if you have any quastions.


It's all about segments)