Class: FacebookAds::ServerSide::UserData

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

Overview

UserData is a set of identifiers Facebook can use for targeted attribution

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(email: nil, phone: nil, gender: nil, date_of_birth: nil, last_name: nil, first_name: nil, city: nil, state: nil, country_code: nil, zip_code: nil, external_id: nil, client_ip_address: nil, client_user_agent: nil, fbc: nil, fbp: nil, subscription_id: nil) ⇒ UserData

UserData is a set of identifiers Facebook can use for targeted attribution

Parameters:

  • email (String) (defaults to: nil)
  • phone (String) (defaults to: nil)
  • gender (String) (defaults to: nil)
  • date_of_birth (String) (defaults to: nil)
  • last_name (String) (defaults to: nil)
  • first_name (String) (defaults to: nil)
  • city (String) (defaults to: nil)
  • state (String) (defaults to: nil)
  • country_code (String) (defaults to: nil)
  • zip_code (String) (defaults to: nil)
  • external_id (String) (defaults to: nil)
  • client_ip_address (String) (defaults to: nil)
  • client_user_agent (String) (defaults to: nil)
  • fbc (String) (defaults to: nil)
  • fbp (String) (defaults to: nil)
  • subscription_id (String) (defaults to: nil)


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
162
163
164
165
# File 'lib/facebook_ads/ad_objects/server_side/user_data.rb', line 113

def initialize(email: nil, phone: nil, gender: nil, date_of_birth: nil,
               last_name: nil, first_name: nil, city: nil, state: nil,
               country_code: nil, zip_code: nil, external_id: nil, client_ip_address: nil,
               client_user_agent: nil, fbc: nil, fbp: nil, subscription_id: nil)
  unless email.nil?
    self.email = email
  end
  unless phone.nil?
    self.phone = phone
  end
  unless gender.nil?
    self.gender = gender
  end
  unless date_of_birth.nil?
    self.date_of_birth = date_of_birth
  end
  unless last_name.nil?
    self.last_name = last_name
  end
  unless first_name.nil?
    self.first_name = first_name
  end
  unless city.nil?
    self.city = city
  end
  unless state.nil?
    self.state = state
  end
  unless country_code.nil?
    self.country_code = country_code
  end
  unless zip_code.nil?
    self.zip_code = zip_code
  end
  unless external_id.nil?
    self.external_id = external_id
  end
  unless client_ip_address.nil?
    self.client_ip_address = client_ip_address
  end
  unless client_user_agent.nil?
    self.client_user_agent = client_user_agent
  end
  unless fbc.nil?
    self.fbc = fbc
  end
  unless fbp.nil?
    self.fbp = fbp
  end
  unless subscription_id.nil?
    self.subscription_id = subscription_id
  end
end

Instance Attribute Details

#cityObject

A city in lower-case without spaces or punctuation. Example: menlopark



53
54
55
# File 'lib/facebook_ads/ad_objects/server_side/user_data.rb', line 53

def city
  @city
end

#client_ip_addressObject

The IP address of the browser corresponding to the event.



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

def client_ip_address
  @client_ip_address
end

#client_user_agentObject

The user agent for the browser corresponding to the event.



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

def client_user_agent
  @client_user_agent
end

#country_codeObject

A two-letter country code in lowercase. Example: us



57
58
59
# File 'lib/facebook_ads/ad_objects/server_side/user_data.rb', line 57

def country_code
  @country_code
end

#date_of_birthObject

A date of birth given as year, month, and day. Format should be ‘YYYYMMDD’ Example: 19971226 for December 26, 1997.



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

def date_of_birth
  @date_of_birth
end

#emailObject

An email address, in lowercase. Example: [email protected]



29
30
31
# File 'lib/facebook_ads/ad_objects/server_side/user_data.rb', line 29

def email
  @email
end

#external_idObject

Any unique ID from the advertiser, such as loyalty membership IDs, user IDs, and external cookie IDs. In the Offline Conversions API (www.facebook.com/business/help/104039186799009), this is known as extern_id. For more information, see Offline Conversions, Providing External IDs. If External ID is being sent via other channels, then it should be sent in the same format via the server-side API.



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

def external_id
  @external_id
end

#fbcObject

The Facebook click ID value stored in the _fbc browser cookie under your domain. See Managing fbc and fbp Parameters for how to get this value (developers.facebook.com/docs/marketing-api/facebook-pixel/server-side-api/parameters#fbc), or generate this value from a fbclid query parameter.



85
86
87
# File 'lib/facebook_ads/ad_objects/server_side/user_data.rb', line 85

def fbc
  @fbc
end

#fbpObject

The Facebook browser ID value stored in the _fbp browser cookie under your domain. See Managing fbc and fbp Parameters for how to get this value (developers.facebook.com/docs/marketing-api/facebook-pixel/server-side-api/parameters#fbc), or generate this value from a fbclid query parameter.



91
92
93
# File 'lib/facebook_ads/ad_objects/server_side/user_data.rb', line 91

def fbp
  @fbp
end

#first_nameObject

A first name in lowercase. Example: joe



49
50
51
# File 'lib/facebook_ads/ad_objects/server_side/user_data.rb', line 49

def first_name
  @first_name
end

#genderObject

Gender, in lowercase. Either f or m.



36
37
38
# File 'lib/facebook_ads/ad_objects/server_side/user_data.rb', line 36

def gender
  @gender
end

#last_nameObject

A last name in lowercase. Example: smith



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

def last_name
  @last_name
end

#phoneObject

A phone number. Include only digits with country code, area code, and number. Example: 16505551212



33
34
35
# File 'lib/facebook_ads/ad_objects/server_side/user_data.rb', line 33

def phone
  @phone
end

#stateObject

A two-letter state code in lowercase. Example: ca



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

def state
  @state
end

#subscription_idObject

The subscription ID for the user in this transaction. This is similar to the order ID for an individual product.



94
95
96
# File 'lib/facebook_ads/ad_objects/server_side/user_data.rb', line 94

def subscription_id
  @subscription_id
end

#zip_codeObject

A five-digit zip code for United States. For other locations, follow each country’s standards. Example: 94035 (for United States)



66
67
68
# File 'lib/facebook_ads/ad_objects/server_side/user_data.rb', line 66

def zip_code
  @zip_code
end

Instance Method Details

#==(o) ⇒ Object

Checks equality by comparing each attribute.



241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
# File 'lib/facebook_ads/ad_objects/server_side/user_data.rb', line 241

def ==(o)
  return true if self.equal?(o)
  self.class == o.class &&
      email == o.email &&
      phone == o.phone &&
      gender == o.gender &&
      date_of_birth == o.date_of_birth &&
      last_name == o.last_name &&
      first_name == o.first_name &&
      city == o.city &&
      country_code == o.country_code &&
      state == o.state &&
      zip_code == o.zip_code &&
      external_id == o.external_id &&
      client_ip_address == o.client_ip_address &&
      client_user_agent == o.client_user_agent &&
      fbc == o.fbc &&
      fbp == o.fbp &&
      subscription_id == o.subscription_id
end

#build(attributes = {}) ⇒ Object

build the object using the input hash

Parameters:

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

    attributes in the form of hash



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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

#eql?(o) ⇒ Boolean

Returns:

  • (Boolean)

See Also:

  • `==` method


263
264
265
# File 'lib/facebook_ads/ad_objects/server_side/user_data.rb', line 263

def eql?(o)
  self == o
end

#hashFixnum

Calculates hash code according to all attributes.

Returns:

  • (Fixnum)

    Hash code



269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
# File 'lib/facebook_ads/ad_objects/server_side/user_data.rb', line 269

def hash
  [
      email,
      phone,
      gender,
      date_of_birth,
      last_name,
      first_name,
      city,
      country_code,
      state,
      zip_code,
      external_id,
      client_ip_address,
      client_user_agent,
      fbc,
      fbp,
      subscription_id
  ].hash

end

#normalizeObject

Normalize input fields to server request format.



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

def normalize
  hash = {}
  unless email.nil?
    hash['em'] = FacebookAds::ServerSide::normalize(email, 'em')
  end
  unless phone.nil?
    hash['ph'] = FacebookAds::ServerSide::normalize(phone, 'ph')
  end
  unless gender.nil?
    hash['ge'] = FacebookAds::ServerSide::normalize(gender, 'ge')
  end
  unless date_of_birth.nil?
    hash['db'] = FacebookAds::ServerSide::normalize(date_of_birth, 'db')
  end
  unless last_name.nil?
    hash['ln'] = FacebookAds::ServerSide::normalize(last_name, 'ln')
  end
  unless first_name.nil?
    hash['fn'] = FacebookAds::ServerSide::normalize(first_name, 'fn')
  end
  unless city.nil?
    hash['ct'] = FacebookAds::ServerSide::normalize(city, 'ct')
  end
  unless country_code.nil?
    hash['country'] = FacebookAds::ServerSide::normalize(country_code, 'country')
  end
  unless state.nil?
    hash['st'] = FacebookAds::ServerSide::normalize(state, 'st')
  end
  unless zip_code.nil?
    hash['zp'] = FacebookAds::ServerSide::normalize(zip_code, 'zp')
  end
  unless external_id.nil?
    hash['external_id'] = external_id
  end
  unless client_ip_address.nil?
    hash['client_ip_address'] = client_ip_address
  end
  unless fbc.nil?
    hash['fbc'] = fbc
  end
  unless fbp.nil?
    hash['fbp'] = fbp
  end
  unless subscription_id.nil?
    hash['subscription_id'] = subscription_id
  end
  hash
end

#to_sString

Returns the string representation of the object

Returns:

  • (String)

    String presentation of the object



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
333
334
335
336
337
338
339
340
341
# File 'lib/facebook_ads/ad_objects/server_side/user_data.rb', line 293

def to_s
  hash = {}
  unless email.nil?
    hash['email'] = email
  end
  unless phone.nil?
    hash['phone'] = phone
  end
  unless gender.nil?
    hash['gender'] = gender
  end
  unless date_of_birth.nil?
    hash['date_of_birth'] = date_of_birth
  end
  unless last_name.nil?
    hash['last_name'] = last_name
  end
  unless first_name.nil?
    hash['first_name'] = first_name
  end
  unless city.nil?
    hash['city'] = city
  end
  unless country_code.nil?
    hash['country_code'] = country_code
  end
  unless state.nil?
    hash['state'] = state
  end
  unless zip_code.nil?
    hash['zip_code'] = zip_code
  end
  unless external_id.nil?
    hash['external_id'] = external_id
  end
  unless client_ip_address.nil?
    hash['client_ip_address'] = client_ip_address
  end
  unless fbc.nil?
    hash['fbc'] = fbc
  end
  unless fbp.nil?
    hash['fbp'] = fbp
  end
  unless subscription_id.nil?
    hash['subscription_id'] = subscription_id
  end
  hash.to_s
end