Class: Conversant::V3::Services::CDN::Analytics

Inherits:
Object
  • Object
show all
Defined in:
lib/conversant/v3/services/cdn/analytics.rb

Overview

Analytics service for CDN metrics and reporting

Provides comprehensive analytics data for CDN performance including:

  • Bandwidth and volume metrics
  • Viewer statistics
  • Request rates and hit rates
  • HTTP status code distribution
  • Referrer and popular content analytics
  • Origin request metrics
  • ISP and user agent analytics

Examples:

Basic usage

cdn = Conversant::V3.cdn(12345)

# Get bandwidth data
bandwidth = cdn.analytics.bandwidths({
  domain: "All",
  startTime: "2025-01-01T00:00:00Z",
  endTime: "2025-01-01T23:59:59Z",
  interval: "hour"
})

# Get viewer statistics
viewers = cdn.analytics.viewers({
  domain: "streaming.example.com",
  startTime: "2025-01-01T00:00:00Z",
  endTime: "2025-01-01T23:59:59Z",
  interval: "minute"
})

Since:

  • 1.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent) ⇒ Analytics

Initialize analytics service

Parameters:

  • parent (CDN)

    the parent CDN service instance

Since:

  • 1.0.0



45
46
47
# File 'lib/conversant/v3/services/cdn/analytics.rb', line 45

def initialize(parent)
  @parent = parent
end

Instance Attribute Details

#parentCDN (readonly)

Returns the parent CDN service instance.

Returns:

  • (CDN)

    the parent CDN service instance

Since:

  • 1.0.0



40
41
42
# File 'lib/conversant/v3/services/cdn/analytics.rb', line 40

def parent
  @parent
end

Instance Method Details

#bandwidths(payload) ⇒ Hash?

Get bandwidth analytics data

Examples:

Get hourly bandwidth for all domains

bandwidth = cdn.analytics.bandwidths({
  domain: "All",
  startTime: "2025-01-01T00:00:00Z",
  endTime: "2025-01-01T23:59:59Z",
  interval: "hour",
  fillFixedTime: true
})
puts bandwidth[:averageThroughput]
bandwidth[:data].each { |point| puts "#{point['time']}: #{point['value']}" }

Parameters:

  • payload (Hash)

    analytics parameters

Options Hash (payload):

  • :domain (String)

    domain name or "All" for all domains

  • :startTime (String)

    start time in ISO 8601 format ("2025-01-01T00:00:00Z")

  • :endTime (String)

    end time in ISO 8601 format

  • :interval (String)

    time interval ("minute", "hour", "day")

  • :fillFixedTime (Boolean)

    whether to fill missing time slots

  • :daHostName (String)

    specific hostname filter

Returns:

  • (Hash, nil)

    bandwidth data with averageThroughput and data array, or nil on error

Since:

  • 1.0.0



73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/conversant/v3/services/cdn/analytics.rb', line 73

def bandwidths(payload)
  response = JSON.parse(@parent.send(:call, 'POST', '/api/report/bandwidth', payload))
  if response&.[]('bandwidth')
    {
      averageThroughput: response&.[]('averageThroughput'),
      data: response&.[]('bandwidth'),
    }
  end
rescue StandardError => e
  @parent.send(:logger).error "#{@parent.send(:identifier)}.METHOD:#{__method__}.EXCEPTION:#{e.message}"
  nil
end

#byte_hit_rate(params) ⇒ Hash?

Get byte hit rate analytics

Parameters:

  • params (Hash)

    analytics parameters (passed as query string)

Returns:

  • (Hash, nil)

    byte hit rate data, or nil on error

Since:

  • 1.0.8



327
328
329
330
331
332
333
334
# File 'lib/conversant/v3/services/cdn/analytics.rb', line 327

def byte_hit_rate(params)
  query_string = URI.encode_www_form(params)
  response = JSON.parse(@parent.send(:call, 'GET', "/api/byte_rate_chart_data?#{query_string}", nil))
  response
rescue StandardError => e
  @parent.send(:logger).error "#{@parent.send(:identifier)}.METHOD:#{__method__}.EXCEPTION:#{e.message}"
  nil
end

#http_codes(payload) ⇒ Hash?

Get HTTP status code analytics

Examples:

Get HTTP status codes

codes = cdn.analytics.http_codes({
  domains: ["example.com"],
  startTime: "2025-01-01T00:00:00Z",
  endTime: "2025-01-01T23:59:59Z",
  interval: "hour"
})
puts "2xx responses: #{codes['2xx']}"
puts "4xx responses: #{codes['4xx']}"

Parameters:

  • payload (Hash)

    analytics parameters

Options Hash (payload):

  • :domains (Array<String>)

    array of domain names

  • :startTime (String)

    start time in ISO 8601 format

  • :endTime (String)

    end time in ISO 8601 format

  • :interval (String)

    time interval

Returns:

  • (Hash, nil)

    HTTP status code distribution data, or nil on error

Since:

  • 1.0.1



202
203
204
205
206
207
# File 'lib/conversant/v3/services/cdn/analytics.rb', line 202

def http_codes(payload)
  JSON.parse(@parent.send(:call, 'POST', "/api/report/customers/#{@parent.customer_id}/http_codes", payload))
rescue StandardError => e
  @parent.send(:logger).error "#{@parent.send(:identifier)}.METHOD:#{__method__}.EXCEPTION:#{e.message}"
  nil
end

#isp(payload) ⇒ Array

Get ISP analytics

Parameters:

  • payload (Hash)

    analytics parameters

Returns:

  • (Array)

    ISP data, or empty array on error

Since:

  • 1.0.8



446
447
448
449
450
451
452
# File 'lib/conversant/v3/services/cdn/analytics.rb', line 446

def isp(payload)
  response = JSON.parse(@parent.send(:call, 'POST', '/api/report/isp', payload))
  response || []
rescue StandardError => e
  @parent.send(:logger).error "#{@parent.send(:identifier)}.METHOD:#{__method__}.EXCEPTION:#{e.message}"
  []
end

#number_of_concurrent_viewers(payload) ⇒ Array

Get number of concurrent viewers by domain

Parameters:

  • payload (Hash)

    analytics parameters

Returns:

  • (Array)

    concurrent viewer data, or empty array on error

Since:

  • 1.0.8



354
355
356
357
358
359
360
# File 'lib/conversant/v3/services/cdn/analytics.rb', line 354

def number_of_concurrent_viewers(payload)
  response = JSON.parse(@parent.send(:call, 'POST', '/api/report/domain/viewers', payload))
  response || []
rescue StandardError => e
  @parent.send(:logger).error "#{@parent.send(:identifier)}.METHOD:#{__method__}.EXCEPTION:#{e.message}"
  []
end

#origin_bandwidth(payload) ⇒ Array

Get origin bandwidth analytics

Parameters:

  • payload (Hash)

    analytics parameters

Returns:

  • (Array)

    origin bandwidth data, or empty array on error

Since:

  • 1.0.8



341
342
343
344
345
346
347
# File 'lib/conversant/v3/services/cdn/analytics.rb', line 341

def origin_bandwidth(payload)
  response = JSON.parse(@parent.send(:call, 'POST', '/api/report/origin_bandwidth', payload))
  response || []
rescue StandardError => e
  @parent.send(:logger).error "#{@parent.send(:identifier)}.METHOD:#{__method__}.EXCEPTION:#{e.message}"
  []
end

#origin_http_codes(payload) ⇒ Array

Get origin HTTP status codes

Parameters:

  • payload (Hash)

    analytics parameters

Returns:

  • (Array)

    origin HTTP code data, or empty array on error

Since:

  • 1.0.8



367
368
369
370
371
372
373
374
# File 'lib/conversant/v3/services/cdn/analytics.rb', line 367

def origin_http_codes(payload)
  customer_id = @parent.send(:customer_id)
  response = JSON.parse(@parent.send(:call, 'POST', "/api/report/customers/#{customer_id}/origin_http_codes", payload))
  response || []
rescue StandardError => e
  @parent.send(:logger).error "#{@parent.send(:identifier)}.METHOD:#{__method__}.EXCEPTION:#{e.message}"
  []
end

#origin_request(payload) ⇒ Hash?

Get origin request analytics

Examples:

Get origin request data

origin = cdn.analytics.origin_request({
  domain: "example.com",
  startTime: "2025-01-01T00:00:00Z",
  endTime: "2025-01-01T23:59:59Z",
  interval: "hour"
})
origin[:data].each { |point| puts "#{point['time']}: #{point['requests']} origin requests" }

Parameters:

  • payload (Hash)

    analytics parameters (passed as query string)

Options Hash (payload):

  • :domain (String)

    domain name

  • :startTime (String)

    start time in ISO 8601 format

  • :endTime (String)

    end time in ISO 8601 format

  • :interval (String)

    time interval

Returns:

  • (Hash, nil)

    origin request data with time series, or nil on error

Since:

  • 1.0.0



293
294
295
296
297
298
299
# File 'lib/conversant/v3/services/cdn/analytics.rb', line 293

def origin_request(payload)
  response = JSON.parse(@parent.send(:call, 'GET', "/api/origin_request_chart_data?#{payload.to_query}"))
  { data: response['requestSpots'] } if response&.[]('requestSpots')
rescue StandardError => e
  @parent.send(:logger).error "#{@parent.send(:identifier)}.METHOD:#{__method__}.EXCEPTION:#{e.message}"
  nil
end

Get popular content URLs by domain

Examples:

Get most requested URLs

urls = cdn.analytics.popular_content_url_by_domain({
  customerId: "12345",
  serviceName: "cdn.example.com",
  startTime: "2025-01-01T00:00:00Z",
  endTime: "2025-01-07T00:00:00Z",
  pageNumber: 0,
  pageSize: 50
})
urls.each { |url| puts "#{url['url']}: #{url['requests']} requests" }

Parameters:

  • payload (Hash)

    analytics parameters

Options Hash (payload):

  • :customerId (String)

    customer ID

  • :serviceName (String)

    domain/service name

  • :startTime (String)

    start time in ISO 8601 format

  • :endTime (String)

    end time in ISO 8601 format

  • :pageNumber (Integer)

    page number (0-based)

  • :pageSize (Integer)

    number of results per page

Returns:

  • (Array)

    array of popular URL data, or empty array on error

Since:

  • 1.0.1



265
266
267
268
269
270
271
# File 'lib/conversant/v3/services/cdn/analytics.rb', line 265

def popular_content_url_by_domain(payload)
  response = JSON.parse(@parent.send(:call, 'POST', '/api/report/getUrlByDomain', payload))
  response&.[]('list') || []
rescue StandardError => e
  @parent.send(:logger).error "#{@parent.send(:identifier)}.METHOD:#{__method__}.EXCEPTION:#{e.message}"
  []
end

Get popular content URL CSV export by domain

Parameters:

  • payload (Hash)

    analytics parameters with csvRequest: 1

Returns:

  • (String, nil)

    CSV data, or nil on error

Since:

  • 1.0.8



420
421
422
423
424
425
426
# File 'lib/conversant/v3/services/cdn/analytics.rb', line 420

def popular_content_url_csv_by_domain(payload)
  response = @parent.send(:call, 'POST', '/api/report/getUrlCsvByDomain', payload)
  response
rescue StandardError => e
  @parent.send(:logger).error "#{@parent.send(:identifier)}.METHOD:#{__method__}.EXCEPTION:#{e.message}"
  nil
end

Get total popular content URL count by domain

Parameters:

  • payload (Hash)

    analytics parameters

Returns:

  • (Hash, nil)

    total URL data, or nil on error

Since:

  • 1.0.8



407
408
409
410
411
412
413
# File 'lib/conversant/v3/services/cdn/analytics.rb', line 407

def popular_content_url_total_by_domain(payload)
  response = JSON.parse(@parent.send(:call, 'POST', '/api/report/getUrlTotalByDomain', payload))
  response
rescue StandardError => e
  @parent.send(:logger).error "#{@parent.send(:identifier)}.METHOD:#{__method__}.EXCEPTION:#{e.message}"
  nil
end

#referrer_by_domain(payload) ⇒ Array

Get referrer analytics by domain

Examples:

Get top referrers

referrers = cdn.analytics.referrer_by_domain({
  customerId: "12345",
  serviceName: "example.com",
  startTime: "2025-01-01T00:00:00Z",
  endTime: "2025-01-07T00:00:00Z",
  pageNumber: 0,
  pageSize: 20
})
referrers.each { |ref| puts "#{ref['referrer']}: #{ref['requests']} requests" }

Parameters:

  • payload (Hash)

    analytics parameters

Options Hash (payload):

  • :customerId (String)

    customer ID

  • :serviceName (String)

    domain/service name

  • :startTime (String)

    start time in ISO 8601 format

  • :endTime (String)

    end time in ISO 8601 format

  • :pageNumber (Integer)

    page number (0-based)

  • :pageSize (Integer)

    number of results per page

Returns:

  • (Array)

    array of referrer data, or empty array on error

Since:

  • 1.0.1



233
234
235
236
237
238
239
# File 'lib/conversant/v3/services/cdn/analytics.rb', line 233

def referrer_by_domain(payload)
  response = JSON.parse(@parent.send(:call, 'POST', '/api/report/getReferrerByDomain', payload))
  response&.[]('list') || []
rescue StandardError => e
  @parent.send(:logger).error "#{@parent.send(:identifier)}.METHOD:#{__method__}.EXCEPTION:#{e.message}"
  []
end

#referrer_csv_by_domain(payload) ⇒ String?

Get referrer CSV export by domain

Parameters:

  • payload (Hash)

    analytics parameters with csvRequest: 1

Returns:

  • (String, nil)

    CSV data, or nil on error

Since:

  • 1.0.8



394
395
396
397
398
399
400
# File 'lib/conversant/v3/services/cdn/analytics.rb', line 394

def referrer_csv_by_domain(payload)
  response = @parent.send(:call, 'POST', '/api/report/getReferrerCsvByDomain', payload)
  response
rescue StandardError => e
  @parent.send(:logger).error "#{@parent.send(:identifier)}.METHOD:#{__method__}.EXCEPTION:#{e.message}"
  nil
end

#referrer_total_by_domain(payload) ⇒ Hash?

Get total referrer count by domain

Parameters:

  • payload (Hash)

    analytics parameters

Returns:

  • (Hash, nil)

    total referrer data, or nil on error

Since:

  • 1.0.8



381
382
383
384
385
386
387
# File 'lib/conversant/v3/services/cdn/analytics.rb', line 381

def referrer_total_by_domain(payload)
  response = JSON.parse(@parent.send(:call, 'POST', '/api/report/getReferrerTotalByDomain', payload))
  response
rescue StandardError => e
  @parent.send(:logger).error "#{@parent.send(:identifier)}.METHOD:#{__method__}.EXCEPTION:#{e.message}"
  nil
end

#request_hit_rate(params) ⇒ Hash?

Get request hit rate analytics

Parameters:

  • params (Hash)

    analytics parameters (passed as query string)

Options Hash (params):

  • :domain (String)

    domain name or "All"

  • :startTime (String)

    start time in ISO 8601 format

  • :endTime (String)

    end time in ISO 8601 format

  • :interval (String)

    time interval

  • :fillFixedTime (Boolean)

    fill missing time slots

Returns:

  • (Hash, nil)

    hit rate data, or nil on error

Since:

  • 1.0.8



313
314
315
316
317
318
319
320
# File 'lib/conversant/v3/services/cdn/analytics.rb', line 313

def request_hit_rate(params)
  query_string = URI.encode_www_form(params)
  response = JSON.parse(@parent.send(:call, 'GET', "/api/hit_rate_chart_data?#{query_string}", nil))
  response
rescue StandardError => e
  @parent.send(:logger).error "#{@parent.send(:identifier)}.METHOD:#{__method__}.EXCEPTION:#{e.message}"
  nil
end

#request_per_second(payload) ⇒ Hash?

Get requests per second (RPS) analytics

Examples:

Get RPS data

rps = cdn.analytics.request_per_second({
  domain: "api.example.com",
  startTime: "2025-01-01T12:00:00Z",
  endTime: "2025-01-01T13:00:00Z"
})
puts "Max RPS: #{rps[:maxQuantity]}"
puts "Avg RPS: #{rps[:avgQuantity]}"
puts "HTTP Total: #{rps[:httpTotalQuantity]}"
puts "HTTPS Total: #{rps[:httpsTotalQuantity]}"

Parameters:

  • payload (Hash)

    analytics parameters (passed as query string)

Options Hash (payload):

  • :domain (String)

    domain name or "All" for all domains

  • :startTime (String)

    start time in ISO 8601 format

  • :endTime (String)

    end time in ISO 8601 format

  • :interval (String)

    time interval

Returns:

  • (Hash, nil)

    RPS data with statistics and time series, or nil on error

Since:

  • 1.0.0



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/conversant/v3/services/cdn/analytics.rb', line 165

def request_per_second(payload)
  response = JSON.parse(@parent.send(:call, 'GET', "/api/rps_chart_data?#{payload.to_query}"))
  if response&.[]('datas')
    {
      maxQuantity: response['maxQuantity'],
      avgQuantity: response['avgQuantity'],
      httpTotalQuantity: response['httpTotalQuantity'],
      httpsTotalQuantity: response['httpsTotalQuantity'],
      data: response['datas'],
    }
  end
rescue StandardError => e
  @parent.send(:logger).error "#{@parent.send(:identifier)}.METHOD:#{__method__}.EXCEPTION:#{e.message}"
  nil
end

#request_visit_number(payload) ⇒ Hash?

Get request and visit number statistics

Parameters:

  • payload (Hash)

    analytics parameters

Returns:

  • (Hash, nil)

    request/visit statistics, or nil on error

Since:

  • 1.0.8



433
434
435
436
437
438
439
# File 'lib/conversant/v3/services/cdn/analytics.rb', line 433

def request_visit_number(payload)
  response = JSON.parse(@parent.send(:call, 'POST', '/api/report/request_visit_number', payload))
  response
rescue StandardError => e
  @parent.send(:logger).error "#{@parent.send(:identifier)}.METHOD:#{__method__}.EXCEPTION:#{e.message}"
  nil
end

#user_agent(payload) ⇒ Array

Get user agent analytics by domain

Parameters:

  • payload (Hash)

    analytics parameters

Returns:

  • (Array)

    user agent data, or empty array on error

Since:

  • 1.0.8



459
460
461
462
463
464
465
# File 'lib/conversant/v3/services/cdn/analytics.rb', line 459

def user_agent(payload)
  response = JSON.parse(@parent.send(:call, 'POST', '/api/report/domain/userAgent', payload))
  response&.[]('list') || []
rescue StandardError => e
  @parent.send(:logger).error "#{@parent.send(:identifier)}.METHOD:#{__method__}.EXCEPTION:#{e.message}"
  []
end

#user_agent_csv(payload) ⇒ String?

Get user agent CSV export by domain

Parameters:

  • payload (Hash)

    analytics parameters

Returns:

  • (String, nil)

    CSV data, or nil on error

Since:

  • 1.0.8



472
473
474
475
476
477
478
# File 'lib/conversant/v3/services/cdn/analytics.rb', line 472

def user_agent_csv(payload)
  response = @parent.send(:call, 'POST', '/api/report/domain/userAgentCsv', payload)
  response
rescue StandardError => e
  @parent.send(:logger).error "#{@parent.send(:identifier)}.METHOD:#{__method__}.EXCEPTION:#{e.message}"
  nil
end

#viewers(payload) ⇒ Array?

Get viewer analytics data

Examples:

Get viewer statistics

viewers = cdn.analytics.viewers({
  domain: "streaming.example.com",
  startTime: "2025-01-01T00:00:00Z",
  endTime: "2025-01-01T23:59:59Z",
  interval: "minute"
})
viewers.each { |point| puts "#{point['time']}: #{point['viewers']} viewers" }

Parameters:

  • payload (Hash)

    analytics parameters

Options Hash (payload):

  • :domain (String)

    domain name or "All" for all domains

  • :startTime (String)

    start time in ISO 8601 format

  • :endTime (String)

    end time in ISO 8601 format

  • :interval (String)

    time interval ("minute", "hour", "day")

Returns:

  • (Array, nil)

    array of viewer data points, or nil on error

Since:

  • 1.0.0



136
137
138
139
140
141
# File 'lib/conversant/v3/services/cdn/analytics.rb', line 136

def viewers(payload)
  JSON.parse(@parent.send(:call, 'POST', '/api/report/viewers', payload))
rescue StandardError => e
  @parent.send(:logger).error "#{@parent.send(:identifier)}.METHOD:#{__method__}.EXCEPTION:#{e.message}"
  nil
end

#volumes(payload) ⇒ Hash?

Get volume analytics data

Examples:

Get daily volume data

volume = cdn.analytics.volumes({
  domain: "example.com",
  startTime: "2025-01-01T00:00:00Z",
  endTime: "2025-01-31T00:00:00Z",
  interval: "day"
})
puts "Domain: #{volume[:domain]}"
volume[:data].each { |point| puts "#{point['time']}: #{point['bytes']} bytes" }

Parameters:

  • payload (Hash)

    analytics parameters

Options Hash (payload):

  • :domain (String)

    domain name or "All" for all domains

  • :startTime (String)

    start time in ISO 8601 format

  • :endTime (String)

    end time in ISO 8601 format

  • :interval (String)

    time interval ("minute", "hour", "day")

  • :fillFixedTime (Boolean)

    whether to fill missing time slots

Returns:

  • (Hash, nil)

    volume data with domain and volumes array, or nil on error

Since:

  • 1.0.0



108
109
110
111
112
113
114
# File 'lib/conversant/v3/services/cdn/analytics.rb', line 108

def volumes(payload)
  response = JSON.parse(@parent.send(:call, 'POST', '/api/report/volume', payload))
  { data: response&.[]('volumes') } if response&.[]('volumes')
rescue StandardError => e
  @parent.send(:logger).error "#{@parent.send(:identifier)}.METHOD:#{__method__}.EXCEPTION:#{e.message}"
  nil
end