Skip to content

Commit

Permalink
add 'advanced_measurement_table' arg to event
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jtomy22912 authored and facebook-github-bot committed May 2, 2023
1 parent 221390e commit 39ac7a9
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 4 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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.

33 changes: 30 additions & 3 deletions facebook_business/adobjects/serverside/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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):
Expand Down Expand Up @@ -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()
Expand Down
56 changes: 56 additions & 0 deletions facebook_business/adobjects/serverside/tests/event_am_test.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 39ac7a9

Please sign in to comment.