Script for copying keywords with conversions?

122 views
Skip to first unread message

Alan Daitch

unread,
Apr 16, 2013, 11:04:06 AM4/16/13
to adwords...@googlegroups.com
Hi! This is my first approach to AdWords scripts. I need to do a script that does the following:

- Looks if any keyword in my Campaign (let's call it Campaign A) had any conversion anytime in history and hasn't the label "Moved".
- Labels this keywords as "Moved".
- Copy this kws to another Campaign (let's call it Campaign B), and enables the ones that were paused.
- Pauses this kws in Campaign A.

Is this possible? Is this simple? Can you help me with at least some links so I can learn how to do this? Thanks!

Kevin Winter (AdWords Scripts Team)

unread,
Apr 17, 2013, 11:01:36 AM4/17/13
to adwords...@googlegroups.com
Hi Alan,
  Yes, this should be doable.  The key is to create the right keyword selector.  If you have a reference to campaign A:

campaign.keywords()

you'll want to add a condition for the conversion:

  .withCondition('Conversions > 0')
 
.forDateRange('ALL_TIME')

and then filter out those that have a label:

  .withCondition('LabelNames CONTAINS_NONE ["Moved"]')

And then iterate over the keywords returned in the iterator with .get() and label the keyword, move it, etc.

- Kevin Winter
AdWords Scripts Team

Alan Daitch

unread,
Apr 17, 2013, 3:43:50 PM4/17/13
to adwords...@googlegroups.com
Hi! I did my homework:

function main() {
 
// Replace with the name of a campaign in your account.
 
var campaignName = "Campaign A";


 
// Find all keywords with conversions and without label "Movida"
 
var keywordsIterator = AdWordsApp.keywords()

 
.withCondition('Conversions > 0')
 
.forDateRange('ALL_TIME')

 
.withCondition('LabelNames CONTAINS_NONE ["Movida"]')
     
.get();

 
// Pause and label this keywords
 
while (keywordsIterator.hasNext()) {
   
var keyword = keywordsIterator.next();
    keyword
.pause();
    keyword
.applyLabel('Movida');
 
}
}



is this right?

Another thing: I couldn't find how to copy this keyword to another campaign and enable it, how can I do that?

Kevin Winter (AdWords Scripts Team)

unread,
Apr 17, 2013, 4:07:46 PM4/17/13
to adwords...@googlegroups.com
Hi lan,
  It's getting there.  You'll need to look up Campaign A, something like this:

var campaignA = AdWordsApp.campaigns().withCondition('CampaignName = "' + campaignName + '"').get().next(); // will break if the campaign doesn't exist.

To move the campaign, you need to decide which ad group to add it to in the second campaign.  Once you've chosen the right adgroup:

adgroup.createKeyword(keyword.getText());

This will create it, default enabled.

- Kevin Winter
AdWords Scripts Team

Alan Daitch

unread,
Apr 17, 2013, 4:18:36 PM4/17/13
to adwords...@googlegroups.com
something like that? I added here the line you gave me for selecting the campaign in wich I have the keywords. I think my main problem is that I don't know how to select specific campaigns and adgroupd, so I haven't added the second line of code because I don't know how to select the adgroup.

function main() {
 
// Replace with the name of a campaign in your account.

 
var campaignName = "Genérica Alfabética";

 
var campaignA = AdWordsApp.campaigns().withCondition('CampaignName = "' + campaignName + '"').get().next(); // will break if the campaign doesn't exist.

 
// Find keywords with conversions that haven't been moved yet

 
var keywordsIterator = AdWordsApp.keywords()
 
.withCondition('Conversions > 0')
 
.forDateRange('ALL_TIME')
 
.withCondition('LabelNames CONTAINS_NONE ["Movida"]')
     
.get();



 
while (keywordsIterator.hasNext()) {

Alan Daitch

unread,
Apr 17, 2013, 5:13:52 PM4/17/13
to adwords...@googlegroups.com
made it!! It's running :D thanks! When I make a post in Spanish AW Community with this, i'll thank you :D


function main() {
 
// Replace with the name of a campaign in your account.
 
var campaignName = "Campaign A";

 
// Find keywords with conversions that haven't been moved yet
 
var keywordsIterator = AdWordsApp.keywords()

 
.withCondition("CampaignName = '" + campaignName + "'")

 
.withCondition('Conversions > 0')
 
.forDateRange('ALL_TIME')

 
.withCondition('LabelNames CONTAINS_NONE ["Moved"]')

     
.get();


 
while (keywordsIterator.hasNext()) {
   
var keyword = keywordsIterator.next();
    keyword
.pause();

    keyword
.applyLabel('Moved');
   
   
// adgroups
   
var adgroupWithConversion = 'All - 1';
   
var adGroupsIterator = AdWordsApp.adGroups()
     
.withCondition("AdGroupName CONTAINS '" + adgroupWithConversion + "'")
     
.get();
   
var adGroup = adGroupsIterator.next();
   
   
    adGroup
.createKeyword(keyword.getText());
   
   
   
   
// adgroups finishes here
   
}
   
 
}
Reply all
Reply to author
Forward
0 new messages