Monday, November 26, 2012

Update Ads for the New Year

This is a companion to one of my earlier posts about updating your keywords for the new year.  You can easily run through each ad you have and update them all for the new year using the script below.  It will also pause the old ad as well, making sure your staying relevant to your customers.  You should schedule this to run every year on January 1st if your advertising relies heavily on dated traffic.

Thanks,
Russ

//-----------------------------------
// Update Ads for 2012
// Created By: Russ Savage
// FreeAdWordsScripts.com
//-----------------------------------
function main() {
  var OLD_YEAR = "2011";
  var NEW_YEAR = "2012";
  //You probably shouldn't update destination urls unless you know what you are doing.
  var FIELDS_CONTAINING_YEAR = ["Headline","Description1",
                                "Description2","DisplayUrl"
                                /*,"DestinationUrl"*/
                               ];
  
  for(i in FIELDS_CONTAINING_YEAR) {
    var field_iter = AdWordsApp.ads()
        .withCondition(FIELDS_CONTAINING_YEAR[i] + " CONTAINS " + OLD_YEAR)
        .withCondition("Status = ENABLED")
        .get();
    
    _iterateThroughAds(field_iter);
  }

  //---------------
  // Private Helper Functions
  //---------------  
  function _iterateThroughAds(ad_iter) {
    while (ad_iter.hasNext()) {
      var ad = ad_iter.next();
      var ag = ad.getAdGroup();
      _createNewAdFromOldAd(ag,ad);
    }
  }
  
  function _createNewAdFromOldAd(adgroup, old_ad) {
    //get the updated ad texts replacing all the old years with the new years
    var new_headline = old_ad.getHeadline().replace(OLD_YEAR,NEW_YEAR);
    var new_desc1 = old_ad.getDescription1().replace(OLD_YEAR,NEW_YEAR);
    var new_desc2 = old_ad.getDescription2().replace(OLD_YEAR,NEW_YEAR);
    var new_display_url = old_ad.getDisplayUrl().replace(OLD_YEAR,NEW_YEAR);
    var new_dest_url = old_ad.getDestinationUrl();/*.replace(OLD_YEAR,NEW_YEAR);*/
    
    //now create the new ad and pause the old one.
    adgroup.createTextAd(new_headline,new_desc1,new_desc2,new_display_url,new_dest_url);
    old_ad.pause();
  }
}

15 comments:

  1. Yes, I can show you how to write an essay about yourself. Just have a peek here https://justdomyhomework.com/blog/essay-about-yourself

    ReplyDelete
  2. Psychology Coursework Writing Services has become a significant challenge owing to the complexity of Psychology Research Writing Services and in other cases lack of time and knowledge needed to prepare Online Psychology Assignment Writing Services .

    ReplyDelete
  3. Engineering assignment writing services are essential for college & university engineering research paper services seekers and Engineering Writing Services.

    ReplyDelete




  4. Wonderful information! I found amazing information on the blogs i suggest everyone to follow the links below to get download files from this website.



    https://apkfasak.com/fmwhatsapp-apk/
    https://apkfasak.com/gb-whatsapp-apk/




    ReplyDelete
  5. Nice post. I learn something totally new and challenging on websites I stumble upon every day. It's always useful to read through articles from other authors and practice something from other sites.also try this WhatsApp Plus Apk.

    ReplyDelete
  6. This is pretty informative. You can also check this messaging app mod that I found :

    https://flosshype.com/fmwhatsapp/

    ReplyDelete
  7. Download thoptv for pc download – Latest version – Free for Android and watch the latest films and tv shows for free! Enjoy unlimited streaming now in this awesome app!

    ReplyDelete
  8. It is important for neurobiology coursework writing help seekers to find the best Neurobiology Writing Services from a reputable neurobiology research paper writing service provider for their custom neurobiology essay writing services.

    ReplyDelete