This is now deprecated since the demise of Gadgets on Sites
Site analytics were stored with the site and the analytics property to which they refer, and accessed through the cSiteStats library. You will need to take a copy of this so you can reference your own properties. Also referenced here are the parameters required to describe what kind of database to store this is using Database abstraction with google apps script.
For testing, my library reference is MKHWwn03HE7ktl0fffddC-iz3TLx7pV4j
Once you’ve taken a copy, you’ll need to set up your properties. Mine look like this and you should modify the function below to represent yours.

The code

By centralizing access to your site options, you can ensure that any apps you create will access the same database and parameters, even though you change them.


The Code

See more like this in Database abstraction with google apps script and Displaying analytics data on site pages