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.rb
file in to your dashingjobs\
folder. - Update the
service_account_email
,key_file
,key_secret
andprofileID
variables
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.
This looks like this might an issue with the fact that Google is currently considering this realtime analytics to be invitation only Beta. Womp womp. I'm getting the same thing: