Class: KlaviyoAPI::MetricsApi
- Inherits:
-
Object
- Object
- KlaviyoAPI::MetricsApi
- Defined in:
- lib/klaviyo-api-sdk/api/metrics_api.rb
Instance Attribute Summary collapse
-
#api_client ⇒ Object
Returns the value of attribute api_client.
Instance Method Summary collapse
-
#get_metric(id, opts = {}) ⇒ Hash<String, Object>
Get Metric Get a metric with the given metric ID.
*Rate limits*:
Burst: ‘10/s`
Steady: `150/m` Scopes: `metrics:read`. -
#get_metric_with_http_info(id, opts = {}) ⇒ Array<(Hash<String, Object>, Integer, Hash)>
Get Metric Get a metric with the given metric ID.<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` Scopes: `metrics:read`.
-
#get_metrics(opts = {}) ⇒ Hash<String, Object>
Get Metrics Get all metrics in an account.
-
#get_metrics_with_http_info(opts = {}) ⇒ Array<(Hash<String, Object>, Integer, Hash)>
Get Metrics Get all metrics in an account.
-
#initialize(api_client = ApiClient.default) ⇒ MetricsApi
constructor
A new instance of MetricsApi.
-
#query_metric_aggregates(metric_aggregate_query, opts = {}) ⇒ Hash<String, Object>
Query Metric Aggregates Query and aggregate event data associated with a metric, including native Klaviyo metrics, integration-specific metrics, and custom events.
-
#query_metric_aggregates_with_http_info(metric_aggregate_query, opts = {}) ⇒ Array<(Hash<String, Object>, Integer, Hash)>
Query Metric Aggregates Query and aggregate event data associated with a metric, including native Klaviyo metrics, integration-specific metrics, and custom events.
Constructor Details
#initialize(api_client = ApiClient.default) ⇒ MetricsApi
Returns a new instance of MetricsApi.
19 20 21 |
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 19 def initialize(api_client = ApiClient.default) @api_client = api_client end |
Instance Attribute Details
#api_client ⇒ Object
Returns the value of attribute api_client.
17 18 19 |
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 17 def api_client @api_client end |
Instance Method Details
#get_metric(id, opts = {}) ⇒ Hash<String, Object>
Get Metric Get a metric with the given metric ID.
*Rate limits*:
Burst: ‘10/s`
Steady: `150/m` Scopes: `metrics:read`
28 29 30 31 |
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 28 def get_metric(id, opts = {}) data, _status_code, _headers = get_metric_with_http_info(id, opts) data end |
#get_metric_with_http_info(id, opts = {}) ⇒ Array<(Hash<String, Object>, Integer, Hash)>
Get Metric Get a metric with the given metric ID.<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` Scopes: `metrics:read`
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 39 def get_metric_with_http_info(id, opts = {}) if @api_client.config.debugging @api_client.config.logger.debug 'Calling API: MetricsApi.get_metric ...' end # verify the required parameter 'id' is set if @api_client.config.client_side_validation && id.nil? fail ArgumentError, "Missing the required parameter 'id' when calling MetricsApi.get_metric" end allowable_values = ["name", "created", "updated", "integration"] if @api_client.config.client_side_validation && opts[:'fields_metric'] && !opts[:'fields_metric'].all? { |item| allowable_values.include?(item) } fail ArgumentError, "invalid value for \"fields_metric\", must include one of #{allowable_values}" end # resource path local_var_path = '/api/metrics/{id}/'.sub('{' + 'id' + '}', CGI.escape(id.to_s)) # query parameters query_params = opts[:query_params] || {} query_params[:'fields[metric]'] = @api_client.build_collection_param(opts[:'fields_metric'], :csv) if !opts[:'fields_metric'].nil? # header parameters header_params = opts[:header_params] || {} # klaviyo api revision header_params['revision'] = ENV['API_REVISION'] || "2023-08-15" # HTTP header 'Accept' (if needed) header_params['Accept'] = @api_client.select_header_accept(['application/json']) # form parameters form_params = opts[:form_params] || {} # http body (model) post_body = opts[:debug_body] # return_type return_type = opts[:debug_return_type] || 'Hash<String, Object>' # auth_names auth_names = opts[:debug_auth_names] || ['Klaviyo-API-Key'] = opts.merge( :operation => :"MetricsApi.get_metric", :header_params => header_params, :query_params => query_params, :form_params => form_params, :body => post_body, :auth_names => auth_names, :return_type => return_type ) data, status_code, headers = @api_client.call_api(:GET, local_var_path, ) if @api_client.config.debugging @api_client.config.logger.debug "API called: MetricsApi#get_metric\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end return data, status_code, headers end |
#get_metrics(opts = {}) ⇒ Hash<String, Object>
Get Metrics Get all metrics in an account. Requests can be filtered by the following fields: integration ‘name`, integration `category` Returns a maximum of 200 results per page.
*Rate limits*:
Burst: `10/s`
Steady: `150/m` Scopes: `metrics:read`
101 102 103 104 |
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 101 def get_metrics(opts = {}) data, _status_code, _headers = get_metrics_with_http_info(opts) data end |
#get_metrics_with_http_info(opts = {}) ⇒ Array<(Hash<String, Object>, Integer, Hash)>
Get Metrics Get all metrics in an account. Requests can be filtered by the following fields: integration `name`, integration `category` Returns a maximum of 200 results per page.<br><br>*Rate limits*:<br>Burst: `10/s`<br>Steady: `150/m` Scopes: `metrics:read`
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 113 def get_metrics_with_http_info(opts = {}) if @api_client.config.debugging @api_client.config.logger.debug 'Calling API: MetricsApi.get_metrics ...' end allowable_values = ["name", "created", "updated", "integration"] if @api_client.config.client_side_validation && opts[:'fields_metric'] && !opts[:'fields_metric'].all? { |item| allowable_values.include?(item) } fail ArgumentError, "invalid value for \"fields_metric\", must include one of #{allowable_values}" end # resource path local_var_path = '/api/metrics/' # query parameters query_params = opts[:query_params] || {} query_params[:'fields[metric]'] = @api_client.build_collection_param(opts[:'fields_metric'], :csv) if !opts[:'fields_metric'].nil? query_params[:'filter'] = opts[:'filter'] if !opts[:'filter'].nil? query_params[:'page[cursor]'] = opts[:'page_cursor'] if !opts[:'page_cursor'].nil? # header parameters header_params = opts[:header_params] || {} # klaviyo api revision header_params['revision'] = ENV['API_REVISION'] || "2023-08-15" # HTTP header 'Accept' (if needed) header_params['Accept'] = @api_client.select_header_accept(['application/json']) # form parameters form_params = opts[:form_params] || {} # http body (model) post_body = opts[:debug_body] # return_type return_type = opts[:debug_return_type] || 'Hash<String, Object>' # auth_names auth_names = opts[:debug_auth_names] || ['Klaviyo-API-Key'] = opts.merge( :operation => :"MetricsApi.get_metrics", :header_params => header_params, :query_params => query_params, :form_params => form_params, :body => post_body, :auth_names => auth_names, :return_type => return_type ) data, status_code, headers = @api_client.call_api(:GET, local_var_path, ) if @api_client.config.debugging @api_client.config.logger.debug "API called: MetricsApi#get_metrics\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end return data, status_code, headers end |
#query_metric_aggregates(metric_aggregate_query, opts = {}) ⇒ Hash<String, Object>
Query Metric Aggregates Query and aggregate event data associated with a metric, including native Klaviyo metrics, integration-specific metrics, and custom events. Queries must be passed in the JSON body of your ‘POST` request. Results can be filtered and grouped by time, event, or profile dimensions. To learn more about how to use this endpoint, check out our new [Using the Query Metric Aggregates Endpoint guide](developers.klaviyo.com/en/docs/using-the-query-metric-aggregates-endpoint). **Request body parameters** (nested under `attributes`): * `return_fields`: request specific fields using [sparse fieldsets](developers.klaviyo.com/en/reference/api_overview#sparse-fieldsets) * `sort`: sort results by a specified field, such as `"-timestamp"` * `page_cursor`: results can be paginated with [cursor-based pagination](developers.klaviyo.com/en/reference/api_overview#pagination) * `page_size`: limit the number of returned results per page * `by`: optional attributes used to group by the aggregation function * When using `by` attributes, an empty `dimensions` response is expected when the counts for the events do not have the associated dimension requested by the set `by` attribute. For example, a query including `"by": ["$flow"]` will return an empty dimensions response for counts of metrics not associated with a `$flow` * `measurement`: the measurement key supports the following values: * `"sum_value"`: perform a summation of the `_Event Value_`, optionally partitioned over any dimension provided in the `by` field * `"count"`: counts the number of events associated to a metric, optionally partitioned over any dimension provided in the `by` field * `"unique"` counts the number of unique customers associated to a metric, optionally partitioned over any dimension provided in the `by` field * `interval`: aggregation interval, such as `"hour"`,`"day"`,`"week"`, and `"month"` * `metric_id`: the metric ID used in the aggregation * `filter`: list of filters for specific fields, must include time range using ISO 8601 format (`"YYYY-MM-DDTHH:MM:SS.mmmmmm"`) * The time range can be filtered by providing a `greater-or-equal` filter on the datetime field, such as `"greater-or-equal(datetime,2021-07-01T00:00:00)"` and a `less-than` filter on the same datetime field, such as `"less-than(datetime,2022-07-01T00:00:00)"` * The time range may span a maximum of one year. Time range dates may be set to a maximum of 5 years prior to the current date * Filter the list of supported aggregate dimensions using the common filter syntax, such as `"equals(URL,\"www.klaviyo.com/\")"` * `timezone`: the timezone used when processing the query. Case sensitive. This field is validated against a list of common timezones from the [IANA Time Zone Database](www.iana.org/time-zones) * While the payload accepts a timezone, the response datetimes returned will be in UTC. For a comprehensive list of native Klaviyo metrics and their associated attributes for grouping and filtering, please refer to the [metrics attributes guide](developers.klaviyo.com/en/docs/supported_metrics_and_attributes).
*Rate limits*:
Burst: `3/s`
Steady: `60/m` Scopes: `metrics:read`
171 172 173 174 |
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 171 def query_metric_aggregates(metric_aggregate_query, opts = {}) data, _status_code, _headers = query_metric_aggregates_with_http_info(metric_aggregate_query, opts) data end |
#query_metric_aggregates_with_http_info(metric_aggregate_query, opts = {}) ⇒ Array<(Hash<String, Object>, Integer, Hash)>
Query Metric Aggregates Query and aggregate event data associated with a metric, including native Klaviyo metrics, integration-specific metrics, and custom events. Queries must be passed in the JSON body of your `POST` request. Results can be filtered and grouped by time, event, or profile dimensions. To learn more about how to use this endpoint, check out our new [Using the Query Metric Aggregates Endpoint guide](developers.klaviyo.com/en/docs/using-the-query-metric-aggregates-endpoint). **Request body parameters** (nested under `attributes`): * `return_fields`: request specific fields using [sparse fieldsets](developers.klaviyo.com/en/reference/api_overview#sparse-fieldsets) * `sort`: sort results by a specified field, such as `"-timestamp"` * `page_cursor`: results can be paginated with [cursor-based pagination](developers.klaviyo.com/en/reference/api_overview#pagination) * `page_size`: limit the number of returned results per page * `by`: optional attributes used to group by the aggregation function * When using `by` attributes, an empty `dimensions` response is expected when the counts for the events do not have the associated dimension requested by the set `by` attribute. For example, a query including `"by": ["$flow"]` will return an empty dimensions response for counts of metrics not associated with a `$flow` * `measurement`: the measurement key supports the following values: * `"sum_value"`: perform a summation of the `_Event Value_`, optionally partitioned over any dimension provided in the `by` field * `"count"`: counts the number of events associated to a metric, optionally partitioned over any dimension provided in the `by` field * `"unique"` counts the number of unique customers associated to a metric, optionally partitioned over any dimension provided in the `by` field * `interval`: aggregation interval, such as `"hour"`,`"day"`,`"week"`, and `"month"` * `metric_id`: the metric ID used in the aggregation * `filter`: list of filters for specific fields, must include time range using ISO 8601 format (`"YYYY-MM-DDTHH:MM:SS.mmmmmm"`) * The time range can be filtered by providing a `greater-or-equal` filter on the datetime field, such as `"greater-or-equal(datetime,2021-07-01T00:00:00)"` and a `less-than` filter on the same datetime field, such as `"less-than(datetime,2022-07-01T00:00:00)"` * The time range may span a maximum of one year. Time range dates may be set to a maximum of 5 years prior to the current date * Filter the list of supported aggregate dimensions using the common filter syntax, such as `"equals(URL,\"www.klaviyo.com/\")"` * `timezone`: the timezone used when processing the query. Case sensitive. This field is validated against a list of common timezones from the [IANA Time Zone Database](www.iana.org/time-zones) * While the payload accepts a timezone, the response datetimes returned will be in UTC. For a comprehensive list of native Klaviyo metrics and their associated attributes for grouping and filtering, please refer to the [metrics attributes guide](developers.klaviyo.com/en/docs/supported_metrics_and_attributes).<br><br>*Rate limits*:<br>Burst: `3/s`<br>Steady: `60/m` Scopes: `metrics:read`
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/klaviyo-api-sdk/api/metrics_api.rb', line 181 def query_metric_aggregates_with_http_info(metric_aggregate_query, opts = {}) if @api_client.config.debugging @api_client.config.logger.debug 'Calling API: MetricsApi.query_metric_aggregates ...' end # verify the required parameter 'metric_aggregate_query' is set if @api_client.config.client_side_validation && metric_aggregate_query.nil? fail ArgumentError, "Missing the required parameter 'metric_aggregate_query' when calling MetricsApi.query_metric_aggregates" end # resource path local_var_path = '/api/metric-aggregates/' # query parameters query_params = opts[:query_params] || {} # header parameters header_params = opts[:header_params] || {} # klaviyo api revision header_params['revision'] = ENV['API_REVISION'] || "2023-08-15" # HTTP header 'Accept' (if needed) header_params['Accept'] = @api_client.select_header_accept(['application/json']) # HTTP header 'Content-Type' content_type = @api_client.select_header_content_type(['application/json']) if !content_type.nil? header_params['Content-Type'] = content_type end # form parameters form_params = opts[:form_params] || {} # http body (model) post_body = opts[:debug_body] || @api_client.object_to_http_body(metric_aggregate_query) # return_type return_type = opts[:debug_return_type] || 'Hash<String, Object>' # auth_names auth_names = opts[:debug_auth_names] || ['Klaviyo-API-Key'] = opts.merge( :operation => :"MetricsApi.query_metric_aggregates", :header_params => header_params, :query_params => query_params, :form_params => form_params, :body => post_body, :auth_names => auth_names, :return_type => return_type ) data, status_code, headers = @api_client.call_api(:POST, local_var_path, ) if @api_client.config.debugging @api_client.config.logger.debug "API called: MetricsApi#query_metric_aggregates\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end return data, status_code, headers end |