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. reach is the exception: on Meta and TikTok the aggregated total is de-duplicated across the range, so daily reach does not sum to it. 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



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
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/models/ad_daily_metrics.rb', line 190

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?(:'cost_per_thruplay')
    self.cost_per_thruplay = attributes[:'cost_per_thruplay']
  end

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

  if attributes.key?(:'engagement_breakdown')
    self.engagement_breakdown = attributes[:'engagement_breakdown']
  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 {}.



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

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.



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

def actions
  @actions
end

#clicksObject

Returns the value of attribute clicks.



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

def clicks
  @clicks
end

#conversionsObject

Count of conversion events over the requested date range. FRACTIONAL: attribution splits one conversion across touchpoints and Google additionally reports modeled conversions, so values like 0.347 are normal. 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.



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

def conversions
  @conversions
end

#cost_per_conversionObject

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



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

def cost_per_conversion
  @cost_per_conversion
end

#cost_per_thruplayObject

Derived spend / videoThruplayWatchedActions, in ad-account native currency. Rounded to 4 decimals rather than the usual 2 because a ThruPlay routinely costs well under a cent. 0 when the ad has no ThruPlays.



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

def cost_per_thruplay
  @cost_per_thruplay
end

#cpcObject

Cost per click



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

def cpc
  @cpc
end

#cpmObject

Cost per 1000 impressions



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

def cpm
  @cpm
end

#ctrObject

Click-through rate (%)



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

def ctr
  @ctr
end

#dateObject

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



95
96
97
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 95

def date
  @date
end

#engagementObject

Returns the value of attribute engagement.



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

def engagement
  @engagement
end

#engagement_breakdownObject

Returns the value of attribute engagement_breakdown.



89
90
91
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 89

def engagement_breakdown
  @engagement_breakdown
end

#funnelObject

Returns the value of attribute funnel.



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

def funnel
  @funnel
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



92
93
94
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 92

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.



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

def purchase_value
  @purchase_value
end

#reachObject

Unique people reached in the requested date range. Meta (facebook/instagram) and TikTok: the platform's own de-duplicated reach for the exact range, fetched live and cached up to ~1 hour (may lag recent delivery; on a transient platform error the value temporarily falls back to a sum of per-day reach, which overcounts people reached on multiple days or by multiple child ads). Because it is de-duplicated, reach is NOT additive on these platforms: neither daily values nor child nodes sum to the range total. Google, LinkedIn, X, Pinterest and OpenAI report 0 (reach not synced). Frequency (impressions / reach) is only meaningful for Meta and TikTok.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

def video_thruplay_watched_actions
  @video_thruplay_watched_actions
end

Class Method Details

.acceptable_attribute_mapObject

Returns attribute mapping this model knows about



132
133
134
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 132

def self.acceptable_attribute_map
  attribute_map
end

.acceptable_attributesObject

Returns all the JSON keys this model knows about



137
138
139
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 137

def self.acceptable_attributes
  acceptable_attribute_map.values
end

.attribute_mapObject

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



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 98

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',
    :'cost_per_thruplay' => :'costPerThruplay',
    :'funnel' => :'funnel',
    :'engagement_breakdown' => :'engagementBreakdown',
    :'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



386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 386

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)



182
183
184
185
186
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 182

def self.openapi_all_of
  [
  :'AdMetrics'
  ]
end

.openapi_nullableObject

List of attributes with nullable: true



176
177
178
179
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 176

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

.openapi_typesObject

Attribute type mapping.



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 142

def self.openapi_types
  {
    :'spend' => :'Float',
    :'impressions' => :'Integer',
    :'reach' => :'Integer',
    :'clicks' => :'Integer',
    :'ctr' => :'Float',
    :'cpc' => :'Float',
    :'cpm' => :'Float',
    :'engagement' => :'Integer',
    :'conversions' => :'Float',
    :'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',
    :'cost_per_thruplay' => :'Float',
    :'funnel' => :'AdFunnelCounts',
    :'engagement_breakdown' => :'AdEngagementCounts',
    :'last_synced_at' => :'Time',
    :'date' => :'Date'
  }
end

Instance Method Details

#==(o) ⇒ Object

Checks equality by comparing each attribute.

Parameters:

  • Object (Object)

    to be compared



338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 338

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 &&
      cost_per_thruplay == o.cost_per_thruplay &&
      funnel == o.funnel &&
      engagement_breakdown == o.engagement_breakdown &&
      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


373
374
375
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 373

def eql?(o)
  self == o
end

#hashInteger

Calculates hash code according to all attributes.

Returns:

  • (Integer)

    Hash code



379
380
381
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 379

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, cost_per_thruplay, funnel, engagement_breakdown, 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



323
324
325
326
327
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 323

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



408
409
410
411
412
413
414
415
416
417
418
419
420
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 408

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



331
332
333
334
# File 'lib/zernio-sdk/models/ad_daily_metrics.rb', line 331

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