JSPM

google-analyticsreporting

1.0.8
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 238
  • Score
    100M100P100Q83072F
  • License ISC

server-side reporting module for google analytics reporting api v4

Package Exports

  • google-analyticsreporting

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (google-analyticsreporting) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Google Analytics Reporting API node module

Node module to access analytics reporting v4 api.

Prerequisites

You'll need to set up a google project with a service user and download the service user JSON file.

Installing

To add this to your node project type the following at the command line:

npm install --save google-analyticsreporting

Using the package

You'll need to include the JSON from the Prerequisites section like so:

var key = require('./path/to/secret.json');

First you'll need to run the auth command, then you can then into the query function.

const ga = require('google-analyticsreporting');
var key = require('./secret/secret.json');


const reportRequests = {
  reportRequests:
    [
      {
        viewId: '<YOUR VIEW ID HERE>',
        dateRanges:
          [
            {
              endDate: '2018-01-18',
              startDate: '2018-01-18',
            },
          ],
          metrics:
          [
            {
              expression: 'ga:dcmCost',
            },
            {
              expression: 'ga:dcmClicks',
            },
            {
              expression: 'ga:dcmImpressions',
            },
          ],
          dimensions:
          [
            {
              name: 'ga:dcmLastEventCampaign',
            },
          ],
      },
  ],
};

ga.auth(key)
  .then(
    ga.query(reportRequests)
    .then(function(error,results){
      var csv = ga.makecsv(error,results);
      console.log(csv);
    })
  );