Class: Zernio::AdDailyMetrics

Inherits:
ApiModelBase show all
Defined in:
lib/zernio-sdk/models/ad_daily_metrics.rb

Overview

One day of metrics. Same fields as AdMetrics plus the date they apply to. Returned inside a node's daily[] when GET /v1/ads/tree is called with timeIncrement=1. Rate metrics (ctr/cpc/cpm/costPerConversion/ roas/videoAvgTimeWatchedActions) are recomputed per day from that day's sums, so summing the additive fields across a node's daily[] reproduces its aggregated metrics total. Do NOT sum or plain-average videoAvgTimeWatchedActions across days: the range value is the play-weighted average of the daily values.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApiModelBase

_deserialize, #_to_hash, #to_body, #to_s

Constructor Details

#initialize(attributes = {}) ⇒ AdDailyMetrics

Initializes the object

Parameters:

  • attributes (Hash) (defaults to: {})

    Model attributes in the form of hash



176
177
178
179
180
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
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
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 176

def initialize(attributes = {})
  if (!attributes.is_a?(Hash))
    fail ArgumentError, "The input argument (attributes) must be a hash in `Zernio::AdDailyMetrics` initialize method"
  end

  # check to see if the attribute exists and convert string to symbol for hash key
  acceptable_attribute_map = self.class.acceptable_attribute_map
  attributes = attributes.each_with_object({}) { |(k, v), h|
    if (!acceptable_attribute_map.key?(k.to_sym))
      fail ArgumentError, "`#{k}` is not a valid attribute in `Zernio::AdDailyMetrics`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect
    end
    h[k.to_sym] = v
  }

  if attributes.key?(:'spend')
    self.spend = attributes[:'spend']
  end

  if attributes.key?(:'impressions')
    self.impressions = attributes[:'impressions']
  end

  if attributes.key?(:'reach')
    self.reach = attributes[:'reach']
  end

  if attributes.key?(:'clicks')
    self.clicks = attributes[:'clicks']
  end

  if attributes.key?(:'ctr')
    self.ctr = attributes[:'ctr']
  end

  if attributes.key?(:'cpc')
    self.cpc = attributes[:'cpc']
  end

  if attributes.key?(:'cpm')
    self.cpm = attributes[:'cpm']
  end

  if attributes.key?(:'engagement')
    self.engagement = attributes[:'engagement']
  end

  if attributes.key?(:'conversions')
    self.conversions = attributes[:'conversions']
  end

  if attributes.key?(:'cost_per_conversion')
    self.cost_per_conversion = attributes[:'cost_per_conversion']
  end

  if attributes.key?(:'actions')
    if (value = attributes[:'actions']).is_a?(Hash)
      self.actions = value
    end
  end

  if attributes.key?(:'action_values')
    if (value = attributes[:'action_values']).is_a?(Hash)
      self.action_values = value
    end
  end

  if attributes.key?(:'purchase_value')
    self.purchase_value = attributes[:'purchase_value']
  end

  if attributes.key?(:'roas')
    self.roas = attributes[:'roas']
  end

  if attributes.key?(:'video_play_actions')
    self.video_play_actions = attributes[:'video_play_actions']
  end

  if attributes.key?(:'video30_sec_watched_actions')
    self.video30_sec_watched_actions = attributes[:'video30_sec_watched_actions']
  end

  if attributes.key?(:'video_thruplay_watched_actions')
    self.video_thruplay_watched_actions = attributes[:'video_thruplay_watched_actions']
  end

  if attributes.key?(:'video_p25_watched_actions')
    self.video_p25_watched_actions = attributes[:'video_p25_watched_actions']
  end

  if attributes.key?(:'video_p50_watched_actions')
    self.video_p50_watched_actions = attributes[:'video_p50_watched_actions']
  end

  if attributes.key?(:'video_p75_watched_actions')
    self.video_p75_watched_actions = attributes[:'video_p75_watched_actions']
  end

  if attributes.key?(:'video_p95_watched_actions')
    self.video_p95_watched_actions = attributes[:'video_p95_watched_actions']
  end

  if attributes.key?(:'video_p100_watched_actions')
    self.video_p100_watched_actions = attributes[:'video_p100_watched_actions']
  end

  if attributes.key?(:'video_avg_time_watched_actions')
    self.video_avg_time_watched_actions = attributes[:'video_avg_time_watched_actions']
  end

  if attributes.key?(:'last_synced_at')
    self.last_synced_at = attributes[:'last_synced_at']
  end

  if attributes.key?(:'date')
    self.date = attributes[:'date']
  end
end

Instance Attribute Details

#action_valuesObject

Monetary mirror of actions, from Meta's Insights action_values[] array. Same keying — values are the revenue attributed to each action_type, in ad-account native currency (same unit as spend; see the campaign node's currency field). Use this to compute revenue-per-event (e.g. avg purchase value). Meta-only; other platforms return {}.



48
49
50
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 48

def action_values
  @action_values
end

#actionsObject

Per-action-type counts summed over the date range, keyed by the platform's action-type names. Meta: raw Insights action_type keys (link_click, offsite_conversion.fb_pixel_purchase, onsite_conversion.lead_grouped, ...) — both engagement and conversion events. X: conversion types (purchase, sign_up, site_visit, download, custom). LinkedIn: conversion types (post_click, post_view, lead_gen). Google returns {} (its per-action names aren't synced per ad). Empty object when no actions are reported. NOTE: keys differ by platform, so branch on the ad's platform when interpreting them.



45
46
47
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 45

def actions
  @actions
end

#clicksObject

Returns the value of attribute clicks.



25
26
27
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 25

def clicks
  @clicks
end

#conversionsObject

Count of conversion events over the requested date range. Meta: events matching the campaign's promoted_object.custom_event_type (PURCHASE, LEAD, etc.). Google: the account's tracked conversions. X and LinkedIn: their reported website/lead conversions (added 2026-07). 0 for non-conversion campaigns or when no events have fired.



39
40
41
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 39

def conversions
  @conversions
end

#cost_per_conversionObject

Derived spend / conversions in the same currency as spend. 0 when conversions is 0.



42
43
44
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 42

def cost_per_conversion
  @cost_per_conversion
end

#cpcObject

Cost per click



31
32
33
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 31

def cpc
  @cpc
end

#cpmObject

Cost per 1000 impressions



34
35
36
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 34

def cpm
  @cpm
end

#ctrObject

Click-through rate (%)



28
29
30
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 28

def ctr
  @ctr
end

#dateObject

Calendar day (YYYY-MM-DD) these metrics apply to.



87
88
89
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 87

def date
  @date
end

#engagementObject

Returns the value of attribute engagement.



36
37
38
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 36

def engagement
  @engagement
end

#impressionsObject

Returns the value of attribute impressions.



21
22
23
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 21

def impressions
  @impressions
end

#last_synced_atObject

Present on individual ads only, not on campaign aggregations



84
85
86
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 84

def last_synced_at
  @last_synced_at
end

#purchase_valueObject

Convenience sum of purchase-type action values — picked from actionValues via the same priority list as conversions so both fields describe the same events. In ad-account native currency. 0 when the campaign has no purchase event configured. Meta-only.



51
52
53
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 51

def purchase_value
  @purchase_value
end

#reachObject

Returns the value of attribute reach.



23
24
25
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 23

def reach
  @reach
end

#roasObject

Return on ad spend — derived as purchaseValue / spend. 0 when spend is 0. Equivalent to Meta's purchase_roas under default attribution. At ad-set and campaign levels this is recomputed from summed purchaseValue + spend (NOT averaged across children) so it's mathematically correct at every rollup level.



54
55
56
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 54

def roas
  @roas
end

#spendObject

Returns the value of attribute spend.



19
20
21
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 19

def spend
  @spend
end

#video30_sec_watched_actionsObject

Views of at least 30 seconds (or to the end, for shorter videos). Meta video_30_sec_watched_actions.



60
61
62
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 60

def video30_sec_watched_actions
  @video30_sec_watched_actions
end

#video_avg_time_watched_actionsObject

Average seconds watched per play (Meta video_avg_time_watched_actions). Aggregated over date ranges and across children as a play-weighted average (total watch time / total plays), never a plain average of averages.



81
82
83
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 81

def video_avg_time_watched_actions
  @video_avg_time_watched_actions
end

#video_p100_watched_actionsObject

Views reaching 100% of the video's length. Meta video_p100_watched_actions.



78
79
80
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 78

def video_p100_watched_actions
  @video_p100_watched_actions
end

#video_p25_watched_actionsObject

Views reaching 25% of the video's length. With the other percentile fields, powers hook/hold/drop-off analysis (e.g. hook rate = videoP25WatchedActions / videoPlayActions). Meta video_p25_watched_actions.



66
67
68
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 66

def video_p25_watched_actions
  @video_p25_watched_actions
end

#video_p50_watched_actionsObject

Views reaching 50% of the video's length. Meta video_p50_watched_actions.



69
70
71
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 69

def video_p50_watched_actions
  @video_p50_watched_actions
end

#video_p75_watched_actionsObject

Views reaching 75% of the video's length. Meta video_p75_watched_actions.



72
73
74
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 72

def video_p75_watched_actions
  @video_p75_watched_actions
end

#video_p95_watched_actionsObject

Views reaching 95% of the video's length. Meta video_p95_watched_actions.



75
76
77
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 75

def video_p95_watched_actions
  @video_p95_watched_actions
end

#video_play_actionsObject

Meta video ads only (0 for non-video ads and other platforms), like all video* fields below. Number of times the video started playing (Meta video_play_actions), summed over the date range and across children at ad-set/campaign level.



57
58
59
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 57

def video_play_actions
  @video_play_actions
end

#video_thruplay_watched_actionsObject

ThruPlays (watched to completion, or at least 15 seconds). Meta video_thruplay_watched_actions.



63
64
65
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 63

def video_thruplay_watched_actions
  @video_thruplay_watched_actions
end

Class Method Details

.acceptable_attribute_mapObject

Returns attribute mapping this model knows about



121
122
123
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 121

def self.acceptable_attribute_map
  attribute_map
end

.acceptable_attributesObject

Returns all the JSON keys this model knows about



126
127
128
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 126

def self.acceptable_attributes
  acceptable_attribute_map.values
end

.attribute_mapObject

Attribute mapping from ruby-style variable name to JSON key.



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 90

def self.attribute_map
  {
    :'spend' => :'spend',
    :'impressions' => :'impressions',
    :'reach' => :'reach',
    :'clicks' => :'clicks',
    :'ctr' => :'ctr',
    :'cpc' => :'cpc',
    :'cpm' => :'cpm',
    :'engagement' => :'engagement',
    :'conversions' => :'conversions',
    :'cost_per_conversion' => :'costPerConversion',
    :'actions' => :'actions',
    :'action_values' => :'actionValues',
    :'purchase_value' => :'purchaseValue',
    :'roas' => :'roas',
    :'video_play_actions' => :'videoPlayActions',
    :'video30_sec_watched_actions' => :'video30SecWatchedActions',
    :'video_thruplay_watched_actions' => :'videoThruplayWatchedActions',
    :'video_p25_watched_actions' => :'videoP25WatchedActions',
    :'video_p50_watched_actions' => :'videoP50WatchedActions',
    :'video_p75_watched_actions' => :'videoP75WatchedActions',
    :'video_p95_watched_actions' => :'videoP95WatchedActions',
    :'video_p100_watched_actions' => :'videoP100WatchedActions',
    :'video_avg_time_watched_actions' => :'videoAvgTimeWatchedActions',
    :'last_synced_at' => :'lastSyncedAt',
    :'date' => :'date'
  }
end

.build_from_hash(attributes) ⇒ Object

Builds the object from hash

Parameters:

  • attributes (Hash)

    Model attributes in the form of hash

Returns:

  • (Object)

    Returns the model itself



357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 357

def self.build_from_hash(attributes)
  return nil unless attributes.is_a?(Hash)
  attributes = attributes.transform_keys(&:to_sym)
  transformed_hash = {}
  openapi_types.each_pair do |key, type|
    if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
      transformed_hash["#{key}"] = nil
    elsif type =~ /\AArray<(.*)>/i
      # check to ensure the input is an array given that the attribute
      # is documented as an array but the input is not
      if attributes[attribute_map[key]].is_a?(Array)
        transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
      end
    elsif !attributes[attribute_map[key]].nil?
      transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
    end
  end
  new(transformed_hash)
end

.openapi_all_ofObject

List of class defined in allOf (OpenAPI v3)



168
169
170
171
172
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 168

def self.openapi_all_of
  [
  :'AdMetrics'
  ]
end

.openapi_nullableObject

List of attributes with nullable: true



162
163
164
165
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 162

def self.openapi_nullable
  Set.new([
  ])
end

.openapi_typesObject

Attribute type mapping.



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
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 131

def self.openapi_types
  {
    :'spend' => :'Float',
    :'impressions' => :'Integer',
    :'reach' => :'Integer',
    :'clicks' => :'Integer',
    :'ctr' => :'Float',
    :'cpc' => :'Float',
    :'cpm' => :'Float',
    :'engagement' => :'Integer',
    :'conversions' => :'Integer',
    :'cost_per_conversion' => :'Float',
    :'actions' => :'Hash<String, Integer>',
    :'action_values' => :'Hash<String, Float>',
    :'purchase_value' => :'Float',
    :'roas' => :'Float',
    :'video_play_actions' => :'Integer',
    :'video30_sec_watched_actions' => :'Integer',
    :'video_thruplay_watched_actions' => :'Integer',
    :'video_p25_watched_actions' => :'Integer',
    :'video_p50_watched_actions' => :'Integer',
    :'video_p75_watched_actions' => :'Integer',
    :'video_p95_watched_actions' => :'Integer',
    :'video_p100_watched_actions' => :'Integer',
    :'video_avg_time_watched_actions' => :'Float',
    :'last_synced_at' => :'Time',
    :'date' => :'Date'
  }
end

Instance Method Details

#==(o) ⇒ Object

Checks equality by comparing each attribute.

Parameters:

  • Object (Object)

    to be compared



312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 312

def ==(o)
  return true if self.equal?(o)
  self.class == o.class &&
      spend == o.spend &&
      impressions == o.impressions &&
      reach == o.reach &&
      clicks == o.clicks &&
      ctr == o.ctr &&
      cpc == o.cpc &&
      cpm == o.cpm &&
      engagement == o.engagement &&
      conversions == o.conversions &&
      cost_per_conversion == o.cost_per_conversion &&
      actions == o.actions &&
      action_values == o.action_values &&
      purchase_value == o.purchase_value &&
      roas == o.roas &&
      video_play_actions == o.video_play_actions &&
      video30_sec_watched_actions == o.video30_sec_watched_actions &&
      video_thruplay_watched_actions == o.video_thruplay_watched_actions &&
      video_p25_watched_actions == o.video_p25_watched_actions &&
      video_p50_watched_actions == o.video_p50_watched_actions &&
      video_p75_watched_actions == o.video_p75_watched_actions &&
      video_p95_watched_actions == o.video_p95_watched_actions &&
      video_p100_watched_actions == o.video_p100_watched_actions &&
      video_avg_time_watched_actions == o.video_avg_time_watched_actions &&
      last_synced_at == o.last_synced_at &&
      date == o.date
end

#eql?(o) ⇒ Boolean

Parameters:

  • Object (Object)

    to be compared

Returns:

  • (Boolean)

See Also:

  • `==` method


344
345
346
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 344

def eql?(o)
  self == o
end

#hashInteger

Calculates hash code according to all attributes.

Returns:

  • (Integer)

    Hash code



350
351
352
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 350

def hash
  [spend, impressions, reach, clicks, ctr, cpc, cpm, engagement, conversions, cost_per_conversion, actions, action_values, purchase_value, roas, video_play_actions, video30_sec_watched_actions, video_thruplay_watched_actions, video_p25_watched_actions, video_p50_watched_actions, video_p75_watched_actions, video_p95_watched_actions, video_p100_watched_actions, video_avg_time_watched_actions, last_synced_at, date].hash
end

#list_invalid_propertiesObject

Show invalid properties with the reasons. Usually used together with valid?

Returns:

  • Array for valid properties with the reasons



297
298
299
300
301
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 297

def list_invalid_properties
  warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
  invalid_properties = Array.new
  invalid_properties
end

#to_hashHash

Returns the object in the form of hash

Returns:

  • (Hash)

    Returns the object in the form of hash



379
380
381
382
383
384
385
386
387
388
389
390
391
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 379

def to_hash
  hash = {}
  self.class.attribute_map.each_pair do |attr, param|
    value = self.send(attr)
    if value.nil?
      is_nullable = self.class.openapi_nullable.include?(attr)
      next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
    end

    hash[param] = _to_hash(value)
  end
  hash
end

#valid?Boolean

Check to see if the all the properties in the model are valid

Returns:

  • (Boolean)

    true if the model is valid



305
306
307
308
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 305

def valid?
  warn '[DEPRECATED] the `valid?` method is obsolete'
  true
end