This repository is a place to find utility modules for interacting with the Google Analytics APIs. The source files are available as node-style modules (in the /lib folder) and as standalone browser scripts (in the build folder). The browser versions are built with browserify and can be accessed from the global object window.gaApiUtils
or by using an AMD module loader.
# Install via npm
npm install git+https://git@github.com/googleanalytics/javascript-api-utils.git
# Install via bower
npm install googleanalytics/javascript-api-utils
Note: all the examples below assume the user is authenticated and gapi.client
is loaded on the page. They also assume the browser supports promises. If you're including this library on sites where modern browser usage isn't guaranteed, a Promise polyfill is required.
var accountSummaries = require('javascript-api-utils/lib/account-summaries');
// Log a list of all the user's Google Analytics views to the console.
accountSummaries.get().then(function(summaries) {
console.log(summaries.allViews());
});
var metadata = require('javascript-api-utils/lib/metadata');
// Log a list of all the user's Google Analytics views to the console.
metadata.get().then(function(columns) {
console.log(columns.allMetrics());
});
To see a demo of these modules in action, run the demo file on a local server on port 8080.
If you'd like to contribute modules to this repository please follow the Google JavaScript style guide and make sure to include relevant tests with any pull requests. Also include demos where appropriate.
make test
make build