Class: CypressViewportUpdater::GoogleAnalyticsReports
- Inherits:
-
Object
- Object
- CypressViewportUpdater::GoogleAnalyticsReports
show all
- Includes:
- Google::Apis::AnalyticsreportingV4, Google::Auth, SentryLogging
- Defined in:
- app/sidekiq/cypress_viewport_updater/google_analytics_reports.rb
Constant Summary
collapse
- JSON_CREDENTIALS =
Settings.google_analytics_cvu.to_json
- SCOPE =
'https://www.googleapis.com/auth/analytics.readonly'
- VIEW_ID =
'176188361'
Instance Method Summary
collapse
#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger, #set_sentry_metadata
Constructor Details
Returns a new instance of GoogleAnalyticsReports.
15
16
17
18
19
20
21
22
|
# File 'app/sidekiq/cypress_viewport_updater/google_analytics_reports.rb', line 15
def initialize
@analytics = AnalyticsReportingService.new
@analytics.authorization = ServiceAccountCredentials.make_creds(
json_key_io: StringIO.new(JSON_CREDENTIALS),
scope: SCOPE
)
@reports = nil
end
|
Instance Method Details
#dimension_device_category ⇒ Object
77
78
79
|
# File 'app/sidekiq/cypress_viewport_updater/google_analytics_reports.rb', line 77
def dimension_device_category
Dimension.new(name: 'ga:deviceCategory')
end
|
#dimension_screen_resolution ⇒ Object
81
82
83
|
# File 'app/sidekiq/cypress_viewport_updater/google_analytics_reports.rb', line 81
def dimension_screen_resolution
Dimension.new(name: 'ga:screenResolution')
end
|
#metric_user ⇒ Object
73
74
75
|
# File 'app/sidekiq/cypress_viewport_updater/google_analytics_reports.rb', line 73
def metric_user
Metric.new(expression: 'ga:users')
end
|
#request_reports ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'app/sidekiq/cypress_viewport_updater/google_analytics_reports.rb', line 24
def request_reports
request = GetReportsRequest.new(report_requests: [
user_report_request,
viewport_report_request
])
begin
@reports = @analytics.batch_get_reports(request).reports
rescue => e
log_exception_to_sentry(e)
end
self
end
|
#user_report ⇒ Object
38
39
40
|
# File 'app/sidekiq/cypress_viewport_updater/google_analytics_reports.rb', line 38
def user_report
@reports[0] if @reports && @reports[0]
end
|
#user_report_request ⇒ Object
48
49
50
51
52
53
54
|
# File 'app/sidekiq/cypress_viewport_updater/google_analytics_reports.rb', line 48
def user_report_request
ReportRequest.new(
view_id: VIEW_ID,
date_ranges: [date_range],
metrics: [metric_user]
)
end
|
#viewport_report ⇒ Object
42
43
44
|
# File 'app/sidekiq/cypress_viewport_updater/google_analytics_reports.rb', line 42
def viewport_report
@reports[1] if @reports && @reports[1]
end
|
#viewport_report_request ⇒ Object
56
57
58
59
60
61
62
63
64
65
|
# File 'app/sidekiq/cypress_viewport_updater/google_analytics_reports.rb', line 56
def viewport_report_request
ReportRequest.new(
view_id: VIEW_ID,
date_ranges: [date_range],
metrics: [metric_user],
dimensions: [dimension_device_category, dimension_screen_resolution],
order_bys: [{ field_name: 'ga:users', sort_order: 'DESCENDING' }],
page_size: 100
)
end
|