hisui 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +24 -1
- data/lib/hisui/request.rb +9 -4
- data/lib/hisui/response.rb +44 -7
- data/lib/hisui/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2f63cc587035f036777979c56d4d39fed2e9f512e126d3809b3a85a7487ff675
|
4
|
+
data.tar.gz: '08e8bea765cb07fae43410ce041ab2ff38bf4ea51c997240f4fac1b05aed0b83'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4196498ee4b4985e30cbac8391115c78b3a43de0e8cb06273f89b12eaa4cfe27fd64c5357d0c5794a56d2ff0a1be5590aa6067a238c14c54a2890474ef178a6d
|
7
|
+
data.tar.gz: d69cf054f142c53fee1692253c6d9b4c6b5d8479fbe5aa80b90b10f5c6f669b280585d76645586a5e3ae0ac138795ccdd44ec76ba743b7131875c5af8beef4dd
|
data/README.md
CHANGED
@@ -44,22 +44,45 @@ end
|
|
44
44
|
|
45
45
|
3. Get Google Analytics API response with `results` methods.
|
46
46
|
Set `start_date` and `end_date` if you need.(defult period is past one month)
|
47
|
+
Set `compare_start_date` and `compare_end_date` if you need.
|
47
48
|
```ruby
|
48
|
-
response = DailySummary.results(profile: profile, start_date: Date.current - 7.days, end_date: Date.current)
|
49
|
+
response = DailySummary.results(profile: profile, start_date: Date.current - 7.days, end_date: Date.current, compare_start_date: Date.current - 7.days - 1.month, compare_end_date: Date.current - 1.month)
|
49
50
|
```
|
50
51
|
|
51
52
|
4. Use data.
|
52
53
|
```ruby
|
54
|
+
# Deprecate
|
53
55
|
response.raw_attributes
|
54
56
|
|
55
57
|
#=> [#<OpenStruct date="20171122", pageviews="137", sessions="73", users="51", newUsers="43", bounceRate="69.56521739130434", pageviewsPerSession="2.608695652173913", avgSessionDuration="87.69565217391305">,
|
56
58
|
# ...
|
57
59
|
# #<OpenStruct date="20171129", pageviews="95", sessions="67", users="44", newUsers="32", bounceRate="80.0", pageviewsPerSession="2.25", avgSessionDuration="42.0">]
|
58
60
|
|
61
|
+
response.primary
|
62
|
+
|
63
|
+
#=> [#<OpenStruct date="20171122", pageviews="137", sessions="73", users="51", newUsers="43", bounceRate="69.56521739130434", pageviewsPerSession="2.608695652173913", avgSessionDuration="87.69565217391305">,
|
64
|
+
# ...
|
65
|
+
# #<OpenStruct date="20171129", pageviews="95", sessions="67", users="44", newUsers="32", bounceRate="80.0", pageviewsPerSession="2.25", avgSessionDuration="42.0">]
|
66
|
+
|
67
|
+
response.comparing
|
68
|
+
|
69
|
+
#=> [#<OpenStruct date="20171022", pageviews="130", sessions="69", users="45", newUsers="40", bounceRate="70.09567898751234", pageviewsPerSession="1.884057975234981", avgSessionDuration="85.02349863284283">,
|
70
|
+
# ...
|
71
|
+
# #<OpenStruct date="20171029", pageviews="95", sessions="67", users="44", newUsers="32", bounceRate="80.0", pageviewsPerSession="2.25", avgSessionDuration="42.0">]
|
72
|
+
|
73
|
+
# Deprecate
|
59
74
|
response.total_values
|
60
75
|
|
61
76
|
#=> #<OpenStruct pageviews="646", sessions="308", users="223", newUsers="144", bounceRate="77.77777777777779", pageviewsPerSession="2.3518518518518519", avgSessionDuration="62.148148148148145">
|
62
77
|
|
78
|
+
response.primary_total
|
79
|
+
|
80
|
+
#=> #<OpenStruct pageviews="646", sessions="308", users="223", newUsers="144", bounceRate="77.77777777777779", pageviewsPerSession="2.3518518518518519", avgSessionDuration="62.148148148148145">
|
81
|
+
|
82
|
+
response.comparing_total
|
83
|
+
|
84
|
+
#=> #<OpenStruct pageviews="640", sessions="299", users="213", newUsers="138", bounceRate="75.97253924292489", pageviewsPerSession="2.1404682398523578", avgSessionDuration="60.814845134904329">
|
85
|
+
|
63
86
|
response.data?
|
64
87
|
|
65
88
|
#=> true
|
data/lib/hisui/request.rb
CHANGED
@@ -2,9 +2,9 @@ require 'google/apis/analyticsreporting_v4'
|
|
2
2
|
|
3
3
|
module Hisui
|
4
4
|
class Request
|
5
|
-
BASIC_OPTION_KEYS = [:start_date, :end_date, :limit]
|
5
|
+
BASIC_OPTION_KEYS = [:start_date, :end_date, :compare_start_date, :compare_end_date, :limit]
|
6
6
|
|
7
|
-
attr_accessor :profile, :model, :start_date, :end_date, :limit
|
7
|
+
attr_accessor :profile, :model, :start_date, :end_date, :compare_start_date, :compare_end_date, :limit
|
8
8
|
|
9
9
|
def initialize(profile:, model:, **options)
|
10
10
|
@profile = profile
|
@@ -21,14 +21,19 @@ module Hisui
|
|
21
21
|
reporting_service = Google::Apis::AnalyticsreportingV4::AnalyticsReportingService.new
|
22
22
|
reporting_service.authorization = profile.user.access_token.token
|
23
23
|
|
24
|
-
|
24
|
+
date_ranges = []
|
25
|
+
date_ranges << Google::Apis::AnalyticsreportingV4::DateRange.new(start_date: start_date.to_s, end_date: end_date.to_s)
|
26
|
+
|
27
|
+
if compare_start_date && compare_end_date
|
28
|
+
date_ranges << Google::Apis::AnalyticsreportingV4::DateRange.new(start_date: compare_start_date.to_s, end_date: compare_end_date.to_s)
|
29
|
+
end
|
25
30
|
|
26
31
|
request = Google::Apis::AnalyticsreportingV4::GetReportsRequest.new(
|
27
32
|
report_requests: [Google::Apis::AnalyticsreportingV4::ReportRequest.new(
|
28
33
|
view_id: profile.id,
|
29
34
|
metrics: model.metrics,
|
30
35
|
dimensions: model.dimensions,
|
31
|
-
date_ranges:
|
36
|
+
date_ranges: date_ranges,
|
32
37
|
order_bys: model.order_bys,
|
33
38
|
page_size: limit
|
34
39
|
)]
|
data/lib/hisui/response.rb
CHANGED
@@ -7,8 +7,13 @@ module Hisui
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def raw_attributes
|
10
|
-
|
11
|
-
|
10
|
+
warn "[DEPRECATION] `raw_attributes` is deprecated. Please use `primary` instead."
|
11
|
+
primary
|
12
|
+
end
|
13
|
+
|
14
|
+
def primary
|
15
|
+
@primary ||= begin
|
16
|
+
primary = []
|
12
17
|
|
13
18
|
data.rows.each do |row|
|
14
19
|
row_data = []
|
@@ -20,15 +25,47 @@ module Hisui
|
|
20
25
|
row_data << value
|
21
26
|
end
|
22
27
|
|
23
|
-
|
28
|
+
primary << Hash[fields.zip(row_data)]
|
29
|
+
end
|
30
|
+
|
31
|
+
primary.map { |attributes| OpenStruct.new(attributes) }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def comparing
|
36
|
+
@comparing ||= begin
|
37
|
+
comparing = []
|
38
|
+
|
39
|
+
data.rows.each do |row|
|
40
|
+
row_data = []
|
41
|
+
row.dimensions.each do |dimension|
|
42
|
+
row_data << dimension
|
43
|
+
end
|
44
|
+
|
45
|
+
if row.metrics.second
|
46
|
+
row.metrics.second.values.each do |value|
|
47
|
+
row_data << value
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
comparing << Hash[fields.zip(row_data)]
|
24
52
|
end
|
25
53
|
|
26
|
-
|
54
|
+
comparing.map { |attributes| OpenStruct.new(attributes) }
|
27
55
|
end
|
28
56
|
end
|
29
57
|
|
30
58
|
def total_values
|
31
|
-
|
59
|
+
warn "[DEPRECATION] `total_values` is deprecated. Please use `primary_total` instead."
|
60
|
+
primary_total
|
61
|
+
end
|
62
|
+
|
63
|
+
def primary_total
|
64
|
+
@primary_total ||= OpenStruct.new(Hash[metrics.zip(data.totals.first.values)])
|
65
|
+
end
|
66
|
+
|
67
|
+
def comparing_total
|
68
|
+
@comparing_total ||= OpenStruct.new(Hash[metrics.zip(data.totals.try(:second).try(:values) || [])])
|
32
69
|
end
|
33
70
|
|
34
71
|
def data?
|
@@ -38,7 +75,7 @@ module Hisui
|
|
38
75
|
private
|
39
76
|
|
40
77
|
def column_header
|
41
|
-
@column_header
|
78
|
+
@column_header ||= response.reports.first.column_header
|
42
79
|
end
|
43
80
|
|
44
81
|
def metrics
|
@@ -66,7 +103,7 @@ module Hisui
|
|
66
103
|
end
|
67
104
|
|
68
105
|
def data
|
69
|
-
@data
|
106
|
+
@data ||= response.reports.first.data
|
70
107
|
end
|
71
108
|
end
|
72
109
|
end
|
data/lib/hisui/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hisui
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ikepon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-06-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -193,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
193
193
|
version: '0'
|
194
194
|
requirements: []
|
195
195
|
rubyforge_project:
|
196
|
-
rubygems_version: 2.6
|
196
|
+
rubygems_version: 2.7.6
|
197
197
|
signing_key:
|
198
198
|
specification_version: 4
|
199
199
|
summary: Access the Google Analytics Reporting API v4 On Rails
|