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


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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/facebook_ads/ad_objects/server_side/custom_data.rb', line 86

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)

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

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



200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/facebook_ads/ad_objects/server_side/custom_data.rb', line 200

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
end

#build(attributes = {}) ⇒ Object

build the object using the input hash

Parameters:

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

    attributes in the form of hash



140
141
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/facebook_ads/ad_objects/server_side/custom_data.rb', line 140

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
end

#eql?(o) ⇒ Boolean

Returns:

  • (Boolean)

See Also:

  • `==` method


218
219
220
# File 'lib/facebook_ads/ad_objects/server_side/custom_data.rb', line 218

def eql?(o)
  self == o
end

#hashFixnum

Calculates hash code according to all attributes.

Returns:

  • (Fixnum)

    Hash code



224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'lib/facebook_ads/ad_objects/server_side/custom_data.rb', line 224

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

#normalizeObject

Normalize input fields to server request format.



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

def normalize
  hash = {}
  unless value.nil?
    hash['value'] = value
  end
  unless currency.nil?
    hash['currency'] = FacebookAds::ServerSide::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 contents.nil?
    content_array = []
    contents.each do |content|
      content_array.push(content.normalize)
    end
    hash['contents'] = content_array
  end
  hash
end

#to_sString

Returns the string representation of the object

Returns:

  • (String)

    String presentation of the object



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

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
  hash.to_s
end