Google AdWord Script Filtering out Keywords according to Campaigns

439 views
Skip to first unread message

Aravin

unread,
Sep 26, 2017, 6:16:53 AM9/26/17
to AdWords Scripts Forum
Hi guys! I need your help in giving me a script which basically sorts out the keywords according to the campaign, So for example keyword "Machine" belongs to which campaigns. That is my task and i am clueless on how to start, may i please ask for someone to help me, that would be very kind of you, thank you and have a good day.

Thomas Müller

unread,
Sep 26, 2017, 6:50:20 AM9/26/17
to AdWords Scripts Forum
Hi Aravin,

this should be possible when you use logger.log ("Campaign = " +AdWordsApp.campaign.getName());

Then you should see, to which campaign your keyword belongs.

Was this helpfull?

Yours
Thomas

Anthony Madrigal

unread,
Sep 26, 2017, 9:33:03 AM9/26/17
to AdWords Scripts Forum
Hi Aravin,

You can use the Keywords Performance Report and use fields such as CampaignName or CampaignId to figure out where the keywords are located. You can add a predicate (WHERE clause) on these fields to have your report filter out campaigns you are not interested in. 

If you are using a keyword selector, you can use orderBy to sort your keywords by its campaigns.

Regards,
Anthony
AdWords Scripts Team

Aravin

unread,
Sep 26, 2017, 11:18:40 PM9/26/17
to AdWords Scripts Forum
Hi Thomas,

It was very helpful, i understood that part of the code, but can i have the whole script to sort out keywords based on campaigns? That would be extremely kind as i am a beginner in this and i must submit my script by tmr. I hope you can take my concerns into consideration. Thank you very much for your time.

Cheers,
Aravin

Aravin

unread,
Sep 26, 2017, 11:51:16 PM9/26/17
to AdWords Scripts Forum
Hi Anthony,

 Is there any samples currently in store for me to try out and understand and try to digest it? As i need to submit this by tmr and i am a beginner. I hope you can take   my concerns into your consideration. Thank you very much for your time.

Anthony Madrigal

unread,
Sep 27, 2017, 10:23:12 AM9/27/17
to AdWords Scripts Forum
Hi Aravin,

If you want to use a report, you can use the following. The WHERE line is optional if you would like to filter your keywords by a certain campaign. If you do not want the filter, you can remove the line.
var spreadsheet = SpreadsheetApp.create('INSERT_REPORT_NAME_HERE');
var report = AdWordsApp.report(
 
'SELECT CampaignName, Criteria, Id ' +
 
'FROM   CAMPAIGN_PERFORMANCE_REPORT ' +
 
'WHERE  CampaignName CONTAINS "campaign" ' +
 
'DURING LAST_30_DAYS');
report
.exportToSheet(spreadsheet.getActiveSheet());

If you want to use a keyword selector, you can use the following. The withCondition line is optional as well.
var keywordIterator = AdWordsApp.keywords()
   
.withCondition('CampaignName CONTAINS "campaign"')
   
.orderBy('CampaignName')
   
.get();
while (keywordIterator.hasNext()) {
 
var keyword = keywordIterator.next();
 
Logger.log("%s can be found in the campaign %s" ,keyword.getText(),keyword.getCampaign().getName());
}

Please let me know if you have any other questions.

Regards,
Anthony
AdWords Scripts Team

Aravin

unread,
Sep 27, 2017, 8:41:49 PM9/27/17
to AdWords Scripts Forum
Hi Mr Anthony,

So the difference between the two is the first one is retrieving a particular campaign, whereas the second code is sorting the keyword according to the campaigns? Thank you for your time.

Cheers,
Aravin

Aravin

unread,
Sep 28, 2017, 3:47:58 AM9/28/17
to AdWords Scripts Forum
Hi Mr Anthony,

To sort keywords based on campaigns i need to use both of the codes or one? As i am a bit confused on the difference of both of them and what they do individually. Sorry sir, i am a beginner hence that's why i can't understand it quite clearly. I hope u take my concerns into consideration.Thank you very much for your time.

Cheers,
Aravin

Anthony Madrigal

unread,
Sep 28, 2017, 10:20:30 AM9/28/17
to AdWords Scripts Forum
Hi Aravin,

You will only need to use one of the codes depending on what you are looking for. If you are looking to modify your keywords (such as it's bids), use the keyword selector. If you want stats on your keywords, I'd recommend using reports. Here is a guide on reports and how they are beneficial. 

Both of the codes I gave you include an optional line if you are only interested in a subset of campaigns. For the reports it's the line that says 'WHERE  CampaignName CONTAINS "campaign" ' + and for the selector it's .withCondition('CampaignName CONTAINS "campaign"'). If you are interested in keywords in all campaigns, just remove those lines respectively. 

Here is the snippet of code I'd recommend using if you want keyword stats from all of your campaigns:
var spreadsheet = SpreadsheetApp.create('INSERT_REPORT_NAME_HERE');
var report = AdWordsApp.report(
 
'SELECT CampaignName, Criteria, Id ' +

 
'FROM  KEYWORDS_PERFORMANCE_REPORT ' +
 
'DURING LAST_30_DAYS');
report
.exportToSheet(spreadsheet.getActiveSheet());

Cheers,
Anthony
AdWords Scripts Team

Aravin

unread,
Oct 5, 2017, 9:23:32 PM10/5/17
to AdWords Scripts Forum
Hi Mr Anthony, may i rephrase my output that i want just to know that we are in sync, i need a full working script to Sort Duplicate Targeting Keywords in Google AdWords, is this what the script that u gave me is doing? I am a beginner in this and i need to submit this by today. Thank you for your time.

Anthony Madrigal

unread,
Oct 6, 2017, 9:21:23 AM10/6/17
to AdWords Scripts Forum
Hi Aravin,

The script I provided will give you a report of all your keywords, regardless of if they are duplicates. If you are looking for a script to detect duplicate keywords, you can use this third party script

Since it is a third party script, I would recommend reaching out to them if you run into any issues.

Cheers,
Anthony
AdWords Scripts Team
Reply all
Reply to author
Forward
0 new messages