Tuesday, July 30, 2013

Figuring Out When Your Ad, AdGroup, Keyword, or Campaign Was Created

Knowing when an Ad (or entity) was created is impossible using scripts. That information is simply not tracked in AdWords. The next best thing is to find out when your Ad first started receiving impressions and assume that is when it was created (If an Ad is created but no one sees it, does it really exist?).

So in order to help me keep track of when my Ads entities were created, I put together the following script to apply labels to my Ads entities with the date of the first impression. That way, I can find out what ads entities I created and make sure I don't take action on anything that is too young. I can also make changes to all the ads entities built on a given day relatively easily in the AdWords UI by just selecting the right label.

Thanks,
Russ



/**************************************
* Track Entity Creation Date
* Version 1.4
* Changelog v1.4
*  - Removed apiVersion from reporting call
* Changelog v1.3
*  - Updated script to handle all entities
* Changelog v1.2
*  - Fixed an issue with comparing dates
* ChangeLog v1.1
*  - Updated logic to work with larger accounts
* Created By: Russ Savage
* http://www.FreeAdWordsScripts.com
**************************************/
//All my labels will start with this. For example: Created:2013-05-01
var LABEL_PREFIX = 'Created:';
var DAYS_IN_REPORT = 30;
var ENTITY = 'ad'; //or adgroup or keyword or campaign
 
function main() {
  //First we get the impression history of our entity
  var ret_map = getImpressionHistory();
  //Then we apply our labels
  applyLabels(ret_map);
}
 
//Function to apply labels to the ads in an account
function applyLabels(ret_map) {
  var iter;
  if(ENTITY === 'campaign') { iter = AdWordsApp.campaigns().get(); }
  if(ENTITY === 'adgroup') { iter = AdWordsApp.adGroups().get(); }
  if(ENTITY === 'ad') { iter = AdWordsApp.ads().get(); }
  if(ENTITY === 'keyword') { iter = AdWordsApp.keywords().get(); }
  
  while(iter.hasNext()) {
    var entity = iter.next();
    var id = entity.getId();
    if(ret_map[id]) {
      var label_name = LABEL_PREFIX+Utilities.formatDate(ret_map[id], AdWordsApp.currentAccount().getTimeZone(), "yyyy-MM-dd");
      createLabelIfNeeded(label_name);
      entity.applyLabel(label_name);
    }
  }
}
 
//This is a helper function to create the label if it does not already exist
function createLabelIfNeeded(name) {
  if(!AdWordsApp.labels().withCondition("Name = '"+name+"'").get().hasNext()) {
    AdWordsApp.createLabel(name);
  }
}
 
//A helper function to find the date days ago
function getDateDaysAgo(days) {
  var the_past = new Date();
  the_past.setDate(the_past.getDate() - days);
  return Utilities.formatDate(the_past,AdWordsApp.currentAccount().getTimeZone(),"yyyyMMdd");
}
 
//A helper function to compare dates.
//Copied from: http://goo.gl/uW48a
function diffDays(firstDate,secondDate) {
  var oneDay = 24*60*60*1000; // hours*minutes*seconds*milliseconds
  return Math.round(Math.abs((firstDate.getTime() - secondDate.getTime())/(oneDay))); 
}
 
function getImpressionHistory() {
  var API_VERSION = { includeZeroImpressions : false };
  var first_date = new Date('10/23/2000');
  var max_days_ago = diffDays(first_date,new Date());
  var cols = ['Date','Id','Impressions'];
  var report = { 
    'campaign' : 'CAMPAIGN_PERFORMANCE_REPORT',
    'adgroup' : 'ADGROUP_PERFORMANCE_REPORT',
    'ad' : 'AD_PERFORMANCE_REPORT',
    'keyword' : 'KEYWORDS_PERFORMANCE_REPORT'}[ENTITY];
  var ret_map = {};
  var prev_days_ago = 0;
  for(var i = DAYS_IN_REPORT; i < max_days_ago; i+=DAYS_IN_REPORT) {
    var start_date = getDateDaysAgo(i);
    var end_date = getDateDaysAgo(prev_days_ago);
    var date_range = start_date+','+end_date;
    Logger.log('Getting data for ' + date_range);
    var query = ['select',cols.join(','),'from',report,'during',date_range].join(' ');
    var report_iter = AdWordsApp.report(query, API_VERSION).rows();
    if(!report_iter.hasNext()) { Logger.log('No more impressions found. Breaking.'); break; } // no more entries
    while(report_iter.hasNext()) { 
      var row = report_iter.next();
      if(ret_map[row['Id']]) {
        var [year,month,day] = (row['Date']).split('-');
        var from_row = new Date(year, parseFloat(month)-1, day);
        var from_map = ret_map[row['Id']];
         
        if(from_row < from_map) {
          ret_map[row['Id']] = from_row;
        }
      } else {
        var [year,month,day] = (row['Date']).split('-');
        ret_map[row['Id']] = new Date(year, parseFloat(month)-1, day);
      }
    }
    prev_days_ago = i;
  }
  return ret_map;
}

59 comments:

  1. It’s amazing in support of me to truly have a web site that is valuable meant for my knowledge.

    ReplyDelete
  2. Niche revises position very seriously 90Per cent in our enterprise and why we certainly have in no way essentially exposed our system for the community.https://bizzebee.com/4-simple-seo-tips-for-new-bloggers/ Establish Links of our website - the audience will probably be open up for your personal temporary, until lastly finally we fulfill track of up by including more quite a bit ranges customers accessible

    ReplyDelete
  3. who made the product even offered to set everything up for me for $10 bucks (ideal for me!), so I was following in like 5 minutes. Backlinks service

    ReplyDelete
  4. In keyword research I use the broad match because it will yield the largest number of keyword ideas from which to harvest final keyword gems.google keyword wrapper

    ReplyDelete
  5. Seo firm inside had been large together with his time, while we put in hrs going through the requirements my business in addition to what choosing a company steps browse around here. He's very professional in addition to reputable. Advocate finest search engine marketing into the nearby organization that is looking for.

    ReplyDelete
  6. I have installed the script. It is running, enabled, green icon lighting. But I don´t see the label anywhere. I looked for a colummn Labels, but didn´t find. Please help me. It is my first script I have ever used.

    ReplyDelete
  7. who made the product even offered to set everything up for me for $10 bucks (ideal for me!), so I was following in like 5 minutes.
    field technician job description

    ReplyDelete
  8. Each of the handsets connected with the base unit also has its own speakerphone, so just at the touch of a button, you can enjoy hands-free conversation while you are cooking or doing something else.

    Cordless Phones For Senior

    ReplyDelete
  9. The product has delighted both end users and internal stakeholders. Due to their effective project management and the experience of user experience design agency team they has been able to deliver a high-quality app within a reasonable timeframe. Their professionalism and transparency set them apart.

    ReplyDelete
  10. I appreciate the time you’ve taken out to show me the ropes and ensure that I have the required knowledge to do a great job. Thank you.
    read more

    ReplyDelete
  11. We are a certified troubleshooting guide, available round the clock to provide the best technical support or specialized technical assistance for canon printer users. We work online with live technical support team to help all frustrated canon printer users. If your canon printer has stopped working or showing canon printer not responding issue, our canon support team is very dedicated to solve this error simply. Our canon printer troubleshooting team has the great skills and extensive experience for solving canon printer not printing problem within a few seconds. Our live technical support team is ready to provide quick help for any issues.

    ReplyDelete
  12. We are the simplest , successful, and self-governing third party QuickBooks support provider, which is providing unlimited QuickBooks support services for all frustrated QuickBooks in very nominal charges. once you plan to open a corporation file not located on another computing system , you'll undergo QuickBooks Error H505. This error code is an annoying error, which can't be resolved easily. This error code appears when QuickBooks company file needs some extra configuration. If you're experiencing this error code again and again, you'll call our QuickBooks professionals to urge the specialized assistance for solving this error code simply. So now, you'll enjoy the simplest services with QuickBooks excellently.

    ReplyDelete
  13. Perfect piece of work you have done, this website is really cool with wonderful information.
    Feel free to visit my web blog: Movie reviews - Movie Laundry provides info on movies, movie reviews, ratings, cast and crew details of movies. Get updated movie reviews from movie Laundry.checkout their works at- movielaundry





    ReplyDelete
  14. It has been just unfathomably liberal with you to give straightforwardly what precisely numerous people would've promoted for an eBook to wind up making some money for their end, basically given that you could have attempted it in the occasion you needed.
    CRM with Invoicing

    ReplyDelete
  15. Thankfulness to my dad who informed me relating to this blog, this website is really amazing.
    weblink

    ReplyDelete
  16. Get ready to boost your business with a strong online presence. Hire India’s most trusted online website development company and get instant quotes. 100% Customer Satisfaction. 1000+ Dynamic Website Designs with built-in SEO. Mobile friendly. Top-notch technology. 24*7 Technical support and much more. Reach us now!

    ReplyDelete
  17. Thanks for compiling such nicest information in your blogs. Articles are very informative and hope again I’ll find more like that.
    web design companies

    ReplyDelete
  18. Great job for publishing such a beneficial web site. Your web log isn’t only useful but it is additionally really creative too. 100 high quality backlinks for $2

    ReplyDelete
  19. Hi to all, the blog has really the dreadful information I really enjoyed a lot.
    UI design company

    ReplyDelete
  20. Sometimes you don’t have time to complete your assignment before deadlines. And due to late submission you can’t get full marks, if you are looking help for completing your assignment then you can contact us. We are providing Online assignment help and we have a team of professional’s academic writers who are more eligible to complete your assignments on time and accurate. For more information visit our website or call us on or Toll free numbers.

    ReplyDelete
  21. The creative minds of Brandphic provide innovative solutions for your business identity and recognition among the audiences. We ensure to make your journey ecstatic by demonstrating our work of art with enthusiasm and determination. branding package

    ReplyDelete
  22. Generally I don't learn post on blogs, but I would like to say that this write-up very pressured me to try and do it!
    Your writing style has been surprised me. Thanks, very great post.
    Cash for Cars Melbourne
    We Buy Cars

    ReplyDelete
  23. The tutorial is very helpful for a first timer like me, by the way if you could have given a tutorial on creating a free website, it would have been very helpful for newbies like me.
    Thank you
    Cash for Unwanted Cars
    Places that Buy Old Cars

    ReplyDelete
  24. Have you ever try online services of Assignment Help even in Malaysia? Are you thinking about the reliability of online services in academic writing? If you have the same questions in your mind, you have to place an order for online services of assignment writing.
    Assignment Helper
    Assignment Help Online

    ReplyDelete
  25. Hello There. I found your blog using msn. This is a really well written article. I will make sure to bookmark it and come back to read more of your useful information. Thanks for the post. I will definitely return.
    Cash for cars Sydney
    cash for scrap cars

    ReplyDelete
  26. Hello There. I found your blog using msn. This is a really well written article. I will make sure to bookmark it and come back to read more of your useful information. Thanks for the post. I will definitely return.
    Car Removal Brisbane
    Cash for Cars Beenleigh

    ReplyDelete
  27. Hey there! I know this is kind of off topic but I was wondering if you knew where I could get a captcha plugin for my comment form? I'm using the same blog platform as yours and I'm having trouble finding one? Thanks a lot!
    Cash for Cars Brisbane
    Cash for Cars Gold Coast

    ReplyDelete
  28. Thanks, foг ones marvelous posting! I genuinely enjoyed reading it, you miggһt Ƅe a great author. I wiⅼl made certain to booҝmark your blog and ѡill often come back sometime soon. I want to encoᥙrage yourself to continue your great job, have a nice evening!
    Cars for Cash Ipswich
    Cars for Cash Brisbane

    ReplyDelete
  29. Wow, that was strange. I just wrote a really long comment but after I clicked submit my comment didn't show up. Grrrr... well, I'm not writing all that over again. Anyways, just wanted to say fantastic blog!
    cash for cars gold coast
    car removal gold coast

    ReplyDelete
  30. Great post. I used to be checking constantly this weblog and I am inspired! Extremely useful information specially the ultimate part :) I maintain such info much. I used to be seeking this particular information for a very lengthy time.
    cash for cars adelaide
    car removal adelaide

    ReplyDelete
  31. Hi This is Noah Dabbler, It is really eye opening post, thanks for sharing it with us, To know more like this type of informative content please visit :FourCreeds

    ReplyDelete
  32. Unique Submission is the most trusted online university assignment help service available today.
    We help students efficiently in completing their due assignments.
    The most distinct feature we offer as a leading assignment help website is confidentiality as customer’s privacy and
    security is of utmost importance to us.


    Assignment Helpers Online

    ReplyDelete
  33. Thanks for posting such an awesome post. to know more visit FourCreeds

    ReplyDelete
  34. Thank you for this use Full Post!

    as it contains a lot of information. I always prefer to read the quality content and this thing I found in you post. Thanks for sharing. https://godsofseo.com/


    Guest Posting Sites
    Guest Posting Site
    Guest Posting Websites
    Forum Submission Sites
    Forum Submission
    Forum Posting Sites
    Forum Submission List
    Forum Posting
    Video Submission Sites
    High PR Video Submission Sites
    Video Sharing Website
    Web 2.0 Sites
    Web 2.0 Sites List
    Best Web 2.0 Sites for Backlinks
    Web 2.0 Submission
    Question and Answer Websites
    Question and Answer Sites List
    Question and Answer Sites
    Question and Answer Sites for SEO

    ReplyDelete
  35. Very Nice Post ...I always prefer to read the quality content and this thing I found in you post. Thanks for sharing. https://www.victoriasecretgiftcardbalance.com/

    Victoria Secret Check Balance
    Victoria Secret Gift Card Balance
    Check Victoria's Secret Gift Card Balance
    Victoria Secret Card Balance
    Check Victoria's Secret Gift Card Balance
    Check Victoria's Secret Card Balance

    ReplyDelete
  36. I am gonna share your post on social media.
    Data warehouse India

    ReplyDelete
  37. I haven’t any word to appreciate this post.....Really i am impressed from this post....the person who create this post it was a great human..thanks for shared this with us. backlinks

    ReplyDelete
  38. All these tips and tricks are helpful for those who have some kind of skills in writing and meet some kind of assistance but it is pointless for those who couldn't write a single paragraph on their own taking cheap paper writing service is the last and best choice for those students because they well-written paper according to the requirements. that's why i only trust helpinhomework.org. Their service and study material are very reliable, you must also try. help in homework

    ReplyDelete
  39. This blog is so nice to me. I will keep on coming here again and again. Visit my link as well.. family relationship

    ReplyDelete
  40. Good blog.Are you also searching for Help With My Nursing Paper? we are the best solution for you. We are best known for delivering nursing writing services to students without having to break the bank.

    ReplyDelete
  41. Good blog. Keep sharing. I love them Are you also searching for Cheap assignment writers? we are the best solution for you. We are best known for delivering nursing writing services to students without having to break the bank

    ReplyDelete
  42. This is quite a good blog.Are you also searching for Nursing Research Paper Help? we are the best solution for you. We are best known for delivering nursing writing services to students without having to break the bank.

    ReplyDelete
  43. Appreciating the time and effort you put into your website and the thorough information you present. It’s amazing to come across a site every now and then that is not the similar old re-written material. Excellent read! We’ve bookmarked your site. Regards cash for cars gold coast

    ReplyDelete
  44. Professional and friendly service anywhere in Brisbane cash for car including North, West, East, and Southside. Make a deal and sell your vehicle in seconds with or without rego or roadworthy.

    ReplyDelete