1

Ok, this may be quite the "what are you actually asking" question so bear with me a bit. As a rule, I'm a .NET and SQL developer. I'm working with AWQL trying to get an adwords script to make a tailored report. Short version, I need to pull from separate date ranges and I'm having issues figuring out how the "compiler" they have deals with it or if even possible to do. In a nutshell I need the data from two months separately compiled into one report. Right now I'm thinking syntax error, but not sure. End goal in geek terms is to the effect of "WHERE(IMPRESSIONS_FROM_THIS_MONTH > IMPRESSIONS_FROM_LAST_MONTH) AND (IMPRESSIONS_FROM_LAST_MONTH > MONTH_BEFORE_THAT). In theory all in the same output (don't care if it's logger or straight to a google doc. I do have the code to put this into a spreadsheet and email me the link), but currently struggling to get it to pull the data. And by struggling I mean a few days of failing lol.

"SELECT KeywordText, ConversionValue, Id, QualityScore " +
  "FROM KEYWORDS_PERFORMANCE_REPORT " +
   "WHERE " +
   "Id = " + kw +
   " AND CampaignId = " + id +
   " AND AdGroupId = " + gName +
   " AND Impressions" +
   " (DURING 20150101, 20150131) > IMPRESSIONS (DURING 20141201, 20141231)" );             

(the variables like gName are there in the full code btw and working until I try compound logic) I'm not sure if the best approach is to query it all at once, or to query separately and somehow splice the results into a single report. AdWords scripting seems to be a lot more restricted than I'm used to and some of the rules it has aren't well documented or explained. Any links or code chunks relevant to this anywhere? Thanks in advance for any help!

4

1 回答 1

1

This piece of code should help. Replace all variables as fit for your purpose.

var daterange1 ="Specify daterange here";
var dateRange2 ="Specify daterange here"; 
    function main(){      
      var sheet = getSheet();
      var AccountIterator = MccApp.accounts().forDateRange(dateRange).withIds(ACCOUNTS).get();
      while(AccountIterator.hasNext()){
        var Account = AccountIterator.next();


        MccApp.select(Account);
            getAccountDetails(sheet);
            getAccountDetails2(sheet)

          }

    }



       function getAccountDetails(sheet){
          var query = "SELECT  Device, CampaignName, ConversionValue, Cost, Conversions " +" FROM CAMPAIGN_PERFORMANCE_REPORT " +"WHERE Impressions > 0 " +" DURING "+dateRange;
          Logger.log(query);
          var report = AdWordsApp.report(query);
          report.exportToSheet(sheet);
        }

    function getAccountDetails2(sheet){
          var query = "SELECT  Device, CampaignName, ConversionValue, Cost, Conversions " +" FROM CAMPAIGN_PERFORMANCE_REPORT " +"WHERE Impressions > 0 " +" DURING "+dateRange;
          Logger.log(query);
          var report = AdWordsApp.report(query);
          report.exportToSheet(sheet);
        }

        function getSheet(){
          var spreadsheet = SpreadsheetApp.openByUrl(url);
          var sheet=spreadsheet.setActiveSheet(spreadsheet.getSheets()[0]);

      return sheet;
    }

I am not optimizing it as it will be a good exercise to do it by yourself. But this will solve your problem.

于 2015-02-17T08:53:32.663 回答