Skip to content

Commit c05b50e

Browse files
shuaiwa-metafacebook-github-bot
authored andcommitted
update attribution_data, custom_data and original_event_data fields
Summary: Update attribution_data, custom_data and original_event_data: 1. add attribution_value to attribution_data 2. add net_revenue to custom_data 3. add order_id & event_id to original_event_data Reviewed By: satwikareddy3 Differential Revision: D74679651 Privacy Context Container: L1246766 fbshipit-source-id: b306f4dce641471670b5cdc8365b7ade1632eb79
1 parent 67fe545 commit c05b50e

File tree

7 files changed

+105
-6
lines changed

7 files changed

+105
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
55

66
## Unreleased
77

8+
## v22.0.2
9+
### Changed
10+
- Update attribution_data, custom_data and original_event_data fields
11+
812
## v17.0.0
913

1014

lib/facebook_ads/ad_objects/server_side/attribution_data.rb

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ class AttributionData
4646
# Attribution woindow in days.
4747
attr_accessor :attr_window
4848

49+
# The share of value generated by this click-conversion pair that is attributed to Meta.
50+
attr_accessor :attribution_value
51+
4952

5053

5154
# @param [String] scope
@@ -56,7 +59,8 @@ class AttributionData
5659
# @param [Float] attribution_share
5760
# @param [String] attribution_model
5861
# @param [String] attr_window
59-
def initialize(scope: nil, visit_time: nil, ad_id: nil, adset_id: nil, campaign_id: nil, attribution_share: nil, attribution_model: nil, attr_window: nil)
62+
# @param [Float] attribution_value
63+
def initialize(scope: nil, visit_time: nil, ad_id: nil, adset_id: nil, campaign_id: nil, attribution_share: nil, attribution_model: nil, attr_window: nil, attribution_value: nil)
6064
unless scope.nil?
6165
self.scope = scope
6266
end
@@ -81,6 +85,9 @@ def initialize(scope: nil, visit_time: nil, ad_id: nil, adset_id: nil, campaign_
8185
unless attr_window.nil?
8286
self.attr_window = attr_window
8387
end
88+
unless attribution_value.nil?
89+
self.attribution_value = attribution_value
90+
end
8491
end
8592

8693
# build the object using the input hash
@@ -122,6 +129,10 @@ def build(attributes = {})
122129
if attributes.has_key?(:'attr_window')
123130
self.attr_window = attributes[:'attr_window']
124131
end
132+
133+
if attributes.has_key?(:'attribution_value')
134+
self.attribution_share = attributes[:'attribution_value']
135+
end
125136
end
126137

127138
# Checks equality by comparing each attribute.
@@ -135,7 +146,8 @@ def ==(o)
135146
campaign_id == o.campaign_id &&
136147
attribution_share == o.attribution_share &&
137148
attribution_model == o.attribution_model &&
138-
attr_window == o.attr_window
149+
attr_window == o.attr_window &&
150+
attribution_value == o.attribution_value
139151
end
140152

141153
# @see the `==` method
@@ -147,7 +159,7 @@ def eql?(o)
147159
# @return [Fixnum] Hash code
148160
def hash
149161
[
150-
scope, visit_time, ad_id, adset_id, campaign_id, attribution_share, attribution_model, attr_window
162+
scope, visit_time, ad_id, adset_id, campaign_id, attribution_share, attribution_model, attr_window, attribution_value
151163
].hash
152164
end
153165

@@ -177,6 +189,9 @@ def to_s
177189
unless attr_window.nil?
178190
hash['attr_window'] = attr_window
179191
end
192+
unless attribution_value.nil?
193+
hash['attribution_value'] = attribution_value
194+
end
180195
hash.to_s
181196
end
182197

@@ -208,6 +223,9 @@ def normalize
208223
unless attr_window.nil?
209224
hash['attr_window'] = attr_window
210225
end
226+
unless attribution_value.nil?
227+
hash['attribution_value'] = attribution_value
228+
end
211229
hash
212230
end
213231

lib/facebook_ads/ad_objects/server_side/custom_data.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ class CustomData
2525
# Example: 142.54.
2626
attr_accessor :value
2727

28+
# A numeric net_revenue associated with this event. This could be a monetary net_revenue or a net_revenue in some other metric.
29+
# Example: 30.54.
30+
attr_accessor :net_revenue
31+
2832
# The currency for the value specified, if applicable. Currency must be a valid ISO 4217 three digit currency code.
2933
# Example: 'usd'.
3034
attr_accessor :currency
@@ -83,6 +87,7 @@ class CustomData
8387

8488

8589
# @param [Float] value
90+
# @param [Float] net_revenue
8691
# @param [String] currency
8792
# @param [String] content_name
8893
# @param [String] content_category
@@ -98,6 +103,7 @@ class CustomData
98103
# @param [String] item_number
99104
# @param [String] custom_properties
100105
def initialize(value: nil,
106+
net_revenue: nil,
101107
currency: nil,
102108
content_name: nil,
103109
content_category: nil,
@@ -116,6 +122,9 @@ def initialize(value: nil,
116122
unless value.nil?
117123
self.value = value
118124
end
125+
unless net_revenue.nil?
126+
self.net_revenue = net_revenue
127+
end
119128
unless currency.nil?
120129
self.currency = currency
121130
end
@@ -173,6 +182,10 @@ def build(attributes = {})
173182
self.value = attributes[:'value']
174183
end
175184

185+
if attributes.has_key?(:'net_revenue')
186+
self.net_revenue = attributes[:'net_revenue']
187+
end
188+
176189
if attributes.has_key?(:'currency')
177190
self.currency = attributes[:'currency']
178191
end
@@ -239,6 +252,7 @@ def ==(o)
239252
return true if self.equal?(o)
240253
self.class == o.class &&
241254
value == o.value &&
255+
net_revenue == o.net_revenue &&
242256
currency == o.currency &&
243257
content_name == o.content_name &&
244258
content_category == o.content_category &&
@@ -265,6 +279,7 @@ def eql?(o)
265279
def hash
266280
[
267281
value,
282+
net_revenue,
268283
currency,
269284
content_name,
270285
content_category,
@@ -289,6 +304,9 @@ def to_s
289304
unless value.nil?
290305
hash['value'] = value
291306
end
307+
unless net_revenue.nil?
308+
hash['net_revenue'] = net_revenue
309+
end
292310
unless currency.nil?
293311
hash['currency'] = currency
294312
end
@@ -342,6 +360,9 @@ def normalize
342360
unless value.nil?
343361
hash['value'] = value
344362
end
363+
unless net_revenue.nil?
364+
hash['net_revenue'] = net_revenue
365+
end
345366
unless currency.nil?
346367
hash['currency'] = FacebookAds::ServerSide::Util.normalize(currency, 'currency')
347368
end

lib/facebook_ads/ad_objects/server_side/original_event_data.rb

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,29 @@ class OriginalEventData
2929
# A Unix timestamp in seconds indicating when the original event occurred.
3030
attr_accessor :event_time
3131

32+
# The order ID for this transaction as a string.
33+
attr_accessor :order_id
34+
35+
# A unique string chosen by the advertiser.
36+
attr_accessor :event_id
37+
3238
# @param [String] event_name
3339
# @param [int] event_time
34-
def initialize(event_name: nil, event_time: nil)
40+
# @param [String] order_id
41+
# @param [String] event_id
42+
def initialize(event_name: nil, event_time: nil, order_id: nil, event_id: nil)
3543
unless event_name.nil?
3644
self.event_name = event_name
3745
end
3846
unless event_time.nil?
3947
self.event_time = event_time
4048
end
49+
unless order_id.nil?
50+
self.order_id = order_id
51+
end
52+
unless event_id.nil?
53+
self.event_id = event_id
54+
end
4155
end
4256

4357
# build the object using the input hash
@@ -55,14 +69,24 @@ def build(attributes = {})
5569
if attributes.has_key?(:'event_time')
5670
self.event_time = attributes[:'event_time']
5771
end
72+
73+
if attributes.has_key?(:'order_id')
74+
self.order_id = attributes[:'order_id']
75+
end
76+
77+
if attributes.has_key?(:'event_id')
78+
self.event_id = attributes[:'event_id']
79+
end
5880
end
5981

6082
# Checks equality by comparing each attribute.
6183
def ==(o)
6284
return true if self.equal?(o)
6385
self.class == o.class &&
6486
event_name == o.event_name &&
65-
event_time == o.event_time
87+
event_time == o.event_time &&
88+
order_id == o.order_id &&
89+
event_id == o.event_id
6690
end
6791

6892
# @see the `==` method
@@ -74,7 +98,7 @@ def eql?(o)
7498
# @return [Fixnum] Hash code
7599
def hash
76100
[
77-
event_name, event_time,
101+
event_name, event_time, order_id, event_id,
78102
].hash
79103
end
80104

@@ -86,6 +110,12 @@ def to_s
86110
unless event_time.nil?
87111
hash['event_time'] = event_time
88112
end
113+
unless order_id.nil?
114+
hash['order_id'] = order_id
115+
end
116+
unless event_id.nil?
117+
hash['event_id'] = event_id
118+
end
89119
hash.to_s
90120
end
91121

@@ -99,6 +129,12 @@ def normalize
99129
unless event_time.nil?
100130
hash['event_time'] = event_time
101131
end
132+
unless order_id.nil?
133+
hash['order_id'] = order_id
134+
end
135+
unless event_id.nil?
136+
hash['event_id'] = event_id
137+
end
102138
hash
103139
end
104140

spec/lib/facebook_ads/ad_objects/server_side/attribution_data_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
attr_window = 7
2828
attribution_share = 0.5
2929
attribution_model = 'last_click'
30+
attribution_value = 3.45
3031
attribution_data = FacebookAds::ServerSide::AttributionData.new(
3132
scope: scope,
3233
visit_time: visit_time,
@@ -36,6 +37,7 @@
3637
attr_window: attr_window,
3738
attribution_share: attribution_share,
3839
attribution_model: attribution_model,
40+
attribution_value: attribution_value,
3941
)
4042

4143
expect(attribution_data.normalize).to eq({
@@ -47,6 +49,7 @@
4749
'attr_window': attr_window,
4850
'attribution_share': attribution_share,
4951
'attribution_model': attribution_model,
52+
'attribution_value': attribution_value,
5053
})
5154
end
5255

@@ -65,6 +68,7 @@
6568
attr_window: 7,
6669
attribution_share: 0.5,
6770
attribution_model: 'last_click',
71+
attribution_value: 3.45,
6872
)
6973
attribution_data2 = FacebookAds::ServerSide::AttributionData.new(
7074
scope: 'click',
@@ -75,6 +79,7 @@
7579
attr_window: 7,
7680
attribution_share: 0.5,
7781
attribution_model: 'last_click',
82+
attribution_value: 3.45,
7883
)
7984
expect(attribution_data1).to eq(attribution_data2)
8085
expect(attribution_data1.hash).to eq(attribution_data2.hash)
@@ -95,6 +100,7 @@
95100
attr_window: 7,
96101
attribution_share: 0.5,
97102
attribution_model: 'last_click',
103+
attribution_value: 3.45,
98104
)
99105
attribution_data2 = FacebookAds::ServerSide::AttributionData.new(
100106
scope: 'click',
@@ -106,6 +112,7 @@
106112
# different attribution share to test
107113
attribution_share: 0.4,
108114
attribution_model: 'last_click',
115+
attribution_value: 2.45,
109116
)
110117
expect(attribution_data1).to_not eq(attribution_data2)
111118
expect(attribution_data1.hash).to_not eq(attribution_data2.hash)

spec/lib/facebook_ads/ad_objects/server_side/custom_data_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
RSpec.describe 'FacebookAds::ServerSide::CustomData' do
2121
it 'normalize works' do
2222
value = 0.1
23+
net_revenue = 0.05
2324
currency = 'usd'
2425
content_name = 'content-name-1'
2526
content_category = 'content-category-2'
@@ -36,6 +37,7 @@
3637
custom_properties = {'custom10' => 'property10'}
3738
custom_data = FacebookAds::ServerSide::CustomData.new(
3839
value: value,
40+
net_revenue: net_revenue,
3941
currency: currency,
4042
content_name: content_name,
4143
content_category: content_category,
@@ -54,6 +56,7 @@
5456

5557
expect(custom_data.normalize).to eq(custom_properties.merge(
5658
'value' => value,
59+
'net_revenue' => net_revenue,
5760
'currency' => currency,
5861
'content_name' => content_name,
5962
'content_category' => content_category,
@@ -88,6 +91,7 @@
8891

8992
custom_data1 = FacebookAds::ServerSide::CustomData.new(
9093
value: 0.1,
94+
net_revenue: 0.05,
9195
currency: 'usd',
9296
content_name: 'content-name-1',
9397
content_category: 'content-category-2',
@@ -105,6 +109,7 @@
105109
)
106110
custom_data2 = FacebookAds::ServerSide::CustomData.new(
107111
value: 0.1,
112+
net_revenue: 0.05,
108113
currency: 'usd',
109114
content_name: 'content-name-1',
110115
content_category: 'content-category-2',
@@ -127,6 +132,7 @@
127132
it 'not equals works' do
128133
custom_data1 = FacebookAds::ServerSide::CustomData.new(
129134
value: 0.1,
135+
net_revenue: 0.05,
130136
currency: 'usd',
131137
content_name: 'content-name-1',
132138
content_category: 'content-category-2',
@@ -144,6 +150,7 @@
144150
)
145151
custom_data2 = FacebookAds::ServerSide::CustomData.new(
146152
value: 0.1,
153+
net_revenue: 0.03,
147154
currency: 'usd',
148155
content_name: 'content-name-1',
149156
content_category: 'content-category-2',

spec/lib/facebook_ads/ad_objects/server_side/original_event_data_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,20 @@
2121
it 'normalize works' do
2222
event_name = 'event-name-1'
2323
event_time = 12345
24+
order_id = 'order_id-1'
25+
event_id = 'event_id-1'
2426
original_event_data = FacebookAds::ServerSide::OriginalEventData.new(
2527
event_name: event_name,
2628
event_time: event_time,
29+
order_id: order_id,
30+
event_id: event_id,
2731
)
2832

2933
expect(original_event_data.normalize).to eq({
3034
'event_name' => event_name,
3135
'event_time' => event_time,
36+
'order_id' => order_id,
37+
'event_id' => event_id,
3238
})
3339
end
3440

0 commit comments

Comments
 (0)