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 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



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

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 {}.



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

#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.



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

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

#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



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

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): Meta's own de-duplicated reach for the exact range, fetched live and cached up to ~1 hour (may lag recent delivery; on a transient Meta 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, Meta reach is NOT additive: neither daily values nor child nodes sum to the range total. TikTok: sum of per-day reach, so multi-day ranges overcount vs TikTok Ads Manager. Google, LinkedIn, X, Pinterest and OpenAI report 0 (reach not synced). Only derive frequency (impressions / reach) for Meta.



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



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

def self.acceptable_attribute_map
  attribute_map
end

.acceptable_attributesObject

Returns all the JSON keys this model knows about



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

def self.acceptable_attributes
  acceptable_attribute_map.values
end

.attribute_mapObject

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



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

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



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

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)



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

def self.openapi_all_of
  [
  :'AdMetrics'
  ]
end

.openapi_nullableObject

List of attributes with nullable: true



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

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

.openapi_typesObject

Attribute type mapping.



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

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',
    :'last_synced_at' => :'Time',
    :'date' => :'Date'
  }
end

Instance Method Details

#==(o) ⇒ Object

Checks equality by comparing each attribute.

Parameters:

  • Object (Object)

    to be compared



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

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


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

def eql?(o)
  self == o
end

#hashInteger

Calculates hash code according to all attributes.

Returns:

  • (Integer)

    Hash code



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

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



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

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



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

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



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

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