This one is deprecated since the demise of Gadgets on sites.
I used to abstract all database matters away from Google Apps Script with Database abstraction with google apps script. The scheduled analytics update wrote the matched site page and analytic data to an abstracted database. At the time of writing, I happened to be using Driver MongoLab.
Once the Matching the site tree to the analytics data was complete, the data needed to be flattened from a tree object so we could create a row per site page. This page was later retrieved by the gadget which created the visual representation of that page’s analytics.
That was achieved in this step
// combine the topic and page data
  var tood = combine(topics,topics);
  
  // commit
  refreshDb ( options, tood);

The database parameters are defined in Storing options and parameters and accessed from that library. This means that multiple projects can use synchronised parameters for the same data.

/** 
 * refreshDb
 * @param {object} options with properties needed to open a dbabstraction database
 * @param {Array.object} pages and array of pages with their stats;
 */
function refreshDb (options,pages) {
  
   // whatever the normal database is
   var handler = cSiteStats.getDataHandle(options.siteCode);
  
  if (!handler.isHappy()) throw 'unable to get handler' + JSON.stringify(options);
      
  // delete all thats there
  var result  = handler.remove();
  if (result.handleCode < 0) throw result;
  
  //save
  var result = handler.save(pages);
  if (result.handleCode < 0) throw result;
  
}

The data stored for each page will look something like this, and will be indexed in the client gadget using page.url.

{
    "_id": {
        "$oid": "543011a6e4b0dbebfeff60af"
    },
    "topic": {
        "url": "https://ramblings.mcpher.com/excel-to-json-and-back/",
        "numChildren": 0,
        "analytics": [
            {
                "varieties": 32,
                "name": "Past Month",
                "pageViews": 6461,
                "favorite": "https://ramblings.mcpher.com/get-started-snippets/",
                "favoriteTitle": "Get Started Snippets",
                "universe": 73,
                "rank": 1
            },
            {
                "varieties": 49,
                "name": "Past Year",
                "pageViews": 88844,
                "favorite": "https://ramblings.mcpher.com/excel-to-json-and-back/",
                "favoriteTitle": "jSon",
                "universe": 73,
                "rank": 0
            },
            {
                "varieties": 77,
                "name": "All Time",
                "pageViews": 210390,
                "favorite": "https://ramblings.mcpher.com/excel-to-json-and-back/",
                "favoriteTitle": "jSon",
                "universe": 73,
                "rank": 0
            }
        ],
        "name": "json",
        "title": "jSon",
        "plusOnes": 107
    },
    "page": {
        "url": "https://ramblings.mcpher.com/excel-to-json-and-back/rest-to-excel-library/json-arrays-of-objects/",
        "numChildren": 0,
        "pageType": 4,
        "analytics": [
            {
                "varieties": 1,
                "name": "Past Month",
                "pageViews": 28,
                "favorite": "https://ramblings.mcpher.com/excel-to-json-and-back/excel-json-conversion/",
                "favoriteTitle": "Excel JSON conversion",
                "universe": 33,
                "rank": 16
            },
            {
                "varieties": 1,
                "name": "Past Year",
                "pageViews": 277,
                "favorite": "https://ramblings.mcpher.com/excel-to-json-and-back/excel-json-conversion/",
                "favoriteTitle": "Excel JSON conversion",
                "universe": 33,
                "rank": 21
            },
            {
                "varieties": 1,
                "name": "All Time",
                "pageViews": 337,
                "favorite": "https://ramblings.mcpher.com/excel-to-json-and-back/",
                "favoriteTitle": "jSon",
                "universe": 33,
                "rank": 23
            }
        ],
        "topicRoot": false,
        "name": "arraydots",
        "title": "JSON arrays of objects",
        "plusOnes": 3
    },
    "site": {
        "url": "https://ramblings.mcpher.com",
        "numChildren": 4,
        "analytics": [
            {
                "varieties": 1000,
                "name": "Past Month",
                "pageViews": 47989,
                "favorite": "",
                "favoriteTitle": "",
                "universe": 0,
                "rank": 0
            },
            {
                "varieties": 1000,
                "name": "Past Year",
                "pageViews": 557876,
                "favorite": "",
                "favoriteTitle": "",
                "universe": 0,
                "rank": 0
            },
            {
                "varieties": 999,
                "name": "All Time",
                "pageViews": 1177090,
                "favorite": "",
                "favoriteTitle": "",
                "universe": 0,
                "rank": 0
            }
        ],
        "name": "share",
        "title": "Desktop Liberation",
        "plusOnes": 2313
    }
}

See more like this in  Displaying analytics data on site pages