Garb

by muzik on 2010-08-09

Garb是一个用于从Google Analytics 中查询数据的Ruby 类。相关链接:

安装

$ sudo gem install garb

用法

用户验证

Garb::Session.login('someone@gmail.com', password)
 

取回账户列表

Garb::Account.all
 

查找配置文件

Garb::Profile.first(id)
 

id可以是统计代码中形如UA-247543-9的web_property_id,亦可是查看配置时网址https://www.google.com/analytics/reporting/?reset=1&id=4662047中形如4662047的数字ID。

不可按域名查找。因为Google Analytics的配置文件并不是和域名绝对绑定的。但如果配置文件的名称就是域名的话,可以Garb::Profile.all取回所有配置文件再用域名比对title。

创建报告


Garb::Session.login('someone@gmail.com', password)
profile=Garb::Profile.first(‘UA-247543-9)

report = Garb::Report.new(profile,:limit=>50)
report.metrics :visits,:pageviews
report.dimensions :keyword,:page_path
report.sort :visits.desc

report.filters :keyword.does_not_match => '(not set)'

report.results

 

此报告取回热门关键词来源及相对应的Page,如:

puts report.results.first
##<OpenStruct visits="91", pageviews="106", keyword="example", page_path="/garb.html">

 

可用的参数

  • :start_date
  • :end_date
  • :limit
  • :offset

指标和纬度

metrics 和 dimensions 可参考 analytics 创建自定义报告中的指标纬度,详细列表可查看Google官方文档:Dimensions & Metrics

排序

sort 默认升序排列,在参数后加.desc即为降序。

过滤

指标可用的过滤语法

eql => '==',
not_eql => '!=',
gt => '>',
gte => '>=',
lt => '<',
lte => '<='

纬度可用的语法

matches => '==',
does_not_match => '!=',
contains => '=~',
does_not_contain => '!~',
substring => '=@',
not_substring => '!@'

示例

report.filters :keyword.does_not_match => '(not set)',:visits.gt => 50
 

{ 0 comments }

午后

by muzik on 2010-07-30

1.连日阴晴交错,冷暖骤变时,一日再三。午睡起来,忽忽间头痛如绞。平生未尝如此痛也,竟至泪下难禁。想是感了风寒,寻药服下,亦急不见效。

2.内子质弱,曩逢意外,自是多病。向数月中,赴院就医之日,十之三四。近感西医无效,求诸中草。余亦无计,惟持瓮捧炉,旦夕煎药以奉。

3.街头偶遇幼时同窗,虽觉相熟,终不敢认。

{ 0 comments }