<https://lh3.googleusercontent.com/-d0yPFHLdRoI/VNRSEXn9MSI/AAAAAAAAAAk/gI5yhvSn0qY/s1600/ad%2Blabel%2Btest.JPG>
Hi,
I want to add labels to my ads. I tried using this script I found from
{http://white.net/blog/label-keywords-ads-bulk-adwords-script/}
function main() {
// Applies labels to specified ads, based on a Google Doc Spreadsheet.
// From
http://white.net/blog/label-keywords-ads-bulk-adwords-script//Change this
to your spreadsheet's URL!
var spreadsheetUrl =
"https://docs.google.com/spreadsheets/d/1-eH8OS0vVxUrs0r9NtEDoUKeWG21JjX1vD-VfK7TVpo/edit#gid=0";
var inputSheet = SpreadsheetApp.openByUrl(spreadsheetUrl).getActiveSheet();
//The sheet in the Google Doc
var i = 2; //Integer for the loop
var numberOfLabels = inputSheet.getLastRow() //Number of rows in the sheet,
which is the number of ad groups that want to be labeled
var lastLabelApplied = ""; //Records the label that was last applied, so if
the next label is the same the Script knows it doesn't have to create it
again
while (i <= numberOfLabels) //This loops through all the rows
{
if (inputSheet.getRange("I"+i).getValue() == "") //If there are no notes
for the current row
{
var labelCampaignName = inputSheet.getRange("A" + i).getValue();
var labelAdGroupName = inputSheet.getRange("B" + i).getValue();
var labelHeadline = inputSheet.getRange("C" + i).getValue();
var labelDescriptionLine1 = inputSheet.getRange("D" + i).getValue();
var labelDescriptionLine2 = inputSheet.getRange("E" + i).getValue();
var labelDisplayURL = inputSheet.getRange("F" + i).getValue();
var labelDestinationURL = inputSheet.getRange("G" + i).getValue();
var labelText = inputSheet.getRange("H" + i).getValue();
var printToSpreadsheet = "-"
//This is a variable that records what will be noted in the spreadsheet for
each ad group (whether the label has been added, or there was an error)
var adIterator = AdWordsApp.ads() //Finds the ads with the specified name
and campaign name
.withCondition("CampaignName = '" + labelCampaignName + "'")
.withCondition("AdGroupName = '" + labelAdGroupName +"'")
.withCondition("Headline = '" + labelHeadline +"'")
.withCondition("Description1 = '" + labelDescriptionLine1 +"'")
.withCondition("Description2 = '" + labelDescriptionLine2 +"'")
.withCondition("DisplayUrl = '" + labelDisplayURL +"'")
.withCondition("DestinationUrl = '" + labelDestinationURL +"'")
.get();
if (adIterator.hasNext()) //If there is a keyword then the label will be
applied
{
var ad = adIterator.next();
if (labelText != lastLabelApplied)
//If this label isn't the same as the last label to be applied, then the
label is created.
//If the label was the same as the last label to be applied we know the
label already exists, so we can skip this
{
AdWordsApp.createLabel(labelText); //Creates the label - if the label
already exists then there may be an error, but the Script will continue
}
ad.applyLabel(labelText); //Applies the label to the keyword
printToSpreadsheet = "Done";
lastLabelApplied = labelText; //Records the last applied label
}
else
{
//This means the keyword iterator was empty, so there wasn't a keyword of
the right name (or a campaign or a group of the right name).
printToSpreadsheet = "Ad not found"; //An error message will be recorded in
the spreadsheet.
}
inputSheet.getRange("I" + i).setValue(printToSpreadsheet); //Writes into
the Notes column in the spreadsheet
Logger.log("Label " + labelText + " applied to '" + labelHeadline + "' in
'" + labelAdGroupName + "', '"+ labelCampaignName +"': " +
printToSpreadsheet); //Also writes into the Log
}//End 'if there are notes'
i = i+1;
}//End while loop
}
And I got this result.
https://lh3.googleusercontent.com/-d0yPFHLdRoI/VNRSEXn9MSI/AAAAAAAAAAk/gI5yhvSn0qY/s1600/ad%2Blabel%2Btest.JPG
Ads from 1-20 are successfully labeled but ads from 21 and beyond is
returning a result " ad not found"
I tried checking my campaign, ad group, and ads, It is all good so I don't
understand why it cannot find my ads.
Please help me, what do I need to do.
--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+:
https://googleadsdeveloper.blogspot.com/
https://plus.google.com/+GoogleAdsDevelopers/posts
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
You received this message because you are subscribed to the Google
Groups "AdWords API Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
---
You received this message because you are subscribed to the Google Groups
"AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
Visit this group at http://groups.google.com/group/adwords-api.
To view this discussion on the web visit
https://groups.google.com/d/msgid/adwords-api/6870b3f3-e537-4c9f-93c1-44ddec33a74e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.