Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
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://ga-dev-tools.appspot.com/query-explorer/
for examples of how to use dimensions and metrics and create a report, and:
https://developers.google.com/analytics/devguides/reporting/core/dimsmets
for examples of dimensions and metrics
FAQs
Google analytics API access via node
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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.