Getting analytics for the site

Each night I run a scheduled task which takes the Google Analytics data for this Google Sites and matches it up to the site pages. At the time of writing I have 1000 different pages in analytics to match to 500 pages on this site. 

The code is pretty straightforward, and will clean up the result of an analytics query and place it in a nicely formatted object. As usual I'm using exponential backoff to avoid rate limiting problems.


I call this for each time period in my report - I'm going for the past month, the past year, and all time - and then match up the analytics with the each page on the site.

  // create a set of analytics for each of these periods
  options.periods.forEach ( function(d,i) {
    // now get the analytics data - for each period
    matchAnalytics ( getAnalytics(options.propertyId,d.start,d.end) , root, site.getUrl(),i);
  });

This returns an array of objects like this - notice how the urls have spelling mistakes to deal with in the matching process.

{"pagePath":"/Home/excelquirks/classeslink/data-manipulation-classes/data-abstraction","pageViews":"2128"},
{"pagePath":"/Home/excelquirks/classeslink/data-manipulation-classes/goog_282824596","pageViews":"10"},
{"pagePath":"/Home/excelquirks/classeslink/data-manipulation-classes/howtocdatase","pageViews":"1"},
{"pagePath":"/Home/excelquirks/classeslink/data-manipulation-classes/howtocdataset","pageViews":"3437"},
{"pagePath":"/Home/excelquirks/classeslink/data-manipulation-classes/howtocdataset/cdatasetdatamodel","pageViews":"939"},


For help and more information join our forum,follow the blog or follow me on twitter .



Comments