Class: Ga4Rails::Client
- Inherits:
-
Object
- Object
- Ga4Rails::Client
- Defined in:
- lib/ga4-rails/client.rb
Overview
A client for interacting with the Google Analytics API.
Instance Attribute Summary collapse
-
#access_token ⇒ OAuth2::AccessToken
readonly
-
the access token obtained from the Google OAuth2 flow.
-
Instance Method Summary collapse
-
#admin ⇒ Ga4Rails::AnalyticsAdmin
Returns an instance of the AnalyticsAdmin class.
-
#available_dimensions(property:) ⇒ Array
Returns an array of available dimensions for a property.
-
#available_metrics(property:) ⇒ Array
Returns an array of available metrics for a property.
- #data ⇒ Object
-
#initialize(access_token:) ⇒ Client
constructor
Initializes a new client.
-
#profiles ⇒ Object
TODO.
-
#run_property_report(property_id:, body:) ⇒ Object
Returns property report for a given property developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/runReport.
Constructor Details
#initialize(access_token:) ⇒ Client
Initializes a new client.
19 20 21 |
# File 'lib/ga4-rails/client.rb', line 19 def initialize(access_token:) @access_token = access_token end |
Instance Attribute Details
#access_token ⇒ OAuth2::AccessToken (readonly)
- the access token obtained from the Google OAuth2 flow
12 13 14 |
# File 'lib/ga4-rails/client.rb', line 12 def access_token @access_token end |
Instance Method Details
#admin ⇒ Ga4Rails::AnalyticsAdmin
Returns an instance of the AnalyticsAdmin class.
27 28 29 |
# File 'lib/ga4-rails/client.rb', line 27 def admin analytics_admin_service end |
#available_dimensions(property:) ⇒ Array
Returns an array of available dimensions for a property.
Example: ‘properties/341194148’
58 59 60 61 62 63 |
# File 'lib/ga4-rails/client.rb', line 58 def available_dimensions(property:) Ga4Rails::GetPropertyMetadata.call( data_service: analytics_data_service, property_id: property ).dimensions end |
#available_metrics(property:) ⇒ Array
Returns an array of available metrics for a property.
Example: ‘properties/341194148’
43 44 45 46 47 48 |
# File 'lib/ga4-rails/client.rb', line 43 def available_metrics(property:) Ga4Rails::GetPropertyMetadata.call( data_service: analytics_data_service, property_id: property ).metrics end |
#data ⇒ Object
31 32 33 |
# File 'lib/ga4-rails/client.rb', line 31 def data analytics_data_service end |
#profiles ⇒ Object
TODO
93 94 |
# File 'lib/ga4-rails/client.rb', line 93 def profiles end |
#run_property_report(property_id:, body:) ⇒ Object
Returns property report for a given property developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/runReport
84 85 86 87 88 89 90 |
# File 'lib/ga4-rails/client.rb', line 84 def run_property_report(property_id:, body:) Ga4Rails::RunPropertyReport.call( data_service: analytics_data_service, property_id: property_id, body: body ) end |