This one is deprecated since the demise of Gadgets on sites.
As described in Database abstraction of site results, each site page has some associated analytics data stored in a database which is updated through a GAS trigger. The page gadget which displays that data is a JavaScript app, which uses the same technique as JSON API for data abstraction classes to serve analytics data to pages.
You can take a copy of this web service here

The code

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