5 messages in com.googlegroups.adwords-apiRe: Retrieval of last day of activity
FromSent OnAttachments
Jesper Ellegaard26 Sep 2007 03:15 
Reed27 Sep 2007 05:14 
Jesper Ellegaard28 Sep 2007 02:03 
Tim Cadell28 Sep 2007 09:13 
Jesper Ellegaard30 Sep 2007 02:00 
Subject:Re: Retrieval of last day of activity
From:Reed (pow@nauticom.net)
Date:09/27/2007 05:14:57 AM
List:com.googlegroups.adwords-api

It sounds like you want to use the ReportService API calls rather than the CampaignServicecalls. The keyword performance reports only include the keywords that had activity during the time period.

On Sep 26, 6:16 am, Jesper Ellegaard <j.@netminers.dk> wrote:

Does the API have a method for retrieval of the last day of activity of a given campaign, group or ad, i.e. which day was an impression last made?

This information is very useful when you what to retrieve e.g. daily historic stats, and don't want to query too many zero-stats.

If such a method does not exists, I would suggest the following recursive function (C#) to get the information in the fewest possible API requests:

private DateTime getLastActivityDate(DateTime startDate, DateTime endDate, Int64 lastImp) { int range = ((TimeSpan)endDate.Subtract(startDate)).Days + 1; //calc days in ragne if ((!campaign.startDaySpecified && range > 1000) || (campaign.startDaySpecified && campaign.startDay > endDate)) //look no further back than campaign start date or a maximum range of 1000 days return DateTime.MinValue.AddDays(1); //add 1 day to allow substracting 1 day (to find last complete day)

Int64 imp = CampaignService.getCampaignStats(idArray, startDate, endDate)[0].impressions; //query count in range services.queryStat++;

//System.Diagnostics.Debug.WriteLine(startDate + " -> " + endDate + " : " + range + " imp: " + imp); if (imp == 0) { // if no imp found, we search backwards endDate = startDate.AddDays(-1); // going backwards, last date is allways day before last startdate if (lastImp == 0) startDate = endDate.AddDays(-(range * 2 - 1)); // if no imp found last time, nothing is found yet, thus expand range else { if (range==1) return startDate.AddDays(-1); // imp has been seen before and range is down to 1, i.e. right date must be the one before current else { startDate = endDate.AddDays(-(range / 2 - 1)); // look in last half of range imp = -1; // signal further on that imp has been seen } } } else { //imp found, search forward if (range == 1) return startDate; //but if range is down to 1, we already got it else startDate = startDate.AddDays(range / 2); //else look in last half of range (i.e. keep enddate) } return getLastActivityDate(startDate, endDate, imp); // recursive call

}

Call it with getLastAvtivityDate(DateTime.now, DateTime.now, 0) - or what ever date you guess would be a good starting point for searching backwards. The relevant Campaign object should be placed in the global "campaign" object.

/Jesper