You'll have noticed by now there is recursion involved in almost every function. Here's a good time to look at the fundamentals of recursion in these kind of tree objects. Each object has children, each of which may have their own children. The simplest way to navigate these kind of structure is with recursion.
Here's a simple example of adding an analytics object in which to store the accumulated page views for each page
Each recursive function follows the same pattern.
A good thing about using recursion is that it forces you to use consistent patterns - it usually completely works, or totally screws up.
See more like this in Displaying analytics data on site pages
Services > Desktop Liberation - the definitive resource for Google Apps Script and Microsoft Office automation > Fancy gadgets on Sites >