Skip to content

Commit b0c3c8b

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: kanakb, liliarizona Differential Revision: D72841933 fbshipit-source-id: 0279a0bc3721aa69e07a503dba22fd45c97a4019
1 parent 65b2057 commit b0c3c8b

File tree

6 files changed

+139
-14
lines changed

6 files changed

+139
-14
lines changed

facebook_business/adobjects/serverside/attribution_data.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ class AttributionData(object):
3333
'attribution_share': 'float',
3434
'attribution_model': 'AttributionModel',
3535
'attr_window': 'int',
36+
'attribution_value': 'float',
3637
}
3738

38-
def __init__(self, scope = None, visit_time = None, ad_id = None, adset_id = None, campaign_id = None, attribution_share = None, attribution_model = None, attr_window = None):
39-
# type: (str, int) -> None
39+
def __init__(self, scope = None, visit_time = None, ad_id = None, adset_id = None, campaign_id = None, attribution_share = None, attribution_model = None, attr_window = None, attribution_value = None):
40+
# type: (str, int, str, str, str, float, AttributionModel, int, float) -> None
4041

4142
"""Conversions API Attribution Data"""
4243
self._scope = None
@@ -47,6 +48,7 @@ def __init__(self, scope = None, visit_time = None, ad_id = None, adset_id = Non
4748
self._attribution_share = None
4849
self._attribution_model = None
4950
self._attr_window = None
51+
self._attribution_value = None
5052

5153
if scope is not None:
5254
self.scope = scope
@@ -64,6 +66,8 @@ def __init__(self, scope = None, visit_time = None, ad_id = None, adset_id = Non
6466
self.attribution_model = attribution_model
6567
if attr_window is not None:
6668
self.attr_window = attr_window
69+
if attribution_value is not None:
70+
self.attribution_value = attribution_value
6771

6872
@property
6973
def scope(self):
@@ -244,6 +248,28 @@ def attr_window(self, attr_window):
244248
"""
245249
self._attr_window = attr_window
246250

251+
@property
252+
def attribution_value(self):
253+
"""Gets the attribution_value of Attribution Data.
254+
255+
The share of value generated by this click-conversion pair that is attributed to Meta.
256+
257+
:return: The attribution_value of Attribution Data.
258+
:rtype: float
259+
"""
260+
return self._attribution_value
261+
262+
@attribution_value.setter
263+
def attribution_value(self, attribution_value):
264+
"""Sets the attribution_value of Attribution Data.
265+
266+
The share of value generated by this click-conversion pair that is attributed to Meta.
267+
268+
:param attribution_value: The attribution_value of Attribution Data.
269+
:type: float
270+
"""
271+
self._attribution_value = attribution_value
272+
247273

248274
def normalize(self):
249275
normalized_payload = {
@@ -255,6 +281,7 @@ def normalize(self):
255281
'attribution_share': self.attribution_share,
256282
'attribution_model': self.attribution_model,
257283
'attr_window': self.attr_window,
284+
'attribution_value': self.attribution_value,
258285
}
259286
normalized_payload = {k: v for k, v in normalized_payload.items() if v is not None}
260287
return normalized_payload

facebook_business/adobjects/serverside/custom_data.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class CustomData(object):
3131
"""
3232
param_types = {
3333
'value': 'float',
34+
'net_revenue': 'float',
3435
'currency': 'str',
3536
'content_name': 'str',
3637
'content_category': 'str',
@@ -50,6 +51,7 @@ class CustomData(object):
5051
def __init__(
5152
self,
5253
value=None,
54+
net_revenue=None,
5355
currency=None,
5456
content_name=None,
5557
content_category=None,
@@ -65,9 +67,10 @@ def __init__(
6567
item_number=None,
6668
custom_properties={},
6769
):
68-
# type: (float, str, str, str, List[str], List[Content], str, str, float, int, str, str, DeliveryCategory ,str, dict) -> None
70+
# type: (float, float, str, str, str, list[str], list[Content], str, str, float, int, str, str, DeliveryCategory ,str, dict) -> None
6971

7072
self._value = None
73+
self._net_revenue = None
7174
self._currency = None
7275
self._content_name = None
7376
self._content_category = None
@@ -84,6 +87,8 @@ def __init__(
8487
self._custom_properties = None
8588
if value is not None:
8689
self.value = value
90+
if net_revenue is not None:
91+
self.net_revenue = net_revenue
8792
if currency is not None:
8893
self.currency = currency
8994
if content_name is not None:
@@ -137,6 +142,30 @@ def value(self, value):
137142
raise TypeError('CustomData.value must be a float or int. TypeError on value: %s' % value)
138143
self._value = value
139144

145+
@property
146+
def net_revenue(self):
147+
"""Gets the net_revenue.
148+
149+
A numeric net revenue associated with this event.
150+
151+
:return: The net_revenue.
152+
:rtype: float or int
153+
"""
154+
return self._net_revenue
155+
156+
@net_revenue.setter
157+
def net_revenue(self, net_revenue):
158+
"""Sets the net_revenue.
159+
160+
A numeric net revenue associated with this event.
161+
162+
:param net_revenue: The net_revenue.
163+
:type: float or int
164+
"""
165+
if not isinstance(net_revenue, (float, int)):
166+
raise TypeError('CustomData.net_revenue must be a float or int. TypeError on value: %s' % net_revenue)
167+
self._net_revenue = net_revenue
168+
140169
@property
141170
def currency(self):
142171
"""Gets the currency.
@@ -475,6 +504,7 @@ def add_custom_property(self, key, value):
475504
def normalize(self):
476505
normalized_payload = {
477506
'value': self.value,
507+
'net_revenue': self.net_revenue,
478508
'currency': Normalize.normalize_field_skip_hashing('currency', self.currency),
479509
'content_name': self.content_name,
480510
'content_category': self.content_category,

facebook_business/adobjects/serverside/original_event_data.py

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,27 @@ class OriginalEventData(object):
2626
param_types = {
2727
'event_name': 'str',
2828
'event_time': 'int',
29+
'order_id': 'str',
30+
'event_id': 'str'
2931
}
3032

31-
def __init__(self, event_name = None, event_time = None):
32-
# type: (str, int) -> None
33+
def __init__(self, event_name = None, event_time = None, order_id = None, event_id = None):
34+
# type: (str, int, str, str) -> None
3335

3436
"""Conversions API Original Event Data"""
3537
self._event_name = None
3638
self._event_time = None
39+
self._order_id = None
40+
self._event_id = None
3741

3842
if event_name is not None:
3943
self.event_name = event_name
4044
if event_time is not None:
4145
self.event_time = event_time
46+
if order_id is not None:
47+
self.order_id = order_id
48+
if event_id is not None:
49+
self.event_id = event_id
4250

4351
@property
4452
def event_name(self):
@@ -88,8 +96,59 @@ def event_time(self, event_time):
8896

8997
self._event_time = event_time
9098

99+
@property
100+
def order_id(self):
101+
"""Gets the order_id of original Event.
102+
103+
The order ID for this transaction as a string.
104+
105+
:return: The order_id of original Event.
106+
:rtype: str
107+
"""
108+
return self._order_id
109+
110+
@order_id.setter
111+
def order_id(self, order_id):
112+
"""Sets the order_id of original Event.
113+
114+
The order ID for this transaction as a string.
115+
116+
:param order_id: The order_id of original Event.
117+
:type: str
118+
:return self
119+
"""
120+
self._order_id = order_id
121+
122+
@property
123+
def event_id(self):
124+
"""Gets the event_id of original Event.
125+
126+
A unique string chosen by the advertiser.
127+
128+
:return: The event_id of original Event.
129+
:rtype: str
130+
"""
131+
return self._event_id
132+
133+
@event_id.setter
134+
def event_id(self, event_id):
135+
"""Sets the event_id of original Event.
136+
137+
A unique string chosen by the advertiser.
138+
139+
:param event_id: The event_id of original Event.
140+
:type: str
141+
:return self
142+
"""
143+
self._event_id = event_id
144+
91145
def normalize(self):
92-
normalized_payload = {'event_name': self.event_name, 'event_time': self.event_time }
146+
normalized_payload = {
147+
'event_name': self.event_name,
148+
'event_time': self.event_time,
149+
'order_id': self.order_id,
150+
'event_id': self.event_id,
151+
}
93152
normalized_payload = {k: v for k, v in normalized_payload.items() if v is not None}
94153
return normalized_payload
95154

facebook_business/adobjects/serverside/tests/attribution_data_test.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,21 @@
2121
from unittest import TestCase
2222

2323
from facebook_business.adobjects.serverside.attribution_data import AttributionData
24+
from facebook_business.adobjects.serverside.attribution_model import AttributionModel
2425

2526

2627
class AttributionDataTest(TestCase):
2728
def test_normalize(self):
2829
expected = {
29-
scope: 'click',
30-
visit_time: 12345,
31-
ad_id: '123',
32-
adset_id: '234',
33-
campaign_id: '456',
34-
attr_window: 7,
35-
attribution_share: 0.5,
36-
attribution_model: 'last_click',
30+
'scope': 'click',
31+
'visit_time': 12345,
32+
'ad_id': '123',
33+
'adset_id': '234',
34+
'campaign_id': '456',
35+
'attr_window': 7,
36+
'attribution_share': 0.5,
37+
'attribution_model': AttributionModel.LAST_CLICK,
38+
'attribution_value': 10.5,
3739
}
3840
attribution_data = AttributionData(
3941
scope=expected['scope'],
@@ -44,6 +46,7 @@ def test_normalize(self):
4446
attr_window=expected['attr_window'],
4547
attribution_share=expected['attribution_share'],
4648
attribution_model=expected['attribution_model'],
49+
attribution_value=expected['attribution_value'],
4750
)
4851

4952
self.assertEqual(attribution_data.normalize(), expected)

facebook_business/adobjects/serverside/tests/custom_data_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def test_normalize(self):
3333

3434
expected = {
3535
'value': 0.5,
36+
'net_revenue': 0.23,
3637
'currency': 'usd',
3738
'content_name': 'content-content1',
3839
'content_category': 'content-category2',
@@ -57,6 +58,7 @@ def test_normalize(self):
5758
}
5859
custom_data = CustomData(
5960
value=expected['value'],
61+
net_revenue=expected['net_revenue'],
6062
currency=expected['currency'],
6163
content_name=expected['content_name'],
6264
content_category=expected['content_category'],

facebook_business/adobjects/serverside/tests/original_event_data_test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,14 @@ def test_normalize(self):
2828
expected = {
2929
'event_name': 'event-name-1',
3030
'event_time': 123456,
31+
'order_id': 'order-id-1',
32+
'event_id': 'event-id-1',
3133
}
3234
original_event_data = OriginalEventData(
3335
event_name=expected['event_name'],
3436
event_time=expected['event_time'],
37+
order_id=expected['order_id'],
38+
event_id=expected['event_id'],
3539
)
3640

3741
self.assertEqual(original_event_data.normalize(), expected)

0 commit comments

Comments
 (0)