GithubHelp home page GithubHelp logo

node-googleanalytics's Introduction

Google Analytics

UNMAINTAINED: In case it wasn't clear from the lack of activity, I don't have the time to work on this project anymore.
I'd be happy to transfer ownership to someone else or add someone as a contributor to the project. Please reach out to me
and let me know!


This project doesn't work and hasn't worked for some time due to google removing the use based configuration.
	See more at https://github.com/ncb000gt/node-googleanalytics/issues/36#issuecomment-383822453

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

node-googleanalytics's People

Contributors

asadja avatar beezee avatar blakmatrix avatar bsphere avatar j-5-s avatar joshvermaire avatar mschierberl avatar ncb000gt avatar orta avatar qzaidi avatar rowanu avatar talibnelson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-googleanalytics's Issues

Metrics being returned in Scientific Notation

Looks like some metrics are presented in scientific notation when returned by the google analytics API.

ie:

 'ga:pageviews': '290593',
 'ga:timeOnPage': '4.95005007E8',
 'ga:uniquePageviews': '196588',
 'ga:timeOnSite': '5.18367835E8',

And returned by this module as such:

   'ga:pageviews': 290593,
   'ga:timeOnPage': 4,
   'ga:uniquePageviews': 196588,
   'ga:timeOnSite': 5,

Upon initial investigation simply changing to a parseFloat on the ga.js file at line 163 does the trick.

I'd be happy to send a pull request for the change, let me know.

Return empty array

Hi,

The .get method is returning an empty array. Is there any updated version of this module?

Thanks
Raf

With a user and password:

Hello, I am having an issue with logging in to google analytics via the username and password method. Below is my config, and my error. Have you experienced this error?

util = require('util'),
config = {
"user": GOOGLE_EMAIL,
"password": GOOGLE_PASSWORD
},
ga = new GA.GA(config);

{ [Error: BadAuthentication
]
responseData: 'Error=BadAuthentication\nUrl=https://www.google.com/accounts/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbte89_uredV3sMhkh15QcN3AP4CvMXlwRzKMTPpbhpX8yX-LTUjbfo3UaIc5naE7KhhAa4C0hOlOIwCig-qpTelg-cuaE4EBJZWmMky_pWfa8CwsyorNhG2tbQonuxXHtC_dnazyvAMqICxncOM7SDu61Y3YFFZjwAQuNHZ_uUa2ss5nY0tjbG4fvXNb0KWssTNrVioDS12oBsaoQYiQGYIWSjRfFcjxzqgL8nzjz2rJiEQ1os\nInfo=WebLoginRequired\n' }

Seems to max out 1000 results

I've tried setting the max-results query param, with and without the start-index param, but both seem to break the query.

GA allows up to 10k as the response, any way to increase this?

Does not properly handle error from Google (Sign-In)

I am having trouble signing into my Google Analytics account with this module. However, when it fails due to BadAuthentication the module throws an exception for error. I believe this should be handled more cleanly.

data is Error=BadAuthentication
Url=https://www.google.com/accounts/ContinueSignIn?XXX...XXX
Info=WebLoginRequired


events.js:74
        throw TypeError('Uncaught, unspecified "error" event.');
              ^
TypeError: Uncaught, unspecified "error" event.
    at TypeError (<anonymous>)
    at GA.EventEmitter.emit (events.js:74:15)
    at IncomingMessage.<anonymous> (/Users/xx/project/node_modules/googleanalytics/lib/ga.js:85:22)
    at IncomingMessage.EventEmitter.emit (events.js:117:20)
    at _stream_readable.js:920:16
    at process._tickCallback (node.js:415:13)

Each request ends in ECONNRESET error

Using the sample to test validity I get the data I need, but the code always ends in an error:

Error: ECONNRESET, Connection reset by peer
at net:304:14
at Client._readImpl (net:358:27)
at IOWatcher.callback (net:454:24)
at node.js:773:9

Node.js version 0.2.6, running on FreeBSD 7.3.

Error trying to get the demo to work

Hi there!

I find this module very helpful and I'm willing to use it.

I copied the demo little project to test it, but it's not working. Here's the error:

...\node_modules\googleanalytics\node_modules\jquery\lib\node-jquery.js:10
window.XMLHttpRequest.prototype.withCredentials = false;
^
TypeError: Cannot read property 'prototype' of undefined
at create (...\node_modules\googleanalytics\node_modules\jquery\lib\node-jquery.js:10:26)
at ...\node_modules\googleanalytics\node_modules\jquery\lib\node-jquery.js:9435:18
at Object. (...\node_modules\googleanalytics\node_modules\jquery\lib\node-jquery.js:9437:2)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:362:17)
at require (module.js:378:17)
at Object. (...\jasmine\node_modules\googleanalytics\lib\ga.js:5:6)

I'm using version v0.8.1 of node on a Windows XP machine.
I declared the 0.2.0 version of your module ( I also tried 0.1.0 with no success)

Do you have an idea of the source of the problem?

Thanks a lot!

module versions issue with npm

I'm installing the module with 'npm install googleanalytics', it install version 0.3.0 (Same as the latest one). but its not the same version. ga.js doesn't include the option to use an access token instead of username / password

Cannot use several metrics types

ga:pageviews, ga:visitors and ga:entrances work, but thing like ga:browser and ga:operatingSystem don't. Is this more likely a problem with my code, or the module? I'm getting errors such as unknown metric(s): ga:browser

Ability to filter by.

I cant seem to see any implementation of the the filter options available on GA API.

Am i missing something...?

Tried passing through in the options but doest appear to work.

Thanks

modules doesn't work with node v0.8.18

I'm getting this error from ga.get:

node_modules/googleanalytics/lib/ga.js:128
for (var col=0; col<parsed_data.columnHeaders.length; col++){
^
TypeError: Cannot read property 'length' of undefined
at IncomingMessage.GA.get (/home/gal/dev/nodejs/ga/node_modules/googleanalytics/lib/ga.js:128:58)
at IncomingMessage.EventEmitter.emit (events.js:126:20)
at IncomingMessage._emitEnd (http.js:366:10)
at HTTPParser.parserOnMessageComplete as onMessageComplete
at CleartextStream.socketOnData as ondata
at CleartextStream.CryptoStream._push (tls.js:544:27)
at SecurePair.cycle (tls.js:898:20)
at EncryptedStream.CryptoStream.write (tls.js:285:13)
at Socket.ondata (stream.js:38:26)
at Socket.EventEmitter.emit (events.js:96:17)

Can't use refresh token

I tried using a refresh token as stated in the README, but it doesn't work.

the only way I could make it work is to use an actual access token (without Auth=) and change the Authorization header in ga.js from "GoogleLogin + token" to "Bearer + token".

I couldn't find it anywhere in Google's documentation the possibility to use a refresh token directly without getting an auth token first.

error:0906D06C:PEM routines:PEM_read_bio:no start line

Like in the title i get this error when following the tutorial on the first page.
error:0906D06C:PEM routines:PEM_read_bio:no start line

I guess it comes from the certificate file, but the options section of the documentation is misleading.
there is effectively a "clientId" parameter on the google interface, but "no email" example.
I tried with my google login email, but it's not working neither.

For the key, i also checked that the file path was correct, as well as the encoding.
i generated the .pem from the .p12 like in the tutorial, i get the message "Mac verified OK"

I really dont know what information to use in the options for "clientId" and "email".

Btw the screenshot on the documentation are not correct and very old. That's probably why i can't find the same informations.
Infortunatelly i can't use the api for now.

Error: socket hang up

I get this error on ubuntu 11.04 64bits :
node.js:134
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: socket hang up
at Client. (http.js:1531:26)
at Client.emit (events.js:64:17)
at Array. (net.js:829:12)
at EventEmitter._tickCallback (node.js:126:26)

My code :
var ga = require('googleanalytics') ;

var GA = new ga.GA({ user: '[email protected]', password: 'xxxxxxxx' });
GA.login(function(error, token) {
if (error != null) {
throw error;
}
});

NPM outdated

Please update to latest version on npm.

Currently npm is installing 0.1.1 version.

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.