Class: FacebookAds::ServerSide::CustomData

Inherits:
Object
  • Object
show all
Defined in:
lib/facebook_ads/ad_objects/server_side/custom_data.rb

Overview

CustomData includes additional business data about the event which is used for ads delivery optimization.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value: nil, currency: nil, content_name: nil, content_category: nil, content_ids: nil, contents: nil, content_type: nil, order_id: nil, predicted_ltv: nil, num_items: nil, status: nil, search_string: nil, delivery_category: nil, item_number: nil, custom_properties: {}) ⇒ CustomData

Returns a new instance of CustomData.

Parameters:

  • value (Float) (defaults to: nil)
  • currency (String) (defaults to: nil)
  • content_name (String) (defaults to: nil)
  • content_category (String) (defaults to: nil)
  • content_ids (Array<String>) (defaults to: nil)
  • contents (Array<Content>) (defaults to: nil)
  • content_type (String) (defaults to: nil)
  • order_id (String) (defaults to: nil)
  • predicted_ltv (Float) (defaults to: nil)
  • num_items (Integer) (defaults to: nil)
  • status (String) (defaults to: nil)
  • search_string (String) (defaults to: nil)
  • delivery_category (String) (defaults to: nil)
  • item_number (String) (defaults to: nil)
  • custom_properties (String) (defaults to: {})


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
130
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
160
161
# File 'lib/facebook_ads/ad_objects/server_side/custom_data.rb', line 100

def initialize(value: nil,
               currency: nil,
               content_name: nil,
               content_category: nil,
               content_ids: nil,
               contents: nil,
               content_type: nil,
               order_id: nil,
               predicted_ltv: nil,
               num_items: nil,
               status: nil,
               search_string: nil,
               delivery_category: nil,
               item_number: nil,
               custom_properties: {})

  unless value.nil?
    self.value = value
  end
  unless currency.nil?
    self.currency = currency
  end
  unless content_name.nil?
    self.content_name = content_name
  end
  unless .nil?
    self. = 
  end
  unless content_ids.nil?
    self.content_ids = content_ids
  end
  unless contents.nil?
    self.contents = contents
  end
  unless content_type.nil?
    self.content_type = content_type
  end
  unless order_id.nil?
    self.order_id = order_id
  end
  unless predicted_ltv.nil?
    self.predicted_ltv = predicted_ltv
  end
  unless num_items.nil?
    self.num_items = num_items
  end
  unless status.nil?
    self.status = status
  end
  unless search_string.nil?
    self.search_string = search_string
  end
  unless delivery_category.nil?
    self.delivery_category = delivery_category
  end
  unless item_number.nil?
    self.item_number = item_number
  end
  unless custom_properties.nil?
    self.custom_properties = custom_properties
  end
end

Instance Attribute Details

#content_categoryObject

The category of the content associated with the event. Example: ‘grocery’



38
39
40
# File 'lib/facebook_ads/ad_objects/server_side/custom_data.rb', line 38

def 
  @content_category
end

#content_idsObject

The content IDs associated with the event, such as product SKUs for items in an AddToCart event: [‘ABC123’, ‘XYZ789’]. If content_type is a product, then your content IDs must be an array with a single string value. Otherwise, this array can contain any number of string values.



43
44
45
# File 'lib/facebook_ads/ad_objects/server_side/custom_data.rb', line 43

def content_ids
  @content_ids
end

#content_nameObject

The name of the page or product associated with the event. Example: ‘lettuce’.



34
35
36
# File 'lib/facebook_ads/ad_objects/server_side/custom_data.rb', line 34

def content_name
  @content_name
end

#content_typeObject

A String equal to either ‘product’ or ‘product_group’. Set to product if the keys you send content_ids or contents represent products. Set to product_group if the keys you send in content_ids represent product groups.



51
52
53
# File 'lib/facebook_ads/ad_objects/server_side/custom_data.rb', line 51

def content_type
  @content_type
end

#contentsObject

An array of Content objects that contain the product IDs associated with the event plus information about the products. id, quantity, and item_price are available fields.



47
48
49
# File 'lib/facebook_ads/ad_objects/server_side/custom_data.rb', line 47

def contents
  @contents
end

#currencyObject

The currency for the value specified, if applicable. Currency must be a valid ISO 4217 three digit currency code. Example: ‘usd’.



30
31
32
# File 'lib/facebook_ads/ad_objects/server_side/custom_data.rb', line 30

def currency
  @currency
end

#custom_propertiesObject

Custom Properties bag for storing other custom fields



82
83
84
# File 'lib/facebook_ads/ad_objects/server_side/custom_data.rb', line 82

def custom_properties
  @custom_properties
end

#delivery_categoryObject

Type of delivery for a purchase event Example: ‘home_delivery’.



75
76
77
# File 'lib/facebook_ads/ad_objects/server_side/custom_data.rb', line 75

def delivery_category
  @delivery_category
end

#item_numberObject

The item number. Example: ‘item1234’.



79
80
81
# File 'lib/facebook_ads/ad_objects/server_side/custom_data.rb', line 79

def item_number
  @item_number
end

#num_itemsObject

Use only with InitiateCheckout events. The number of items that a user tries to buy during checkout. Example: 4



63
64
65
# File 'lib/facebook_ads/ad_objects/server_side/custom_data.rb', line 63

def num_items
  @num_items
end

#order_idObject

The order ID for this transaction as a String. Example: ‘order1234’.



55
56
57
# File 'lib/facebook_ads/ad_objects/server_side/custom_data.rb', line 55

def order_id
  @order_id
end

#predicted_ltvObject

The predicted lifetime value of a conversion event. Example: 432.12.



59
60
61
# File 'lib/facebook_ads/ad_objects/server_side/custom_data.rb', line 59

def predicted_ltv
  @predicted_ltv
end

#search_stringObject

Use only with Search events. A search query made by a user. Example: ‘lettuce’.



71
72
73
# File 'lib/facebook_ads/ad_objects/server_side/custom_data.rb', line 71

def search_string
  @search_string
end

#statusObject

Use only with CompleteRegistration events. The status of the registration event, as a String. Example: ‘registered’.



67
68
69
# File 'lib/facebook_ads/ad_objects/server_side/custom_data.rb', line 67

def status
  @status
end

#valueObject

A numeric value associated with this event. This could be a monetary value or a value in some other metric. Example: 142.54.



26
27
28
# File 'lib/facebook_ads/ad_objects/server_side/custom_data.rb', line 26

def value
  @value
end

Instance Method Details

#==(o) ⇒ Object

Checks equality by comparing each attribute.



238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
# File 'lib/facebook_ads/ad_objects/server_side/custom_data.rb', line 238

def ==(o)
  return true if self.equal?(o)
  self.class == o.class &&
      value == o.value &&
      currency == o.currency &&
      content_name == o.content_name &&
       == o. &&
      content_ids == o.content_ids &&
      contents == o.contents &&
      content_type == o.content_type &&
      order_id == o.order_id &&
      predicted_ltv == o.predicted_ltv &&
      num_items == o.num_items &&
      status == o.status &&
      search_string == o.search_string &&
      delivery_category == o.delivery_category &&
      item_number == o.item_number &&
      custom_properties == o.custom_properties
end

#add_custom_property(key, value) ⇒ Object

Add other custom fields to custom properties.



335
336
337
# File 'lib/facebook_ads/ad_objects/server_side/custom_data.rb', line 335

def add_custom_property(key, value)
  custom_properties[key] = value;
end

#build(attributes = {}) ⇒ Object

build the object using the input hash

Parameters:

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

    attributes in the form of hash



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
# File 'lib/facebook_ads/ad_objects/server_side/custom_data.rb', line 166

def build(attributes = {})
  return unless attributes.is_a?(Hash)

  # convert string to symbol for hash key
  attributes = attributes.each_with_object({}) { |(k, v), h| h[k.to_sym] = v }

  if attributes.has_key?(:'value')
    self.value = attributes[:'value']
  end

  if attributes.has_key?(:'currency')
    self.currency = attributes[:'currency']
  end

  if attributes.has_key?(:'content_name')
    self.content_name = attributes[:'content_name']
  end

  if attributes.has_key?(:'content_category')
    self. = attributes[:'content_category']
  end

  if attributes.has_key?(:'content_ids')
    if (value = attributes[:'content_ids']).is_a?(Array)
      self.content_ids = value
    end
  end

  if attributes.has_key?(:'contents')
    if (value = attributes[:'contents']).is_a?(Array)
      self.contents = value
    end
  end

  if attributes.has_key?(:'content_type')
    self.content_type = attributes[:'content_type']
  end

  if attributes.has_key?(:'order_id')
    self.order_id = attributes[:'order_id']
  end

  if attributes.has_key?(:'predicted_ltv')
    self.predicted_ltv = attributes[:'predicted_ltv']
  end

  if attributes.has_key?(:'num_items')
    self.num_items = attributes[:'num_items']
  end

  if attributes.has_key?(:'status')
    self.status = attributes[:'status']
  end

  if attributes.has_key?(:'search_string')
    self.search_string = attributes[:'search_string']
  end

  if attributes.has_key?(:'delivery_category')
    self.delivery_category = attributes[:'delivery_category']
  end

  if attributes.has_key?(:'item_number')
    self.item_number = attributes[:'item_number']
  end

  if attributes.has_key?(:'custom_properties')
    self.custom_properties = attributes[:'custom_properties']
  end
end

#eql?(o) ⇒ Boolean

Returns:

  • (Boolean)

See Also:

  • `==` method


259
260
261
# File 'lib/facebook_ads/ad_objects/server_side/custom_data.rb', line 259

def eql?(o)
  self == o
end

#hashFixnum

Calculates hash code according to all attributes.

Returns:

  • (Fixnum)

    Hash code



265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
# File 'lib/facebook_ads/ad_objects/server_side/custom_data.rb', line 265

def hash
  [
      value,
      currency,
      content_name,
      ,
      content_ids,
      contents,
      content_type,
      order_id,
      predicted_ltv,
      num_items,
      status,
      search_string,
      delivery_category,
      item_number,
      custom_properties
  ].hash
end

#normalizeObject

Normalize input fields to server request format.



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
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
# File 'lib/facebook_ads/ad_objects/server_side/custom_data.rb', line 340

def normalize
  hash = {}
  unless value.nil?
    hash['value'] = value
  end
  unless currency.nil?
    hash['currency'] = FacebookAds::ServerSide::Util.normalize(currency, 'currency')
  end
  unless content_name.nil?
    hash['content_name'] = content_name
  end
  unless .nil?
    hash['content_category'] = 
  end
  unless content_ids.nil?
    hash['content_ids'] = content_ids
  end
  unless content_type.nil?
    hash['content_type'] = content_type
  end
  unless order_id.nil?
    hash['order_id'] = order_id
  end
  unless predicted_ltv.nil?
    hash['predicted_ltv'] = predicted_ltv
  end
  unless num_items.nil?
    hash['num_items'] = num_items
  end
  unless status.nil?
    hash['status'] = status
  end
  unless search_string.nil?
    hash['search_string'] = search_string
  end
  unless delivery_category.nil?
    hash['delivery_category'] = FacebookAds::ServerSide::Util.normalize(delivery_category, 'delivery_category')
  end
  unless item_number.nil?
    hash['item_number'] = item_number
  end

  unless contents.nil?
    content_array = []
    contents.each do |content|
      content_array.push(content.normalize)
    end
    hash['contents'] = content_array
  end

  hash.merge!(custom_properties) unless custom_properties.nil?
  hash
end

#to_sString

Returns the string representation of the object

Returns:

  • (String)

    String presentation of the object



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
320
321
322
323
324
325
326
327
328
329
330
331
332
# File 'lib/facebook_ads/ad_objects/server_side/custom_data.rb', line 287

def to_s
  hash = {}
  unless value.nil?
    hash['value'] = value
  end
  unless currency.nil?
    hash['currency'] = currency
  end
  unless content_name.nil?
    hash['content_name'] = content_name
  end
  unless .nil?
    hash['content_category'] = 
  end
  unless content_ids.nil?
    hash['content_ids'] = content_ids
  end
  unless contents.nil?
    hash['contents'] = contents.to_s
  end
  unless content_type.nil?
    hash['content_type'] = content_type
  end
  unless order_id.nil?
    hash['order_id'] = order_id
  end
  unless predicted_ltv.nil?
    hash['predicted_ltv'] = predicted_ltv
  end
  unless num_items.nil?
    hash['num_items'] = num_items
  end
  unless status.nil?
    hash['status'] = status
  end
  unless search_string.nil?
    hash['search_string'] = search_string
  end
  unless delivery_category.nil?
    hash['delivery_category'] = delivery_category
  end
  unless custom_properties.nil?
    hash['custom_properties'] = custom_properties
  end
  hash.to_s
end