Class: Zernio::AdMetrics
- Inherits:
-
ApiModelBase
- Object
- ApiModelBase
- Zernio::AdMetrics
- Defined in:
- lib/zernio-sdk/models/ad_metrics.rb
Instance Attribute Summary collapse
-
#action_values ⇒ Object
Monetary mirror of
actions, from Meta's Insightsaction_values[]array. -
#actions ⇒ Object
Per-action-type counts summed over the date range, keyed by the platform's action-type names.
-
#clicks ⇒ Object
Returns the value of attribute clicks.
-
#conversions ⇒ Object
Count of conversion events over the requested date range.
-
#cost_per_conversion ⇒ Object
Derived spend / conversions in the same currency as spend.
-
#cpc ⇒ Object
Cost per click.
-
#cpm ⇒ Object
Cost per 1000 impressions.
-
#ctr ⇒ Object
Click-through rate (%).
-
#engagement ⇒ Object
Returns the value of attribute engagement.
-
#impressions ⇒ Object
Returns the value of attribute impressions.
-
#last_synced_at ⇒ Object
Present on individual ads only, not on campaign aggregations.
-
#purchase_value ⇒ Object
Convenience sum of purchase-type action values — picked from
actionValuesvia the same priority list asconversionsso both fields describe the same events. -
#reach ⇒ Object
Returns the value of attribute reach.
-
#roas ⇒ Object
Return on ad spend — derived as
purchaseValue / spend. -
#spend ⇒ Object
Returns the value of attribute spend.
-
#video30_sec_watched_actions ⇒ Object
Views of at least 30 seconds (or to the end, for shorter videos).
-
#video_avg_time_watched_actions ⇒ Object
Average seconds watched per play (Meta
video_avg_time_watched_actions). -
#video_p100_watched_actions ⇒ Object
Views reaching 100% of the video's length.
-
#video_p25_watched_actions ⇒ Object
Views reaching 25% of the video's length.
-
#video_p50_watched_actions ⇒ Object
Views reaching 50% of the video's length.
-
#video_p75_watched_actions ⇒ Object
Views reaching 75% of the video's length.
-
#video_p95_watched_actions ⇒ Object
Views reaching 95% of the video's length.
-
#video_play_actions ⇒ Object
Meta video ads only (0 for non-video ads and other platforms), like all video* fields below.
-
#video_thruplay_watched_actions ⇒ Object
ThruPlays (watched to completion, or at least 15 seconds).
Class Method Summary collapse
-
.acceptable_attribute_map ⇒ Object
Returns attribute mapping this model knows about.
-
.acceptable_attributes ⇒ Object
Returns all the JSON keys this model knows about.
-
.attribute_map ⇒ Object
Attribute mapping from ruby-style variable name to JSON key.
-
.build_from_hash(attributes) ⇒ Object
Builds the object from hash.
-
.openapi_nullable ⇒ Object
List of attributes with nullable: true.
-
.openapi_types ⇒ Object
Attribute type mapping.
Instance Method Summary collapse
-
#==(o) ⇒ Object
Checks equality by comparing each attribute.
- #eql?(o) ⇒ Boolean
-
#hash ⇒ Integer
Calculates hash code according to all attributes.
-
#initialize(attributes = {}) ⇒ AdMetrics
constructor
Initializes the object.
-
#list_invalid_properties ⇒ Object
Show invalid properties with the reasons.
-
#to_hash ⇒ Hash
Returns the object in the form of hash.
-
#valid? ⇒ Boolean
Check to see if the all the properties in the model are valid.
Methods inherited from ApiModelBase
_deserialize, #_to_hash, #to_body, #to_s
Constructor Details
#initialize(attributes = {}) ⇒ AdMetrics
Initializes the object
163 164 165 166 167 168 169 170 171 172 173 174 175 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 |
# File 'lib/zernio-sdk/models/ad_metrics.rb', line 163 def initialize(attributes = {}) if (!attributes.is_a?(Hash)) fail ArgumentError, "The input argument (attributes) must be a hash in `Zernio::AdMetrics` 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::AdMetrics`. 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 end |
Instance Attribute Details
#action_values ⇒ Object
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 {}.
47 48 49 |
# File 'lib/zernio-sdk/models/ad_metrics.rb', line 47 def action_values @action_values end |
#actions ⇒ Object
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.
44 45 46 |
# File 'lib/zernio-sdk/models/ad_metrics.rb', line 44 def actions @actions end |
#clicks ⇒ Object
Returns the value of attribute clicks.
24 25 26 |
# File 'lib/zernio-sdk/models/ad_metrics.rb', line 24 def clicks @clicks end |
#conversions ⇒ Object
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.
38 39 40 |
# File 'lib/zernio-sdk/models/ad_metrics.rb', line 38 def conversions @conversions end |
#cost_per_conversion ⇒ Object
Derived spend / conversions in the same currency as spend. 0 when conversions is 0.
41 42 43 |
# File 'lib/zernio-sdk/models/ad_metrics.rb', line 41 def cost_per_conversion @cost_per_conversion end |
#cpc ⇒ Object
Cost per click
30 31 32 |
# File 'lib/zernio-sdk/models/ad_metrics.rb', line 30 def cpc @cpc end |
#cpm ⇒ Object
Cost per 1000 impressions
33 34 35 |
# File 'lib/zernio-sdk/models/ad_metrics.rb', line 33 def cpm @cpm end |
#ctr ⇒ Object
Click-through rate (%)
27 28 29 |
# File 'lib/zernio-sdk/models/ad_metrics.rb', line 27 def ctr @ctr end |
#engagement ⇒ Object
Returns the value of attribute engagement.
35 36 37 |
# File 'lib/zernio-sdk/models/ad_metrics.rb', line 35 def engagement @engagement end |
#impressions ⇒ Object
Returns the value of attribute impressions.
20 21 22 |
# File 'lib/zernio-sdk/models/ad_metrics.rb', line 20 def impressions @impressions end |
#last_synced_at ⇒ Object
Present on individual ads only, not on campaign aggregations
83 84 85 |
# File 'lib/zernio-sdk/models/ad_metrics.rb', line 83 def last_synced_at @last_synced_at end |
#purchase_value ⇒ Object
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.
50 51 52 |
# File 'lib/zernio-sdk/models/ad_metrics.rb', line 50 def purchase_value @purchase_value end |
#reach ⇒ Object
Returns the value of attribute reach.
22 23 24 |
# File 'lib/zernio-sdk/models/ad_metrics.rb', line 22 def reach @reach end |
#roas ⇒ Object
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.
53 54 55 |
# File 'lib/zernio-sdk/models/ad_metrics.rb', line 53 def roas @roas end |
#spend ⇒ Object
Returns the value of attribute spend.
18 19 20 |
# File 'lib/zernio-sdk/models/ad_metrics.rb', line 18 def spend @spend end |
#video30_sec_watched_actions ⇒ Object
Views of at least 30 seconds (or to the end, for shorter videos). Meta video_30_sec_watched_actions.
59 60 61 |
# File 'lib/zernio-sdk/models/ad_metrics.rb', line 59 def video30_sec_watched_actions @video30_sec_watched_actions end |
#video_avg_time_watched_actions ⇒ Object
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.
80 81 82 |
# File 'lib/zernio-sdk/models/ad_metrics.rb', line 80 def video_avg_time_watched_actions @video_avg_time_watched_actions end |
#video_p100_watched_actions ⇒ Object
Views reaching 100% of the video's length. Meta video_p100_watched_actions.
77 78 79 |
# File 'lib/zernio-sdk/models/ad_metrics.rb', line 77 def video_p100_watched_actions @video_p100_watched_actions end |
#video_p25_watched_actions ⇒ Object
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.
65 66 67 |
# File 'lib/zernio-sdk/models/ad_metrics.rb', line 65 def video_p25_watched_actions @video_p25_watched_actions end |
#video_p50_watched_actions ⇒ Object
Views reaching 50% of the video's length. Meta video_p50_watched_actions.
68 69 70 |
# File 'lib/zernio-sdk/models/ad_metrics.rb', line 68 def video_p50_watched_actions @video_p50_watched_actions end |
#video_p75_watched_actions ⇒ Object
Views reaching 75% of the video's length. Meta video_p75_watched_actions.
71 72 73 |
# File 'lib/zernio-sdk/models/ad_metrics.rb', line 71 def video_p75_watched_actions @video_p75_watched_actions end |
#video_p95_watched_actions ⇒ Object
Views reaching 95% of the video's length. Meta video_p95_watched_actions.
74 75 76 |
# File 'lib/zernio-sdk/models/ad_metrics.rb', line 74 def video_p95_watched_actions @video_p95_watched_actions end |
#video_play_actions ⇒ Object
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.
56 57 58 |
# File 'lib/zernio-sdk/models/ad_metrics.rb', line 56 def video_play_actions @video_play_actions end |
#video_thruplay_watched_actions ⇒ Object
ThruPlays (watched to completion, or at least 15 seconds). Meta video_thruplay_watched_actions.
62 63 64 |
# File 'lib/zernio-sdk/models/ad_metrics.rb', line 62 def video_thruplay_watched_actions @video_thruplay_watched_actions end |
Class Method Details
.acceptable_attribute_map ⇒ Object
Returns attribute mapping this model knows about
116 117 118 |
# File 'lib/zernio-sdk/models/ad_metrics.rb', line 116 def self.acceptable_attribute_map attribute_map end |
.acceptable_attributes ⇒ Object
Returns all the JSON keys this model knows about
121 122 123 |
# File 'lib/zernio-sdk/models/ad_metrics.rb', line 121 def self.acceptable_attributes acceptable_attribute_map.values end |
.attribute_map ⇒ Object
Attribute mapping from ruby-style variable name to JSON key.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/zernio-sdk/models/ad_metrics.rb', line 86 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' } end |
.build_from_hash(attributes) ⇒ Object
Builds the object from hash
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 |
# File 'lib/zernio-sdk/models/ad_metrics.rb', line 339 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_nullable ⇒ Object
List of attributes with nullable: true
156 157 158 159 |
# File 'lib/zernio-sdk/models/ad_metrics.rb', line 156 def self.openapi_nullable Set.new([ ]) end |
.openapi_types ⇒ Object
Attribute type mapping.
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 |
# File 'lib/zernio-sdk/models/ad_metrics.rb', line 126 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' } end |
Instance Method Details
#==(o) ⇒ Object
Checks equality by comparing each attribute.
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 320 321 322 |
# File 'lib/zernio-sdk/models/ad_metrics.rb', line 295 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 end |
#eql?(o) ⇒ Boolean
326 327 328 |
# File 'lib/zernio-sdk/models/ad_metrics.rb', line 326 def eql?(o) self == o end |
#hash ⇒ Integer
Calculates hash code according to all attributes.
332 333 334 |
# File 'lib/zernio-sdk/models/ad_metrics.rb', line 332 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].hash end |
#list_invalid_properties ⇒ Object
Show invalid properties with the reasons. Usually used together with valid?
280 281 282 283 284 |
# File 'lib/zernio-sdk/models/ad_metrics.rb', line 280 def list_invalid_properties warn '[DEPRECATED] the `list_invalid_properties` method is obsolete' invalid_properties = Array.new invalid_properties end |
#to_hash ⇒ Hash
Returns the object in the form of hash
361 362 363 364 365 366 367 368 369 370 371 372 373 |
# File 'lib/zernio-sdk/models/ad_metrics.rb', line 361 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
288 289 290 291 |
# File 'lib/zernio-sdk/models/ad_metrics.rb', line 288 def valid? warn '[DEPRECATED] the `valid?` method is obsolete' true end |