class FacebookAds::ServerSide::CustomData

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

Attributes

content_category[RW]

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

content_ids[RW]

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.

content_name[RW]

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

content_type[RW]

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.

contents[RW]

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.

currency[RW]

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

custom_properties[RW]

Custom Properties bag for storing other custom fields

delivery_category[RW]

Type of delivery for a purchase event Example: 'home_delivery'.

item_number[RW]

The item number. Example: 'item1234'.

num_items[RW]

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

order_id[RW]

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

predicted_ltv[RW]

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

search_string[RW]

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

status[RW]

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

value[RW]

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

Public Class Methods

new(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: {}) click to toggle source

@param [Float] value @param [String] currency @param [String] content_name @param [String] content_category @param [Array<String>] content_ids @param [Array<Content>] contents @param [String] content_type @param [String] order_id @param [Float] predicted_ltv @param [Integer] num_items @param [String] status @param [String] search_string @param [String] delivery_category @param [String] item_number @param [String] custom_properties

# 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 content_category.nil?
    self.content_category = content_category
  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

Public Instance Methods

==(o) click to toggle source

Checks equality by comparing each attribute.

# 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 &&
      content_category == o.content_category &&
      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) click to toggle source

Add other custom fields to custom properties.

# 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 = {}) click to toggle source

build the object using the input hash @param [Hash] attributes attributes in the form of hash

# 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.content_category = 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) click to toggle source

@see the `==` method

# File lib/facebook_ads/ad_objects/server_side/custom_data.rb, line 259
def eql?(o)
  self == o
end
hash() click to toggle source

Calculates hash code according to all attributes. @return [Fixnum] Hash code

# File lib/facebook_ads/ad_objects/server_side/custom_data.rb, line 265
def hash
  [
      value,
      currency,
      content_name,
      content_category,
      content_ids,
      contents,
      content_type,
      order_id,
      predicted_ltv,
      num_items,
      status,
      search_string,
      delivery_category,
      item_number,
      custom_properties
  ].hash
end
normalize() click to toggle source

Normalize input fields to server request format.

# 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 content_category.nil?
    hash['content_category'] = 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_s() click to toggle source

Returns the string representation of the object @return [String] String presentation of the object

# 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 content_category.nil?
    hash['content_category'] = 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