Class: FacebookAds::ServerSide::Event

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

Overview

Server Side Event object.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event_name: nil, event_time: nil, event_source_url: nil, opt_out: nil, event_id: nil, user_data: nil, custom_data: nil, app_data: nil, data_processing_options: nil, data_processing_options_country: nil, data_processing_options_state: nil, action_source: nil, advanced_measurement_table: nil, messaging_channel: nil, original_event_data: nil, attribution_data: nil, referrer_url: nil) ⇒ Event

Returns a new instance of Event.

Parameters:



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

def initialize(event_name: nil,
               event_time: nil,
               event_source_url: nil,
               opt_out: nil,
               event_id: nil,
               user_data: nil,
               custom_data: nil,
               app_data: nil,
               data_processing_options: nil,
               data_processing_options_country: nil,
               data_processing_options_state: nil,
               action_source: nil,
               advanced_measurement_table: nil,
               messaging_channel: nil,
               original_event_data: nil,
               attribution_data: nil,
               referrer_url: nil
               )

  unless event_name.nil?
    self.event_name = event_name
  end
  unless event_time.nil?
    self.event_time = event_time
  end
  unless event_source_url.nil?
    self.event_source_url = event_source_url
  end
  unless opt_out.nil?
    self.opt_out = opt_out
  end
  unless event_id.nil?
    self.event_id = event_id
  end
  unless user_data.nil?
    self.user_data = user_data
  end
  unless custom_data.nil?
    self.custom_data = custom_data
  end
  unless app_data.nil?
    self.app_data = app_data
  end
  unless data_processing_options.nil?
    self.data_processing_options = data_processing_options
  end
  unless data_processing_options_country.nil?
    self.data_processing_options_country = data_processing_options_country
  end
  unless data_processing_options_state.nil?
    self.data_processing_options_state = data_processing_options_state
  end
  unless action_source.nil?
    self.action_source = action_source
  end
  unless advanced_measurement_table.nil?
    self.advanced_measurement_table = advanced_measurement_table
  end
  unless messaging_channel.nil?
    self.messaging_channel = messaging_channel
  end
  unless original_event_data.nil?
    self.original_event_data = original_event_data
  end
  unless attribution_data.nil?
    self.attribution_data = attribution_data
  end
  unless referrer_url.nil?
    self.referrer_url = referrer_url
  end
end

Instance Attribute Details

#action_sourceObject

Where the conversion occurred.



76
77
78
# File 'lib/facebook_ads/ad_objects/server_side/event.rb', line 76

def action_source
  @action_source
end

#advanced_measurement_tableObject

Name of Advanced Measurement table. Only used for the Advanced Measurement API in the Advanced Analytics product



80
81
82
# File 'lib/facebook_ads/ad_objects/server_side/event.rb', line 80

def advanced_measurement_table
  @advanced_measurement_table
end

#app_dataObject

An Object that contains app data.



61
62
63
# File 'lib/facebook_ads/ad_objects/server_side/event.rb', line 61

def app_data
  @app_data
end

#attribution_dataObject

Attribution data info



89
90
91
# File 'lib/facebook_ads/ad_objects/server_side/event.rb', line 89

def attribution_data
  @attribution_data
end

#custom_dataObject

An Object that includes additional business data about the event.



58
59
60
# File 'lib/facebook_ads/ad_objects/server_side/event.rb', line 58

def custom_data
  @custom_data
end

#data_processing_optionsObject

Processing options you would like to enable for a specific event. For more details see developers.facebook.com/docs/marketing-apis/data-processing-options



65
66
67
# File 'lib/facebook_ads/ad_objects/server_side/event.rb', line 65

def data_processing_options
  @data_processing_options
end

#data_processing_options_countryObject

A country that you want to associate to this data processing option For more details see developers.facebook.com/docs/marketing-apis/data-processing-options



69
70
71
# File 'lib/facebook_ads/ad_objects/server_side/event.rb', line 69

def data_processing_options_country
  @data_processing_options_country
end

#data_processing_options_stateObject

A state that you want to associate with this data processing option. For more details see developers.facebook.com/docs/marketing-apis/data-processing-options



73
74
75
# File 'lib/facebook_ads/ad_objects/server_side/event.rb', line 73

def data_processing_options_state
  @data_processing_options_state
end

#event_idObject

This ID can be any unique string chosen by the advertiser. event_id is used to deduplicate events sent by both Facebook Pixel and Server-Side API. event_name is also used in the deduplication process. For deduplication, the eventID from Facebook pixel must match the event_id in the corresponding Server-Side API event.



52
53
54
# File 'lib/facebook_ads/ad_objects/server_side/event.rb', line 52

def event_id
  @event_id
end

#event_nameObject

A Facebook pixel Standard Event or Custom Event name. This is used with event_id to determine if events are identical.



35
36
37
# File 'lib/facebook_ads/ad_objects/server_side/event.rb', line 35

def event_name
  @event_name
end

#event_source_urlObject

The browser URL where the event happened.



41
42
43
# File 'lib/facebook_ads/ad_objects/server_side/event.rb', line 41

def event_source_url
  @event_source_url
end

#event_timeObject

A Unix timestamp in seconds indicating when the actual event occurred.



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

def event_time
  @event_time
end

#messaging_channelObject

Messaging channel for the event



83
84
85
# File 'lib/facebook_ads/ad_objects/server_side/event.rb', line 83

def messaging_channel
  @messaging_channel
end

#opt_outObject

A flag that indicates we should not use this event for ads delivery optimization. If set to true, we only use the event for attribution.



45
46
47
# File 'lib/facebook_ads/ad_objects/server_side/event.rb', line 45

def opt_out
  @opt_out
end

#original_event_dataObject

Original event info



86
87
88
# File 'lib/facebook_ads/ad_objects/server_side/event.rb', line 86

def original_event_data
  @original_event_data
end

#param_builderObject

The CAPI ParamBuilder instance constructed when set_request_context is called. Used internally to extract auto-populated fields from the request context.



106
107
108
# File 'lib/facebook_ads/ad_objects/server_side/event.rb', line 106

def param_builder
  @param_builder
end

#preferenceObject

Preference allowlist controlling which fields the CAPI ParamBuilder is allowed to auto-set on the event. Set by set_request_context.



101
102
103
# File 'lib/facebook_ads/ad_objects/server_side/event.rb', line 101

def preference
  @preference
end

#referrer_urlObject

The referrer URL of the browser request that triggered the event.



92
93
94
# File 'lib/facebook_ads/ad_objects/server_side/event.rb', line 92

def referrer_url
  @referrer_url
end

#request_contextObject

The request context (e.g. an HTTP request object) supplied via set_request_context. Used by the CAPI ParamBuilder to auto-extract parameters such as fbc, fbp, client_ip_address.



97
98
99
# File 'lib/facebook_ads/ad_objects/server_side/event.rb', line 97

def request_context
  @request_context
end

#user_dataObject

An Object that contains user data.



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

def user_data
  @user_data
end

Instance Method Details

#==(o) ⇒ Object

Checks equality by comparing each attribute.



329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
# File 'lib/facebook_ads/ad_objects/server_side/event.rb', line 329

def ==(o)
  return true if self.equal?(o)
  self.class == o.class &&
      event_name == o.event_name &&
      event_time == o.event_time &&
      event_source_url == o.event_source_url &&
      opt_out == o.opt_out &&
      event_id == o.event_id &&
      user_data == o.user_data &&
      custom_data == o.custom_data &&
      app_data == o.app_data &&
      data_processing_options == o.data_processing_options &&
      data_processing_options_country == o.data_processing_options_country &&
      data_processing_options_state == o.data_processing_options_state &&
      action_source == o.action_source &&
      advanced_measurement_table == o.advanced_measurement_table &&
      messaging_channel == o.messaging_channel &&
      original_event_data == o.original_event_data &&
      attribution_data == o.attribution_data &&
      referrer_url == o.referrer_url
end

#build(attributes = {}) ⇒ Object

build the object using the input hash

Parameters:

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

    attributes in the form of hash



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

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?(:'event_name')
    self.event_name = attributes[:'event_name']
  end

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

#eql?(o) ⇒ Boolean

Returns:

  • (Boolean)

See Also:

  • `==` method


352
353
354
# File 'lib/facebook_ads/ad_objects/server_side/event.rb', line 352

def eql?(o)
  self == o
end

#hashFixnum

Calculates hash code according to all attributes.

Returns:

  • (Fixnum)

    Hash code



358
359
360
361
362
363
364
365
# File 'lib/facebook_ads/ad_objects/server_side/event.rb', line 358

def hash
  [
    event_name, event_time, event_source_url, opt_out, event_id, user_data, custom_data, app_data,
    data_processing_options, data_processing_options_country, data_processing_options_state,
    action_source, advanced_measurement_table, messaging_channel, original_event_data, attribution_data,
    referrer_url
  ].hash
end

#list_invalid_propertiesObject

Show invalid properties with the reasons. Usually used together with valid?

Returns:

  • Array for valid properties with the reasons



302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
# File 'lib/facebook_ads/ad_objects/server_side/event.rb', line 302

def list_invalid_properties
  invalid_properties = Array.new
  if @event_name.nil?
    invalid_properties.push('invalid value for "event_name", event_name cannot be nil.')
  end

  if @event_time.nil?
    invalid_properties.push('invalid value for "event_time", event_time cannot be nil.')
  end

  if @user_data.nil?
    invalid_properties.push('invalid value for "user_data", user_data cannot be nil.')
  end

  invalid_properties
end

#normalizeObject

Normalize input fields to server request format.



425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
# File 'lib/facebook_ads/ad_objects/server_side/event.rb', line 425

def normalize
  apply_param_builder_defaults

  hash = {}
  unless event_name.nil?
    hash['event_name'] = event_name
  end
  unless event_time.nil?
    hash['event_time'] = event_time
  end
  unless event_source_url.nil?
    hash['event_source_url'] = event_source_url
  end
  unless opt_out.nil?
    hash['opt_out'] = opt_out
  end
  unless event_id.nil?
    hash['event_id'] = event_id
  end
  unless user_data.nil?
    hash['user_data'] = user_data.normalize
  end
  unless custom_data.nil?
    hash['custom_data'] = custom_data.normalize
  end
  unless app_data.nil?
    hash['app_data'] = app_data.normalize
  end
  unless data_processing_options.nil?
    hash['data_processing_options'] = data_processing_options
  end
  unless data_processing_options_country.nil?
    hash['data_processing_options_country'] = data_processing_options_country
  end
  unless data_processing_options_state.nil?
    hash['data_processing_options_state'] = data_processing_options_state
  end
  unless action_source.nil?
    hash['action_source'] = FacebookAds::ServerSide::Util.normalize(
      action_source,
      'action_source'
    )
  end
  unless advanced_measurement_table.nil?
    hash['advanced_measurement_table'] = advanced_measurement_table
  end
  unless messaging_channel.nil?
    hash['messaging_channel'] = messaging_channel
  end
  unless original_event_data.nil?
    hash['original_event_data'] = original_event_data.normalize
  end
  unless attribution_data.nil?
    hash['attribution_data'] = attribution_data.normalize
  end
  unless referrer_url.nil?
    hash['referrer_url'] = referrer_url
  end
  hash
end

#set_request_context(context, preference: nil) ⇒ self

Sets the request context and optional preference for automatic data extraction.

Stores the context and constructs a CAPI ParamBuilder; extraction of parameters (fbc, fbp, …) into UserData is deferred until normalize runs at send time, so call order with user_data assignment does not matter. The preference object controls which data are allowed to be auto-set. If no preference is provided, all fields default to true.

Parameters:

  • context

    Object the request context (e.g. an HTTP request)

  • preference (FacebookAds::ServerSide::Preference) (defaults to: nil)

    optional Preference object controlling auto-extraction

Returns:

  • (self)

    returns self for chaining



287
288
289
290
291
292
293
294
295
296
297
298
# File 'lib/facebook_ads/ad_objects/server_side/event.rb', line 287

def set_request_context(context, preference: nil)
  unless preference.nil? || preference.is_a?(FacebookAds::ServerSide::Preference)
    raise ArgumentError,
      'Event.preference must be a FacebookAds::ServerSide::Preference'
  end

  self.request_context = context
  self.preference = preference.nil? ? FacebookAds::ServerSide::Preference.new : preference
  self.param_builder = ::ParamBuilder.new
  self.param_builder.process_request_from_context(context)
  self
end

#to_sObject



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
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
# File 'lib/facebook_ads/ad_objects/server_side/event.rb', line 367

def to_s
  hash = {}
  unless event_name.nil?
    hash['event_name'] = event_name
  end
  unless event_time.nil?
    hash['event_time'] = event_time
  end
  unless event_source_url.nil?
    hash['event_source_url'] = event_source_url
  end
  unless opt_out.nil?
    hash['opt_out'] = opt_out
  end
  unless event_id.nil?
    hash['event_id'] = event_id
  end
  unless user_data.nil?
    hash['user_data'] = user_data.to_s
  end
  unless custom_data.nil?
    hash['custom_data'] = custom_data.to_s
  end
  unless app_data.nil?
    hash['app_data'] = app_data.to_s
  end
  unless data_processing_options.nil?
    hash['data_processing_options'] = data_processing_options.to_s
  end
  unless data_processing_options_country.nil?
    hash['data_processing_options_country'] = data_processing_options_country.to_s
  end
  unless data_processing_options_state.nil?
    hash['data_processing_options_state'] = data_processing_options_state.to_s
  end
  unless action_source.nil?
    hash['action_source'] = action_source
  end
  unless advanced_measurement_table.nil?
    hash['advanced_measurement_table'] = advanced_measurement_table
  end
  unless messaging_channel.nil?
    hash['messaging_channel'] = messaging_channel
  end
  unless original_event_data.nil?
    hash['original_event_data'] = original_event_data.to_s
  end
  unless attribution_data.nil?
    hash['attribution_data'] = attribution_data.to_s
  end
  unless referrer_url.nil?
    hash['referrer_url'] = referrer_url
  end
  hash.to_s
end

#valid?Boolean

Check to see if the all the properties in the model are valid

Returns:

  • (Boolean)

    true if the model is valid



321
322
323
324
325
326
# File 'lib/facebook_ads/ad_objects/server_side/event.rb', line 321

def valid?
  return false if @event_name.nil?
  return false if @event_time.nil?
  return false if @user_data.nil?
  true
end