Skip to content

Instantly share code, notes, and snippets.

@copernicus
Forked from SeanJA/Gemfile
Created November 19, 2012 14:11
Show Gist options
  • Save copernicus/4110850 to your computer and use it in GitHub Desktop.
Save copernicus/4110850 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment