Class: Ga4Rails::GetPropertyMetadata

Inherits:
Request
  • Object
show all
Defined in:
lib/ga4-rails/requests/get_property_metadata.rb

Overview

A class for running GA Data Api property report.

Usage: metrics = Ga4Rails::GetPropertyMetadata.new(

data_service: data_service,
property_id: property_id

).metrics dimensions = Ga4Rails::GetPropertyMetadata.new(

data_service: data_service,
property_id: property_id

).dimensions

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Request

call

Constructor Details

#initialize(data_service:, property_id:) ⇒ GetPropertyMetadata

Returns a new instance of GetPropertyMetadata.



22
23
24
25
# File 'lib/ga4-rails/requests/get_property_metadata.rb', line 22

def initialize(data_service:, property_id:)
  @data_service = data_service
  @property_id = property_id
end

Instance Attribute Details

#data_serviceGa4Rails::AnalyticsData

- the data service wraper to run the report

Returns:



19
20
21
# File 'lib/ga4-rails/requests/get_property_metadata.rb', line 19

def data_service
  @data_service
end

#property_idString

- the GA4 roperty ID, example: ‘properties/341194148’

Returns:

  • (String)

    the current value of property_id



19
20
21
# File 'lib/ga4-rails/requests/get_property_metadata.rb', line 19

def property_id
  @property_id
end

#responseObject

Returns the value of attribute response.



20
21
22
# File 'lib/ga4-rails/requests/get_property_metadata.rb', line 20

def response
  @response
end

Instance Method Details

#callObject



35
36
37
38
39
# File 'lib/ga4-rails/requests/get_property_metadata.rb', line 35

def call
  @response = data_service.("#{property_id}/metadata")

  self
end

#dimensionsObject



31
32
33
# File 'lib/ga4-rails/requests/get_property_metadata.rb', line 31

def dimensions
  @dimensions ||= JSON.parse(response.dimensions.to_json)
end

#metricsObject



27
28
29
# File 'lib/ga4-rails/requests/get_property_metadata.rb', line 27

def metrics
  @metrics ||= JSON.parse(response.metrics.to_json)
end