Skip to content

Instantly share code, notes, and snippets.

@SeanJA
Created November 6, 2012 04:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save SeanJA/4022494 to your computer and use it in GitHub Desktop.
Save SeanJA/4022494 to your computer and use it in GitHub Desktop.
pageviews widget for dashing
<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
<div data-id="daily_pageviews" data-view="Number" data-title="Page Views" data-moreinfo="Today"></div>
</li>
<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
<div data-id="monthly_pageviews" data-view="Number" data-title="Page Views" data-moreinfo="Today"></div>
</li>
gem 'garb', :git => 'git://github.com/Sija/garb.git'
require 'garb'
username = ''
password = ''
api_key = ''
ua = ''
Garb::Session.api_key = api_key
Garb::Session.login(username, password)
class PageViews
extend Garb::Model
metrics :pageviews
dimensions :date
end
profile = Garb::Management::Profile.all.detect {|p| p.web_property_id == ua}
SCHEDULER.every '1m', :first_in => 0 do
views = PageViews.results(
profile,
:start_date => Time.now,
:end_date => Time.now,
:limit => 1
)
value = views.first.pageviews
send_event('daily_pageviews', { current: value })
end
require 'garb'
username = ''
password = ''
api_key = ''
ua = ''
Garb::Session.api_key = api_key
Garb::Session.login(username, password)
class PageViews
extend Garb::Model
metrics :pageviews
dimensions :month
end
profile = Garb::Management::Profile.all.detect {|p| p.web_property_id == ua}
SCHEDULER.every '1m', :first_in => 0 do
views = PageViews.results(
profile,
:limit => 1
)
value = views.first.pageviews
send_event('monthly_pageviews', { current: value })
end
@SeanJA
Copy link
Author

SeanJA commented Nov 6, 2012

I went with the monthly one myself, but if you have a high-traffic site, you might want to go with the daily one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment