
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
Google Analytics API access, with automated concurrency limiting and optional request caching.
npm install ga-api --save
Note: you'll need to setup a google service account here: https://developers.google.com/identity/protocols/OAuth2ServiceAccount#creatinganaccount in order to use this library, and have access to google analytics reporting.
Before using the library, setup the google service account as described in the link, then grab the following information:
You can find the client ID and Email in the google developers console here (after creating it):

And the view ID in the google analytics console here:

So you end up with something like:
var options = {
clientId: "clientidisalongandseeminglyrandomstringofcharacters.apps.googleusercontent.com",
email: "clientidisalongandseeminglyrandomstringofcharacters@developer.gserviceaccount.com",
key: "google-service-private-key.pem",
ids: "ga:12345678"
};
gaApi(args, callBack, settings)
Where:
error and a result argumentThe args must also include the Authentication information from above, ie: clientId, email, key and ids.
This function receives an error object and the resulting data from your query, i.e:
function(error, result) {
if(error) throw error;
// Do something with result here
}
The settings can optionally override some deafult settings, these include:
var options = {...authentication info from above...},
gaApi = require('ga-api');
gaApi(_.extend({}, options, {
startDate: "2015-06-03",
endDate: "2015-06-10",
dimensions: "ga:affiliation,ga:date",
metrics: "ga:revenuePerTransaction"
}), function(err, data) {
console.log(data);
});
The resulting data will look something like this:
{ kind: 'analytics#gaData',
id: 'https://www.googleapis.com/analytics/v3/data/ga?ids=ga:XXXXXXXX&dimensions=ga:affiliation,ga:date&metrics=ga:revenuePerTransaction&sort=ga:affiliation&start-date=2015-06-03&end-date=2015-06-10',
query:
{ 'start-date': '2015-06-03',
'end-date': '2015-06-10',
ids: 'ga:XXXXXXXX',
dimensions: 'ga:affiliation,ga:date',
metrics: [ 'ga:revenuePerTransaction' ],
sort: [ 'ga:affiliation' ],
'start-index': 1,
'max-results': 1000 },
itemsPerPage: 1000,
totalResults: 32,
selfLink: 'https://www.googleapis.com/analytics/v3/data/ga?ids=ga:XXXXXXXX&dimensions=ga:affiliation,ga:date&metrics=ga:revenuePerTransaction&sort=ga:affiliation&start-date=2015-06-03&end-date=2015-06-10',
profileInfo:
{ profileId: 'XXXXXXXX',
accountId: 'XXXXXXXX',
webPropertyId: 'UA-XXXXXXXX-2',
internalWebPropertyId: 'XXXXXXXX',
profileName: 'Web data',
tableId: 'ga:XXXXXXXX' },
containsSampledData: false,
columnHeaders:
[ { name: 'ga:affiliation',
columnType: 'DIMENSION',
dataType: 'STRING' },
{ name: 'ga:date', columnType: 'DIMENSION', dataType: 'STRING' },
{ name: 'ga:revenuePerTransaction',
columnType: 'METRIC',
dataType: 'CURRENCY' } ],
totalsForAllResults: { 'ga:revenuePerTransaction': '123.456' },
rows:
[ [ 'SOURCE1', '20150603', '12.34' ],
[ 'SOURCE1', '20150604', '56.78' ],
[ 'SOURCE2', '20150603', '90.12' ],
[ 'SOURCE2', '20150604', '34.56' ],
[ 'SOURCE3', '20150603', '78.90' ],
[ 'SOURCE3', '20150605', '12.34' ],
}
So essentially the "rows" attribute of the data object will have what you want.
Note: See this page: https://developers.google.com/analytics/devguides/reporting/core/dimsmets for examples of dimensions and metrics
FAQs
Google analytics API access via node
The npm package ga-api receives a total of 17 weekly downloads. As such, ga-api popularity was classified as not popular.
We found that ga-api demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.