1
votes

I am having trouble getting the filter to work. I want to be able to get all the visits to this page. I was wondering not only how to get the filter to work, but also the start date. I would like to see how to make it page specific as well as not limited by the date. Thanks!

function Update() {
    try {
      var api = Analytics.Data.Ga.get(
           "ga:162531584", // Table id (format ga:xxxxxx).
           "forever?",    // Start-date (format yyyy-MM-dd).
           "yesterday",    // End-date (format yyyy-MM-dd).
           'ga:pageviews',  // Comma seperated list of metrics.
           'filters=ga:pagePath==/downloads/IAU.php;'
       );
        var sheet = SpreadsheetApp.getActiveSheet();
        sheet.getRange(1, 1).setValue(api.rows[0][0]);
    } catch(error) {
        Browser.msgBox("Failed To Get Statistics!\r\n" + error);
    }
}
1

1 Answers

1
votes

It looks like you are calling Analytics.Data.Ga.get() incorrectly. The proper way to do it is:

   var api = Analytics.Data.Ga.get(
       'ga:162531584', // Table id (format ga:xxxxxx).
       '2005-01-01',   // Start-date (format yyyy-MM-dd).
       'today',        // End-date (format yyyy-MM-dd).
       'ga:pageviews', // Comma seperated list of metrics.
       {
         'dimensions': 'ga:pagePath',
         'filters': 'ga:pagePath==/downloads/IAU.php'
       }
   );

The key changes here are:

  • Dimensions, filters, etc. need to be passed in an object to Analytics.Data.Ga.get()
  • Declare dimensions that you want returned in the report
  • Date parameters (see below)

If you want your reporting period to show "all time" data, the easiest thing to do is to set your:

  • start date to the earliest valid start-date which is 2005-01-01 [reference]
  • end date to today