marți, 22 iulie 2014

Label Keywords and Ads in Bulk with an AdWords Script

Label Keywords and Ads in Bulk with an AdWords Script

Link to White.net

Label Keywords and Ads in Bulk with an AdWords Script

Posted: 22 Jul 2014 01:55 AM PDT

Last month I had an AdWords Script for bulk labelling ad groups – here's a similar one to label keywords and creative. Now you can cover everything in your account in labels, until it looks like an explosion in a post-it factory!

There are many reasons to label keywords: to keep track of different types of term (like ‘Cheap’ or ‘Branded’); to monitor keywords of questionable performance; to see the effects of bid changes; or just when you've added a new batch and want to keep track of where they are.

And labelling ads makes it much easier to test similar ad text or different landing pages over multiple ad groups. Or you could label seasonal ads so you know when they need to be activated or paused. Or if you're working in multiple languages, you could use labels to give a translation.

Keywords

Set up a Google Doc spreadsheet like this:

KW Labels Google Doc 1

If you copy in broad match modified keywords that begin with a +, the Google Doc will try to read them as a formula rather than a string and give a '#NAME?' error. To get around this, add a space in front of the first + (the Script will trim the keyword text, so the extraneous space will be ignored). Alternatively put an ‘ in front first to show it's a string not a formula.

Create a new Script and paste this in:

function main() {
// Applies labels to specified keywords, 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/EXAMPLE/edit?usp=sharing";

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("F"+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 labelKeywordText = inputSheet.getRange("C" + i).getValue().trim();
var labelMatchType = inputSheet.getRange("D" + i).getValue().trim().toUpperCase();
var labelText = inputSheet.getRange("E" + 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)

if (labelMatchType == "BROAD" || labelMatchType == "PHRASE" || labelMatchType == "EXACT") //Checks the match type is valid
{
var keywordIterator = AdWordsApp.keywords() //Finds the keywords with the specified name and campaign name
.withCondition("CampaignName = '" + labelCampaignName + "'")
.withCondition("AdGroupName = '" + labelAdGroupName +"'")
.withCondition("Text = '" + labelKeywordText +"'")
.withCondition("KeywordMatchType = " + labelMatchType)
.get();

if (keywordIterator.hasNext()) //If there is a keyword then the label will be applied
{
var keyword = keywordIterator.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
}

keyword.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 = "Keyword not found"; //An error message will be recorded in the spreadsheet.
}

}//End 'if valid match type'

else //If match type isn't valid
{
printToSpreadsheet = "Match type invalid"; //An error message will be recorded in the spreadsheet.
}

inputSheet.getRange("F" + i).setValue(printToSpreadsheet); //Writes into the Notes column in the spreadsheet
Logger.log("Label " + labelText + " applied to '" + labelKeywordText + "' in '" + labelAdGroupName + "', '"+ labelCampaignName +"': " + printToSpreadsheet); //Also writes into the Log

}//End 'if there are notes'

i = i+1;

}//End while loop
}

Once it's authorised and run, you should see the changes in your account and the notes filled into your doc:
KW Labels Google Doc 2

If it says 'Match Type Invalid' make sure the match is spelt right. If it says 'Keyword not found' that could be a typo in any of the other columns.

Notes:

  • Capitalisation matters for nearly everything.
  • Capitalisation doesn't matter for match type (and there can be a space in front of the word) – but it has to be 'exact', 'broad' or 'phrase'. You can't use negative match.
  • If you look in the Script logs you may see errors saying "You're already using this label name". These don't matter.
  • Having said that, the Script checks to see if the current label is the same as the last label it added. So if you order by the label's text it should make things a little more efficient, and reduce the "already using this label" errors.
  • If the Script times out before it can label everything, run it again. It will ignore the keywords it’s already done.
  • But that means you can’t have anything in the ‘Notes’ column of the spreadsheet – if there’s anything in there then the Script assumes that line has been done, and moves on to the next line.

Ads

Again, set up a Google Doc spreadsheet.

Ad Labels Google Doc 1

And use this 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/EXAMPLE/edit?usp=sharing";

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
}

The results:

Ad Labels Google Doc 2

Notes:

  • Capitalisation matters for everything. (This is very useful if your ads are testing Title Case against sentence case!)
  • Like with the keywords, the Script logs may have errors saying "You're already using this label name", and it's best to order the ads by label test.

If you've got any questions or improvements, please comment below!

Image credit: Brainstorms at INDEX: Views by Jacob Bøtter.

The post Label Keywords and Ads in Bulk with an AdWords Script appeared first on White.net.

Niciun comentariu:

Trimiteți un comentariu