From 39ac7a960aba62056133bbc97b299658c3c527b4 Mon Sep 17 00:00:00 2001 From: Jerin Tomy Date: Tue, 2 May 2023 13:07:43 -0700 Subject: [PATCH] add 'advanced_measurement_table' arg to event Summary: Argument added to CAPI Graph endpoint in D28614990, reflecting the changes in the SDK as well Reviewed By: HanyanLiu Differential Revision: D43889230 fbshipit-source-id: 9c5e5f3df8ac30dc281421f66ea6d472fc2d857d --- CHANGELOG.md | 4 +- .../adobjects/serverside/event.py | 33 ++++++++++- .../serverside/tests/event_am_test.py | 56 +++++++++++++++++++ 3 files changed, 89 insertions(+), 4 deletions(-) create mode 100644 facebook_business/adobjects/serverside/tests/event_am_test.py diff --git a/CHANGELOG.md b/CHANGELOG.md index da9b83ab..20fa60a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file. ## Unreleased +### Added +- `advanced_measurement_table` field to Event for Conversion API + ## v11.0.0 @@ -121,4 +124,3 @@ All notable changes to this project will be documented in this file. ### Deprecated - `parent_id` in `AbstractCrudObject`. - Function `remote_create`, `remote_read`, `remote_update` and `remote_delete` for `AbstractCrudObject`. Check out our [recommended way](https://github.com/facebook/facebook-python-business-sdk#exploring-the-graph) to make API call with python SDK. - diff --git a/facebook_business/adobjects/serverside/event.py b/facebook_business/adobjects/serverside/event.py index 078e287c..5cf30a9d 100644 --- a/facebook_business/adobjects/serverside/event.py +++ b/facebook_business/adobjects/serverside/event.py @@ -39,13 +39,14 @@ class Event(object): 'data_processing_options_country': 'int', 'data_processing_options_state': 'int', 'action_source': 'ActionSource', + 'advanced_measurement_table': 'str', } def __init__(self, event_name = None, event_time = None, event_source_url = None, opt_out = None, event_id = None, user_data = None, custom_data = None, data_processing_options = None, data_processing_options_country = None, - data_processing_options_state = None, action_source = None): - # type: (str, int, str, bool, str, UserData, CustomData, list[str], int, int, ActionSource) -> None + data_processing_options_state = None, action_source = None, advanced_measurement_table = None): + # type: (str, int, str, bool, str, UserData, CustomData, list[str], int, int, ActionSource, str) -> None """Conversions API Event""" self._event_name = None @@ -59,6 +60,7 @@ def __init__(self, event_name = None, event_time = None, event_source_url = None self._data_processing_options_country = None self._data_processing_options_state = None self._action_source = None + self._advanced_measurement_table = None self.event_name = event_name self.event_time = event_time if event_source_url is not None: @@ -79,6 +81,8 @@ def __init__(self, event_name = None, event_time = None, event_source_url = None self.data_processing_options_state = data_processing_options_state if action_source is not None: self.action_source = action_source + if advanced_measurement_table is not None: + self.advanced_measurement_table = advanced_measurement_table @property def event_name(self): @@ -350,12 +354,35 @@ def action_source(self, action_source): self._action_source = action_source + @property + def advanced_measurement_table(self): + """Gets the advanced_measurement_table. + + Only used for the Advanced Measurement API in the Advanced Analytics product. + + :return: The advanced_measurement_table. + :rtype: str + """ + return self._advanced_measurement_table + + @advanced_measurement_table.setter + def advanced_measurement_table(self, advanced_measurement_table): + """Sets the advanced_measurement_table. + + Only used for the Advanced Measurement API in the Advanced Analytics product. + + :param advanced_measurement_table: The advanced_measurement_table. + :type: str + """ + self._advanced_measurement_table = advanced_measurement_table + def normalize(self): normalized_payload = {'event_name': self.event_name, 'event_time': self.event_time, 'event_source_url': self.event_source_url, 'opt_out': self.opt_out, 'event_id': self.event_id, 'data_processing_options': self.data_processing_options, 'data_processing_options_country' : self.data_processing_options_country, - 'data_processing_options_state': self.data_processing_options_state } + 'data_processing_options_state': self.data_processing_options_state, + 'advanced_measurement_table': self.advanced_measurement_table } if self.user_data is not None: normalized_payload['user_data'] = self.user_data.normalize() diff --git a/facebook_business/adobjects/serverside/tests/event_am_test.py b/facebook_business/adobjects/serverside/tests/event_am_test.py new file mode 100644 index 00000000..25775566 --- /dev/null +++ b/facebook_business/adobjects/serverside/tests/event_am_test.py @@ -0,0 +1,56 @@ +# Copyright 2014 Facebook, Inc. + +# You are hereby granted a non-exclusive, worldwide, royalty-free license to +# use, copy, modify, and distribute this software in source code or binary +# form for use in connection with the web services and APIs provided by +# Facebook. + +# As with any software that integrates with the Facebook platform, your use +# of this software is subject to the Facebook Developer Principles and +# Policies [http://developers.facebook.com/policy/]. This copyright notice +# shall be included in all copies or substantial portions of the software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. + +from unittest import TestCase + +from facebook_business import FacebookAdsApi +from facebook_business.adobjects.serverside.action_source import ActionSource +from facebook_business.adobjects.serverside.custom_data import CustomData +from facebook_business.adobjects.serverside.event import Event +from facebook_business.adobjects.serverside.user_data import UserData + + +class EventAmTest(TestCase): + def test_constructor(self): + event_name = 'custom' + event_time = 123 + user_data = UserData(email='eg@test.com') + custom_data = CustomData(custom_properties={'col_1': 'foo'}) + data_processing_options = ['AMO'] + advanced_measurement_table = 'test_am_table' + event = Event( + event_name=event_name, + event_time=event_time, + user_data=user_data, + custom_data=custom_data, + data_processing_options=data_processing_options, + action_source=None, + advanced_measurement_table=advanced_measurement_table + ) + expected_params = { + 'event_name': event_name, + 'event_time': event_time, + 'user_data': user_data.normalize(), + 'custom_data': custom_data.normalize(), + 'data_processing_options': data_processing_options, + 'advanced_measurement_table': advanced_measurement_table + } + + self.assertEqual(event.normalize(), expected_params)