Willkommen im DAIR Media Blog!

Unser Blog ist umgezogen. Sie finden alle aktuellen Beiträge unter: www.dair-media.net/blog/

Freitag, 24. Juli 2015

Labels in Accounts mit AdWords Script erstellen

Beim Verwalten von AdWords Account sind Labels ein sehr nützliches Hilfsmittel, um elemente wie Kampagnen, Anzeigengruppen, Anzeigen oder Keywords zu markieren, diese zu filtern oder entsprechende Berichte und andere Aktionen an mit Labels markierten Elementen auszuführen. Ein paar gute Beispiele für die Verwendung von Labels liefert Sascha Schmitz in seinem Blog.

Meistens werden immer wieder die gleichen Labels verwendet. Wer nun anfängt, in einem neuen AdWords Account zu arbeiten, muss alle Labels neu erstellen. Je nach Anzahl der Labels wird dies schnell mühselig. Der neue AdWords Editor (ab Version 11.1.2) schafft etwas Erleichterung, denn hier können Labels zwischen den Accounts kopiert werden. Allerdings muss hier immer noch jedes Acocunt einzeln aufgemacht und die Labels dann eingefügt werden. Schneller und flexibler funktioniert es mit einem AdWords Script.



Der Script ist ganz einfach zu handhaben: Ihr definiert die Labels, also Namen, ggf. Farbe und Beschreibung, und lässt den Script laufen. Dies funktioniert sowohl in einem Account als auch aus einem MCC heraus für mehrere verwaltete Account. In diesem Fall müssen nur die IDs der betroffenen Accounts und die Option für MCC-Nutzung auf 'true' gesetzt weden. Im Script-Code ist eine ausführliche Beschreibung nochmal enthalten.



/********************************************************************
* Account and MCC AdWords Script 'Label Creator'
* 
* @version: 1.1 - 2015-07-23
* @author: Alexander Gut | DAIR-Media.net
* 
* This Script creates set of labels for an AdWords Account.
* 
* Define labels to create in the AdWords account and run the script.
* Use JSON notation to define the labels array an use this notation:
*
* 'LABEL-NAME' : {'color': 'LABEL-COLOR', 'descr': 'LABEL-DESCRIPTION'}
*
* You can use these values:
* 
* LABEL-NAME: The name of the new Label. Label names are case sensitive
* and must be unique. Max length is 100 characters.
*
* LABEL-COLOR: (optional) The background color of the new label.
* The color must be specified in either RGB form (#RRGGBB or #RGB),
* or one of the 16 basic CSS color names:
* http://www.w3.org/TR/css3-color/#html4
*
* LABEL-DESCRIPTION: (optional) The description of the new label.
* If not specified, the description will be empty. Max length is
* 200 characters.
* 
* Please note: array keys 'color' and 'descr' schould not be changed.
* You can set default values for color and description for all labels.
*
*
* CHANGELOG:
* v1.1 - add optional MCC functionality to be able to create
*        new lables in multiple managed accounts at the same time
* v1.0 - initial release
*
********************************************************************/

var LABELS = {
   'watch': {'color': '#cc33cc'}, 
   'Brand': {'color': '#33cc00'},
   'Non-Brand': {'color': '#00cccc'},
   'deactivated': {'color': '#999999'},
   'paused': {'color': '#c0c0c0'}
   };

var LABELS_DEFAULT_COLOR = '';
var LABELS_DEFAULT_DESCR = '';


var USE_AS_MCC_SCRIPT = false;
var ACCOUNT_IDS = []; // array of strings with managed Account-IDs, e.g. ['111-111-1111', '222-222-2222']

function main() {

 if (USE_AS_MCC_SCRIPT && ACCOUNT_IDS.length > 0){
  var mccAccount = AdWordsApp.currentAccount();
  var accountIterator = MccApp.accounts().withIds(ACCOUNT_IDS).get();

  while (accountIterator.hasNext()) {
   var account = accountIterator.next();
   MccApp.select(account);
   Logger.log('START processing account %s', account.getCustomerId());
   createLabels();
   Logger.log('DONE processing account %s', account.getCustomerId());
  }
 }
 else {
  createLabels();
 }
 
}

function createLabels(){
 for (var lbl in LABELS){
  var newLabelName = lbl;
  var newLabelColor = LABELS[lbl]['color'] || LABELS_DEFAULT_COLOR;
  var newLabelDescr = LABELS[lbl]['descr'] || LABELS_DEFAULT_DESCR;
  
  // Try to get label first to prevent exception createing the same label name.
  var labelIterator = AdWordsApp.labels().withCondition("Name = '" + newLabelName + "'").get();
  if(!labelIterator.hasNext()){
   if (!AdWordsApp.getExecutionInfo().isPreview()) { // dont't really create label if script is in preview mode
    AdWordsApp.createLabel(newLabelName, newLabelDescr, newLabelColor);
   }
   Logger.log("New Label '" + newLabelName + "' with color '" + newLabelColor + "' and description '" + newLabelDescr + "' have been created.");
  }
  else{
   Logger.log("Label '" + newLabelName + "' was already in account.");
  } 
 }
}



Fragen zu diesem AdWords Script oder Verbesserungsvorschläge? Einfach unsere AdWords Agentur kontaktieren oder hier in Kommentaren posten. Wir freuen uns auf Feedback.

Keine Kommentare:

Kommentar veröffentlichen