Labels on my ads

75 views
Skip to first unread message

kalipa...@gmail.com

unread,
Feb 4, 2015, 3:39:13 AM2/4/15
to adwor...@googlegroups.com

Hi,

So I want to put labels on my ads..  I have a lot of ads so manual is not a good solution for me.
I tried using a script I found from the net and it was not very successful.


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
}


This is the result I am getting

https://lh4.googleusercontent.com/-7FmryFnLj04/VNHYq5LzuxI/AAAAAAAAAAU/1pnZeyIkvsM/s1600/ad%2Blabel%2Btest.JPG


All ad labels are added from 1 - 19 but from 20 and beyond I am getting this "ad not found" note
Checking the campaign, adgroups and ads, it is all correct and I just don't understand why this is happening.

Do I need to change something on the script?

I found that script here

{http://white.net/blog/label-keywords-ads-bulk-adwords-script/}



Anash P. Oommen (AdWords API Team)

unread,
Feb 4, 2015, 9:25:30 AM2/4/15
to adwor...@googlegroups.com
Hi,

Could you please repost on the AdWords Scripts forum? 

Cheers,
Anash P. Oommen,
AdWords API Advisor.
Reply all
Reply to author
Forward
0 new messages