Git Product home page Git Product logo

node-googleanalytics's Introduction

Google Analytics

Pull data from Google Analytics for use in projects.

The library maintains tracking of the token so that you don't have to and will push the token around with your requests. Should you require a different token, just create a new GA instance. However, this is asynchronous through eventing so if you do want the token you can latch onto the event.

  • Updated for NodeJS 0.6.x *

Usage

With a user and password:

var GA = require('googleanalytics'),
    util = require('util'),
    config = {
        "user": "myusername",
        "password": "mypassword"
    },
    ga = new GA.GA(config);

ga.login(function(err, token) {
    var options = {
        'ids': 'ga:<profileid>',
        'start-date': '2010-09-01',
        'end-date': '2010-09-30',
        'dimensions': 'ga:pagePath',
        'metrics': 'ga:pageviews',
        'sort': '-ga:pagePath'
    };

    ga.get(options, function(err, entries) {
       util.debug(JSON.stringify(entries));
    });
});

If you have already gotten permission from a user, you can simply use the oAuth access token you have:

var GA = require('googleanalytics'),
    util = require('util'),
    config = {
        "token": "XXXXXXXXXXXX"
    },
    ga = new GA.GA(config);

var options = {
    'ids': 'ga:<profileid>',
    'start-date': '2010-09-01',
    'end-date': '2010-09-30',
    'dimensions': 'ga:pagePath',
    'metrics': 'ga:pageviews',
    'sort': '-ga:pagePath'
};

ga.get(options, function(err, entries) {
    util.debug(JSON.stringify(entries));
});

You can specify the type of token by setting 'tokenType', default is 'Bearer'.

See node-gapitoken for easy service account Server to Server authorization flow.

API

  • login([callback]) - The callback is optional. However, if it is given, it is added to the token event.
  • get(options, callback)

Event API

  • token(err, token)
  • entries(err, entries)

Entry API

  • metrics[]
  • dimensions[]

Each array contains objects. These objects contain the following:

  • name - The name of the metric or dimension requested
  • value - The value associated. If the value is a Number, it is parsed for you. Otherwise, it will be a string.

Contributors

License

see license file

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.