Giter Club home page Giter Club logo

googleapis-analytics-demo's Introduction

googleapis-analytics-demo

GitHub last commit

Demo of the Google Analytics API.

Prerequisites

Install

Clone the repository:

git clone https://github.com/remarkablemark/googleapis-analytics-demo.git
cd googleapis-analytics-demo

Install the dependencies:

npm install

Authentication

Login to Google Cloud Platform. Agree to the Terms of Service if you haven't already.

Create a New Project with a Project name and Project ID.

Enable the Google Analytics API.

Go to Credentials and create a Service account credential, which enables server-to-server, app-level authentication using robot accounts. Fill in the Service account name and Service account ID and click Done.

In Credentials, look for Service Accounts and click the newly created Email. Click Keys > Add Key > Create new key > Key type > JSON > Create. The private key, which allows access to your cloud resources, will be saved to your computer.

Move the key to the project directory:

mv path/to/project-id-abcdef123456.json auth.json

Only private_key and client_email are necessary for JWT authorization. See auth.example.json:

{
  "private_key": "-----BEGIN PRIVATE KEY-----\nabc123\n-----END PRIVATE KEY-----\n",
  "client_email": "[email protected]"
}

Alternatively, the keys can be set in .env. See .env.example:

CLIENT_EMAIL="[email protected]"
PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\nabc123\n-----END PRIVATE KEY-----\n"

Open Google Analytics and go to Admin > View Settings and copy the View ID.

Set VIEW_ID in .env. See .env.example:

echo 'VIEW_ID=12345678' >> .env

Go back to Admin and go to View User Management. In View permissions, click + to Add users and add the service account email client_email.

Run

npm start

Prints the Google Analytics real-time data for a view (profile). See Real Time Reporting API.

License

MIT

googleapis-analytics-demo's People

Contributors

remarkablemark avatar

Stargazers

 avatar

Watchers

 avatar  avatar

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.