Class: Zernio::AdInsightsApi
- Inherits:
-
Object
- Object
- Zernio::AdInsightsApi
- Defined in:
- lib/zernio-sdk/api/ad_insights_api.rb
Instance Attribute Summary collapse
-
#api_client ⇒ Object
Returns the value of attribute api_client.
Instance Method Summary collapse
-
#create_ad_insights_report(create_ad_insights_report_request, opts = {}) ⇒ CreateAdInsightsReport202Response
Submit an async insights report run Submits an asynchronous Meta insights report.
-
#create_ad_insights_report_with_http_info(create_ad_insights_report_request, opts = {}) ⇒ Array<(CreateAdInsightsReport202Response, Integer, Hash)>
Submit an async insights report run Submits an asynchronous Meta insights report.
-
#get_ad_analytics(ad_id, opts = {}) ⇒ GetAdAnalytics200Response
Get ad analytics Returns detailed performance analytics for an ad.
-
#get_ad_analytics_with_http_info(ad_id, opts = {}) ⇒ Array<(GetAdAnalytics200Response, Integer, Hash)>
Get ad analytics Returns detailed performance analytics for an ad.
-
#get_ad_insights_report(report_run_id, account_id, opts = {}) ⇒ GetAdInsightsReport200Response
Poll an async insights report run Status and results for a report run created via POST /v1/ads/insights/reports.
-
#get_ad_insights_report_with_http_info(report_run_id, account_id, opts = {}) ⇒ Array<(GetAdInsightsReport200Response, Integer, Hash)>
Poll an async insights report run Status and results for a report run created via POST /v1/ads/insights/reports.
-
#get_campaign_analytics(campaign_id, opts = {}) ⇒ GetCampaignAnalytics200Response
Get campaign analytics Returns performance analytics for a whole campaign in one call: summary metrics, a daily timeline over the requested date range (summed across the campaign's ads), and optional demographic breakdowns.
-
#get_campaign_analytics_with_http_info(campaign_id, opts = {}) ⇒ Array<(GetCampaignAnalytics200Response, Integer, Hash)>
Get campaign analytics Returns performance analytics for a whole campaign in one call: summary metrics, a daily timeline over the requested date range (summed across the campaign's ads), and optional demographic breakdowns.
-
#initialize(api_client = ApiClient.default) ⇒ AdInsightsApi
constructor
A new instance of AdInsightsApi.
-
#query_ad_insights(account_id, object_id, opts = {}) ⇒ QueryAdInsights200Response
Flexible live insights query Live, flexible insights query against Meta's Graph API.
-
#query_ad_insights_with_http_info(account_id, object_id, opts = {}) ⇒ Array<(QueryAdInsights200Response, Integer, Hash)>
Flexible live insights query Live, flexible insights query against Meta's Graph API.
Constructor Details
#initialize(api_client = ApiClient.default) ⇒ AdInsightsApi
Returns a new instance of AdInsightsApi.
19 20 21 |
# File 'lib/zernio-sdk/api/ad_insights_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/zernio-sdk/api/ad_insights_api.rb', line 17 def api_client @api_client end |
Instance Method Details
#create_ad_insights_report(create_ad_insights_report_request, opts = {}) ⇒ CreateAdInsightsReport202Response
Submit an async insights report run
Submits an asynchronous Meta insights report. Same query surface as GET /v1/ads/insights, but in the JSON body; Meta processes the report server-side, which is the right choice for long ranges or large accounts where the sync query is slow or rate-limited. Returns a reportRunId to poll via GET /v1/ads/insights/reports/reportRunId.
27 28 29 30 |
# File 'lib/zernio-sdk/api/ad_insights_api.rb', line 27 def create_ad_insights_report(create_ad_insights_report_request, opts = {}) data, _status_code, _headers = create_ad_insights_report_with_http_info(create_ad_insights_report_request, opts) data end |
#create_ad_insights_report_with_http_info(create_ad_insights_report_request, opts = {}) ⇒ Array<(CreateAdInsightsReport202Response, Integer, Hash)>
Submit an async insights report run Submits an asynchronous Meta insights report. Same query surface as GET /v1/ads/insights, but in the JSON body; Meta processes the report server-side, which is the right choice for long ranges or large accounts where the sync query is slow or rate-limited. Returns a `reportRunId` to poll via GET /v1/ads/insights/reports/reportRunId.
37 38 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 |
# File 'lib/zernio-sdk/api/ad_insights_api.rb', line 37 def create_ad_insights_report_with_http_info(create_ad_insights_report_request, opts = {}) if @api_client.config.debugging @api_client.config.logger.debug 'Calling API: AdInsightsApi.create_ad_insights_report ...' end # verify the required parameter 'create_ad_insights_report_request' is set if @api_client.config.client_side_validation && create_ad_insights_report_request.nil? fail ArgumentError, "Missing the required parameter 'create_ad_insights_report_request' when calling AdInsightsApi.create_ad_insights_report" end # resource path local_var_path = '/v1/ads/insights/reports' # query parameters query_params = opts[:query_params] || {} # header parameters header_params = opts[:header_params] || {} # HTTP header 'Accept' (if needed) header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept'] # 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(create_ad_insights_report_request) # return_type return_type = opts[:debug_return_type] || 'CreateAdInsightsReport202Response' # auth_names auth_names = opts[:debug_auth_names] || ['bearerAuth'] = opts.merge( :operation => :"AdInsightsApi.create_ad_insights_report", :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: AdInsightsApi#create_ad_insights_report\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end return data, status_code, headers end |
#get_ad_analytics(ad_id, opts = {}) ⇒ GetAdAnalytics200Response
Get ad analytics Returns detailed performance analytics for an ad. Includes summary metrics, a daily timeline over the requested date range, and optional demographic breakdowns (Meta and TikTok only). If no date range is provided, defaults to the last 90 days. Date range is capped at 730 days max.
98 99 100 101 |
# File 'lib/zernio-sdk/api/ad_insights_api.rb', line 98 def get_ad_analytics(ad_id, opts = {}) data, _status_code, _headers = get_ad_analytics_with_http_info(ad_id, opts) data end |
#get_ad_analytics_with_http_info(ad_id, opts = {}) ⇒ Array<(GetAdAnalytics200Response, Integer, Hash)>
Get ad analytics Returns detailed performance analytics for an ad. Includes summary metrics, a daily timeline over the requested date range, and optional demographic breakdowns (Meta and TikTok only). If no date range is provided, defaults to the last 90 days. Date range is capped at 730 days max.
111 112 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 |
# File 'lib/zernio-sdk/api/ad_insights_api.rb', line 111 def get_ad_analytics_with_http_info(ad_id, opts = {}) if @api_client.config.debugging @api_client.config.logger.debug 'Calling API: AdInsightsApi.get_ad_analytics ...' end # verify the required parameter 'ad_id' is set if @api_client.config.client_side_validation && ad_id.nil? fail ArgumentError, "Missing the required parameter 'ad_id' when calling AdInsightsApi.get_ad_analytics" end # resource path local_var_path = '/v1/ads/{adId}/analytics'.sub('{' + 'adId' + '}', CGI.escape(ad_id.to_s)) # query parameters query_params = opts[:query_params] || {} query_params[:'fromDate'] = opts[:'from_date'] if !opts[:'from_date'].nil? query_params[:'toDate'] = opts[:'to_date'] if !opts[:'to_date'].nil? query_params[:'breakdowns'] = opts[:'breakdowns'] if !opts[:'breakdowns'].nil? # header parameters header_params = opts[:header_params] || {} # HTTP header 'Accept' (if needed) header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept'] # form parameters form_params = opts[:form_params] || {} # http body (model) post_body = opts[:debug_body] # return_type return_type = opts[:debug_return_type] || 'GetAdAnalytics200Response' # auth_names auth_names = opts[:debug_auth_names] || ['bearerAuth'] = opts.merge( :operation => :"AdInsightsApi.get_ad_analytics", :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: AdInsightsApi#get_ad_analytics\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end return data, status_code, headers end |
#get_ad_insights_report(report_run_id, account_id, opts = {}) ⇒ GetAdInsightsReport200Response
Poll an async insights report run
Status and results for a report run created via POST /v1/ads/insights/reports. While the job runs, returns status and percentCompletion. Once status is "Job Completed" the response also carries a data page, cursor-paginated via limit / after.
170 171 172 173 |
# File 'lib/zernio-sdk/api/ad_insights_api.rb', line 170 def get_ad_insights_report(report_run_id, account_id, opts = {}) data, _status_code, _headers = get_ad_insights_report_with_http_info(report_run_id, account_id, opts) data end |
#get_ad_insights_report_with_http_info(report_run_id, account_id, opts = {}) ⇒ Array<(GetAdInsightsReport200Response, Integer, Hash)>
Poll an async insights report run Status and results for a report run created via POST /v1/ads/insights/reports. While the job runs, returns `status` and `percentCompletion`. Once `status` is "Job Completed" the response also carries a `data` page, cursor-paginated via `limit` / `after`.
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 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/zernio-sdk/api/ad_insights_api.rb', line 183 def get_ad_insights_report_with_http_info(report_run_id, account_id, opts = {}) if @api_client.config.debugging @api_client.config.logger.debug 'Calling API: AdInsightsApi.get_ad_insights_report ...' end # verify the required parameter 'report_run_id' is set if @api_client.config.client_side_validation && report_run_id.nil? fail ArgumentError, "Missing the required parameter 'report_run_id' when calling AdInsightsApi.get_ad_insights_report" end # verify the required parameter 'account_id' is set if @api_client.config.client_side_validation && account_id.nil? fail ArgumentError, "Missing the required parameter 'account_id' when calling AdInsightsApi.get_ad_insights_report" end if @api_client.config.client_side_validation && !opts[:'limit'].nil? && opts[:'limit'] > 500 fail ArgumentError, 'invalid value for "opts[:"limit"]" when calling AdInsightsApi.get_ad_insights_report, must be smaller than or equal to 500.' end if @api_client.config.client_side_validation && !opts[:'limit'].nil? && opts[:'limit'] < 1 fail ArgumentError, 'invalid value for "opts[:"limit"]" when calling AdInsightsApi.get_ad_insights_report, must be greater than or equal to 1.' end # resource path local_var_path = '/v1/ads/insights/reports/{reportRunId}'.sub('{' + 'reportRunId' + '}', CGI.escape(report_run_id.to_s)) # query parameters query_params = opts[:query_params] || {} query_params[:'accountId'] = account_id query_params[:'limit'] = opts[:'limit'] if !opts[:'limit'].nil? query_params[:'after'] = opts[:'after'] if !opts[:'after'].nil? # header parameters header_params = opts[:header_params] || {} # HTTP header 'Accept' (if needed) header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept'] # form parameters form_params = opts[:form_params] || {} # http body (model) post_body = opts[:debug_body] # return_type return_type = opts[:debug_return_type] || 'GetAdInsightsReport200Response' # auth_names auth_names = opts[:debug_auth_names] || ['bearerAuth'] = opts.merge( :operation => :"AdInsightsApi.get_ad_insights_report", :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: AdInsightsApi#get_ad_insights_report\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end return data, status_code, headers end |
#get_campaign_analytics(campaign_id, opts = {}) ⇒ GetCampaignAnalytics200Response
Get campaign analytics
Returns performance analytics for a whole campaign in one call: summary metrics, a daily timeline over the requested date range (summed across the campaign's ads), and optional demographic breakdowns. Breakdowns are fetched live from Meta at the campaign level (one call per dimension, no per-ad fan-out), so an agency dashboard gets campaign-level age/gender/etc. without summing thousands of per-ad reads. campaignId is the platform campaign id; pass platform when a campaign id could be ambiguous across platforms. If no date range is provided, defaults to the last 90 days. Date range is capped at 730 days max.
255 256 257 258 |
# File 'lib/zernio-sdk/api/ad_insights_api.rb', line 255 def get_campaign_analytics(campaign_id, opts = {}) data, _status_code, _headers = get_campaign_analytics_with_http_info(campaign_id, opts) data end |
#get_campaign_analytics_with_http_info(campaign_id, opts = {}) ⇒ Array<(GetCampaignAnalytics200Response, Integer, Hash)>
Get campaign analytics Returns performance analytics for a whole campaign in one call: summary metrics, a daily timeline over the requested date range (summed across the campaign's ads), and optional demographic breakdowns. Breakdowns are fetched live from Meta at the campaign level (one call per dimension, no per-ad fan-out), so an agency dashboard gets campaign-level age/gender/etc. without summing thousands of per-ad reads. `campaignId` is the platform campaign id; pass `platform` when a campaign id could be ambiguous across platforms. If no date range is provided, defaults to the last 90 days. Date range is capped at 730 days max.
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 |
# File 'lib/zernio-sdk/api/ad_insights_api.rb', line 269 def get_campaign_analytics_with_http_info(campaign_id, opts = {}) if @api_client.config.debugging @api_client.config.logger.debug 'Calling API: AdInsightsApi.get_campaign_analytics ...' end # verify the required parameter 'campaign_id' is set if @api_client.config.client_side_validation && campaign_id.nil? fail ArgumentError, "Missing the required parameter 'campaign_id' when calling AdInsightsApi.get_campaign_analytics" end # resource path local_var_path = '/v1/ads/campaigns/{campaignId}/analytics'.sub('{' + 'campaignId' + '}', CGI.escape(campaign_id.to_s)) # query parameters query_params = opts[:query_params] || {} query_params[:'platform'] = opts[:'platform'] if !opts[:'platform'].nil? query_params[:'fromDate'] = opts[:'from_date'] if !opts[:'from_date'].nil? query_params[:'toDate'] = opts[:'to_date'] if !opts[:'to_date'].nil? query_params[:'breakdowns'] = opts[:'breakdowns'] if !opts[:'breakdowns'].nil? # header parameters header_params = opts[:header_params] || {} # HTTP header 'Accept' (if needed) header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept'] # form parameters form_params = opts[:form_params] || {} # http body (model) post_body = opts[:debug_body] # return_type return_type = opts[:debug_return_type] || 'GetCampaignAnalytics200Response' # auth_names auth_names = opts[:debug_auth_names] || ['bearerAuth'] = opts.merge( :operation => :"AdInsightsApi.get_campaign_analytics", :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: AdInsightsApi#get_campaign_analytics\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end return data, status_code, headers end |
#query_ad_insights(account_id, object_id, opts = {}) ⇒ QueryAdInsights200Response
Flexible live insights query
Live, flexible insights query against Meta's Graph API. Unlike GET /v1/ads/adId/analytics (fixed metric set, cached), this forwards caller-chosen fields, breakdowns and filtering to any Meta insights node and returns Meta's rows verbatim. objectId selects the node: an ad account, campaign, ad set or ad platform id. level sets row granularity independently of the node. Semantic validation is Meta's: an unknown field or invalid breakdown combination returns a 400 carrying Meta's message. For long ranges or agency-scale accounts prefer the async variant (POST /v1/ads/insights/reports).
341 342 343 344 |
# File 'lib/zernio-sdk/api/ad_insights_api.rb', line 341 def query_ad_insights(account_id, object_id, opts = {}) data, _status_code, _headers = query_ad_insights_with_http_info(account_id, object_id, opts) data end |
#query_ad_insights_with_http_info(account_id, object_id, opts = {}) ⇒ Array<(QueryAdInsights200Response, Integer, Hash)>
Flexible live insights query Live, flexible insights query against Meta's Graph API. Unlike GET /v1/ads/adId/analytics (fixed metric set, cached), this forwards caller-chosen `fields`, `breakdowns` and `filtering` to any Meta insights node and returns Meta's rows verbatim. `objectId` selects the node: an ad account, campaign, ad set or ad platform id. `level` sets row granularity independently of the node. Semantic validation is Meta's: an unknown field or invalid breakdown combination returns a 400 carrying Meta's message. For long ranges or agency-scale accounts prefer the async variant (POST /v1/ads/insights/reports).
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 |
# File 'lib/zernio-sdk/api/ad_insights_api.rb', line 366 def query_ad_insights_with_http_info(account_id, object_id, opts = {}) if @api_client.config.debugging @api_client.config.logger.debug 'Calling API: AdInsightsApi.query_ad_insights ...' end # verify the required parameter 'account_id' is set if @api_client.config.client_side_validation && account_id.nil? fail ArgumentError, "Missing the required parameter 'account_id' when calling AdInsightsApi.query_ad_insights" end # verify the required parameter 'object_id' is set if @api_client.config.client_side_validation && object_id.nil? fail ArgumentError, "Missing the required parameter 'object_id' when calling AdInsightsApi.query_ad_insights" end allowable_values = ["ad", "adset", "campaign", "account"] if @api_client.config.client_side_validation && opts[:'level'] && !allowable_values.include?(opts[:'level']) fail ArgumentError, "invalid value for \"level\", must be one of #{allowable_values}" end if @api_client.config.client_side_validation && !opts[:'limit'].nil? && opts[:'limit'] > 500 fail ArgumentError, 'invalid value for "opts[:"limit"]" when calling AdInsightsApi.query_ad_insights, must be smaller than or equal to 500.' end if @api_client.config.client_side_validation && !opts[:'limit'].nil? && opts[:'limit'] < 1 fail ArgumentError, 'invalid value for "opts[:"limit"]" when calling AdInsightsApi.query_ad_insights, must be greater than or equal to 1.' end # resource path local_var_path = '/v1/ads/insights' # query parameters query_params = opts[:query_params] || {} query_params[:'accountId'] = account_id query_params[:'objectId'] = object_id query_params[:'level'] = opts[:'level'] if !opts[:'level'].nil? query_params[:'fields'] = opts[:'fields'] if !opts[:'fields'].nil? query_params[:'breakdowns'] = opts[:'breakdowns'] if !opts[:'breakdowns'].nil? query_params[:'actionBreakdowns'] = opts[:'action_breakdowns'] if !opts[:'action_breakdowns'].nil? query_params[:'actionAttributionWindows'] = opts[:'action_attribution_windows'] if !opts[:'action_attribution_windows'].nil? query_params[:'actionReportTime'] = opts[:'action_report_time'] if !opts[:'action_report_time'].nil? query_params[:'useUnifiedAttributionSetting'] = opts[:'use_unified_attribution_setting'] if !opts[:'use_unified_attribution_setting'].nil? query_params[:'filtering'] = opts[:'filtering'] if !opts[:'filtering'].nil? query_params[:'datePreset'] = opts[:'date_preset'] if !opts[:'date_preset'].nil? query_params[:'fromDate'] = opts[:'from_date'] if !opts[:'from_date'].nil? query_params[:'toDate'] = opts[:'to_date'] if !opts[:'to_date'].nil? query_params[:'timeIncrement'] = opts[:'time_increment'] if !opts[:'time_increment'].nil? query_params[:'limit'] = opts[:'limit'] if !opts[:'limit'].nil? query_params[:'after'] = opts[:'after'] if !opts[:'after'].nil? # header parameters header_params = opts[:header_params] || {} # HTTP header 'Accept' (if needed) header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept'] # form parameters form_params = opts[:form_params] || {} # http body (model) post_body = opts[:debug_body] # return_type return_type = opts[:debug_return_type] || 'QueryAdInsights200Response' # auth_names auth_names = opts[:debug_auth_names] || ['bearerAuth'] = opts.merge( :operation => :"AdInsightsApi.query_ad_insights", :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: AdInsightsApi#query_ad_insights\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end return data, status_code, headers end |