A Dashing widget for displaying the number of current visitors (in real time) to your website, as reported by Google Analytics.
This widget is a fork of https://gist.github.com/mtowers/5986576
Add it to dashing's gemfile:
gem 'google-api-client'
and run bundle install.
To use this widget, you'll first need to set up a Google API project and attach it to the Google Analytics profile you wish to monitor, as well as request access to the Google Analytics Real Time API.
- Go to http://goo.gl/7ZPlMI and fill the form
- Go to https://code.google.com/apis/console
- Click 'Create Project'
- Enable 'Analytics API' service and accept both TOS's
- Click 'API Access' in the left-hand nav menu
- Click 'Create an OAuth 2.0 Client ID'
- Enter a product name (e.g. Dashing Widget) - logo and url are optional
- Click 'Next'
- Under Application Type, select 'Service Account'
- Click 'Create Client ID'
- Click 'Download private key' NOTE: This will be your only opportunity to download this key.
- Note the password for your new private key ('notasecret')
- Close the download key dialog
- Find the details for the service account you just created and copy it's email address which will look something like this:
[email protected]- you'll need it in your ruby code later
Note: you will need to be an administrator of the Google Analytics profile
- Log in to your Google Analytics account: http://www.google.com/analytics/
- Click 'Admin' in the upper-right corner
- Select the account containing the profile you wish to use
- Select the property containing the profile you wish to use
- Select the profile you wish to use
- Click the 'Users' tab
- Click '+ New User'
- Enter the email address you copied from step 13 above
- Click 'Add User'
- On your Google Analytics profile page, click the 'Profile Settings' tab
- Under 'General Information' copy your Profile ID (e.g. 654321) - you'll need it in your ruby code later
- Copy the
visitor_count.rbfile in to your dashingjobs\folder. - Update the
service_account_email,key_file,key_secretandprofileIDvariables
service_account_email = '[YOUR SERVICE ACCOUTN EMAIL]' # Email of service account
key_file = 'path/to/your/keyfile.p12' # File containing your private key
key_secret = 'notasecret' # Password to unlock private key
profileID = '[YOUR PROFILE ID]' # Analytics profile ID.- Add the widget HTML to your dashboard
<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
<div data-id="visitor_count_real_time" data-view="Graph" data-title="Current Visitors"></div>
</li>If you want to modify this plugin to pull other data from Google Analytics, be sure to check out the Google Analytics Query Explorer.

What is wrong? How to solve?
MINGW64 /c/Teste $ ruby -v ruby 2.3.3p222 (2016-11-21 revision 56859) [i386-mingw32] MINGW64 /c/Teste $ gem environment RubyGems Environment: - RUBYGEMS VERSION: 2.6.11 - RUBY VERSION: 2.3.3 (2016-11-21 patchlevel 222) [i386-mingw32] - INSTALLATION DIRECTORY: C:/Ruby23/lib/ruby/gems/2.3.0 - USER INSTALLATION DIRECTORY: C:/Users/marcelovilela.mg/.gem/ruby/2.3.0 - RUBY EXECUTABLE: C:/Ruby23/bin/ruby.exe - EXECUTABLE DIRECTORY: C:/Ruby23/bin - SPEC CACHE DIRECTORY: C:/Users/marcelovilela.mg/.gem/specs - SYSTEM CONFIGURATION DIRECTORY: C:/ProgramData - RUBYGEMS PLATFORMS: - ruby - x86-mingw32 - GEM PATHS: - C:/Ruby23/lib/ruby/gems/2.3.0 - C:/Users/marcelovilela.mg/.gem/ruby/2.3.0 - GEM CONFIGURATION: - :update_sources => true - :verbose => true - :backtrace => false - :bulk_threshold => 1000 - REMOTE SOURCES: - https://rubygems.org/ - SHELL PATH: - C:\Users\marcelovilela.mg\bin - C:\Program Files\Git\mingw64\bin - C:\Program Files\Git\usr\local\bin - C:\Program Files\Git\usr\bin - C:\Program Files\Git\usr\bin - C:\Program Files\Git\mingw64\bin - C:\Program Files\Git\usr\bin - C:\Users\marcelovilela.mg\bin - C:\Ruby23\bin - C:\ProgramData\Oracle\Java\javapath - C:\Program Files\Common Files\Microsoft Shared\Windows Live - C:\Windows\system32 - C:\Windows - C:\Windows\System32\Wbem - C:\Windows\System32\WindowsPowerShell\v1.0 - C:\Program Files\Intel\DMIX - C:\Program Files\TortoiseSVN\bin - C:\python26 - C:\python26\scripts - C:\cheetah-2.4.4\bin - C:\Program Files\nodejs - C:\Program Files (x86)\Skype\Phone - C:\Program Files\Git\cmd - C:\Users\marcelovilela.mg\AppData\Roaming\npm - C:\Python27\Scripts - C:\Python27 - C:\Program Files\Git\usr\bin\vendor_perl - C:\Program Files\Git\usr\bin\core_perl MINGW64 /c/Teste $ gem list google-api-client -d google-api-client (0.11.1) Authors: Steven Bazyl, Tim Emiola, Sergio Gomes, Bob Aman Homepage: https://github.com/google/google-api-ruby-client License: Apache 2.0 Installed at: C:/Ruby23/lib/ruby/gems/2.3.0 Client for accessing Google APIs MINGW64 /c/Teste $ ruby visitor_count.rb C:/Ruby23/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- google/api_client (LoadError) from C:/Ruby23/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require' from visitor_count.rb:1:in `<main>'