Giter Site home page Giter Site logo

arissetyawan / ga_dashboard Goto Github PK

View Code? Open in Web Editor NEW

This project forked from renugasaraswathy/ga_dashboard

0.0 3.0 0.0 14 KB

This gem helps in bringing Google Analytics Dashboard into a Rails application

License: MIT License

Ruby 99.37% Shell 0.63%

ga_dashboard's Introduction

GA Dashboard

This gem helps you to import Google Analytics Dashboard into your Rails application.

You can pull out the following stats from Google Analytics

  1. Most Popular Pages
  2. Geo Chart (Map) or Table which represents the following data for a given time period
    • Users count from various countries across the world
    • Users count from various countries in a continent
    • Users count from various cities of a country
  3. Overview of users and sessions for a given time period as line chart

Installation

Add this line to your application's Gemfile:

gem 'ga_dashboard'

And then execute:

$ bundle

Or install it yourself as:

$ gem install ga_dashboard

Usage

###Prerequisites

You need to set up the following things before using this gem.

  1. Create Google Analytics account for your project, add the script with tracking code in all the view pages that you want to track.
  2. Create a project at Google Developers Console
  3. In Google Developers console, Select your Project -> API & auth -> Search for Analytics -> Enable API
  4. Under API & auth -> Credentials -> Add Credentials -> Service Account -> Select P12 and create
  5. Download the Key file and save it in your_project_folder/lib/keys
  6. Note down the service email address that is created. It should be something like โ€˜[email protected]โ€™
  7. Login into your Google Analytics account -> Admin -> User Management -> Add permission to your service email address.
  8. Open Query Explorer, select your GA account for the project. Note down the number shown after ga. (e.g., ga:xxxxxxxxxx) which is the GA Profile ID

###Configure your Rails application

In your Rails application, create a file 'ga_dashboard.rb' inside config/initializers with the following lines

GA_SERVICE_EMAIL_ADDRESS="<Your Service Email Address>"
GA_PROFILE_ID="<Ga Profile ID>"
PATH_TO_KEY_FILE="#{Rails.root}/keys/<Your key file name>"

###Add code to your controller (e.g., reports_controller#index)

@ga_dashboard_api=GaDashboard::AnalyticsApi.new("your_project_name",version_no)

###Add the dashboard in your views

In your view file (e.g., reports/index.html.erb) add this

<script src='https://www.google.com/jsapi'></script>
  • Create the division where you want the dashboard to be appear.
  • Use any of the helper methods listed below to generate the view.

####1. Popular Pages

display_most_popular_pages(ga_dashboard_api,pages_starting_with,start_date,end_date,id_of_the_division)

#####Example:

<div id='popular_pages'></div>
<%= display_most_popular_pages(@ga_dashboard_api,"home",DateTime.now-2.months,DateTime.now,'popular_pages') %>

#####Screenshot ScreenShot

####2. Users count from various countries across the world

display_users_from_countries_across_world(ga_dashboard_api,start_date,end_date,id_of_the_division,format="table",options={})

#####Example: Using Map

<div id='world'></div>
<%= display_users_from_countries_across_world(@ga_dashboard_api,DateTime.now-2.months,DateTime.now,'world','map',{:title=>'Users Across world'}) %>

#####Screenshot ScreenShot

#####Example: Using Table

<div id='world1'></div>
<%= display_users_from_countries_across_world(@ga_dashboard_api,DateTime.now-2.months,DateTime.now,'world1','table',{:title=>'Users Across world'}) %>

#####Screenshot ScreenShot

####3. Users count from various countries in a continent

display_users_from_countries_of_continent(ga_dashboard_api,continent,start_date,end_date,division_id,format="table",options={})

Acceptable continent names are Africa,Europe,Americas,Asia and Oceania

#####Example: Using Map

<div id='continent'></div>
<%= display_users_from_countries_of_continent(@ga_dashboard_api,"Asia",DateTime.now-2.months,DateTime.now,'continent','map',{:title=>"Users from Asia"}) %>

#####Screenshot ScreenShot

####4. Users count from various cities of a country

display_users_from_cities_of_country(ga_dashboard_api,country,start_date,end_date,id_of_the_division,format="table",options={})

Acceptable country names are listed here

#####Example: Using Map

<div id='country'></div>
<%= display_users_from_cities_of_country(@ga_dashboard_api,"India",DateTime.now-2.months,DateTime.now,'country','map',{:title=>"Users from India"}) %>

#####Screenshot ScreenShot

####5. Users Overview

display_users_overview(ga_dashboard_api,start_date,end_date,region_type,region,div_id,options={})
  • Region Type - Acceptable values are country or continent
  • Region - continent names or countries names basis region type

#####Example: Using Map

<div id='users_overview1'></div>
<%= display_users_overview(@ga_dashboard_api,DateTime.now-2.months,DateTime.now,'country','India','users_overview1',{:title=>"Users Overview",:height=>'500'}) %>

#####Screenshot ScreenShot

<div id='users_overview2'></div>
<%= display_users_overview(@ga_dashboard_api,DateTime.now-1.months,DateTime.now,'country','India','users_overview2',{:title=>"Users Overview",:height=>'500'}) %>

#####Screenshot ScreenShot

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/renugasaraswathy/ga_dashboard. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

License

The gem is available as open source under the terms of the MIT License.

ga_dashboard's People

Contributors

arissetyawan avatar

Watchers

James Cloos avatar Saraswathy Renuga 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.