Class: Ga4Rails::RunPropertyReport

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

Overview

A class for running GA Data Api property report.

Usage: response = Ga4Rails::RunPropertyReport.new(

data_service: data_service,
property_id: property_id,
body: body

).response

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Request

call

Constructor Details

#initialize(data_service:, property_id:, body:) ⇒ RunPropertyReport

Returns a new instance of RunPropertyReport.



33
34
35
36
37
# File 'lib/ga4-rails/requests/run_property_report.rb', line 33

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

Instance Attribute Details

#bodyString

- the report request body, example:

 body = {
  "date_ranges": [
    {
      "start_date": "30daysAgo",
      "end_date": "today"
    }
  ],
  "metrics": [
    { name: "totalUsers" }
  ]
}

Returns:

  • (String)

    the current value of body



30
31
32
# File 'lib/ga4-rails/requests/run_property_report.rb', line 30

def body
  @body
end

#data_serviceGa4Rails::AnalyticsData

- the data service wraper to run the report

Returns:



30
31
32
# File 'lib/ga4-rails/requests/run_property_report.rb', line 30

def data_service
  @data_service
end

#property_idString

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

Returns:

  • (String)

    the current value of property_id



30
31
32
# File 'lib/ga4-rails/requests/run_property_report.rb', line 30

def property_id
  @property_id
end

#responseObject

Returns the value of attribute response.



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

def response
  @response
end

Instance Method Details

#callObject



39
40
41
42
43
44
# File 'lib/ga4-rails/requests/run_property_report.rb', line 39

def call
  request = Google::Apis::AnalyticsdataV1beta::RunReportRequest.new(body)
  @response = data_service.run_property_report(property_id, request)

  self
end