From 0e15a447b18087ef1e4bbdd8e64b9e5345433bd7 Mon Sep 17 00:00:00 2001 From: Marcus Hof <13001502+MarconLP@users.noreply.github.com> Date: Tue, 29 Oct 2024 13:48:34 +0100 Subject: [PATCH 1/2] fix(cdp): fallback to hashing an empty string and filter out empty user data values (#25863) Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> --- .../templates/meta_ads/template_meta_ads.py | 37 ++++++++++++------- .../meta_ads/test_template_meta_ads.py | 5 ++- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/posthog/cdp/templates/meta_ads/template_meta_ads.py b/posthog/cdp/templates/meta_ads/template_meta_ads.py index 146166b14946d..0fb1631f90ea7 100644 --- a/posthog/cdp/templates/meta_ads/template_meta_ads.py +++ b/posthog/cdp/templates/meta_ads/template_meta_ads.py @@ -9,22 +9,31 @@ icon_url="/static/services/meta-ads.png", category=["Advertisement"], hog=""" +let body := { + 'data': [ + { + 'event_name': inputs.eventName, + 'event_time': inputs.eventTime, + 'action_source': inputs.actionSource, + 'user_data': {} + } + ], + 'access_token': inputs.accessToken +} + +for (let key, value in inputs.userData) { + // e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 is an empty string hashed + if (not empty(value) and value != 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855') { + body.data.1.user_data[key] := value + } +} + let res := fetch(f'https://graph.facebook.com/v21.0/{inputs.pixelId}/events', { 'method': 'POST', 'headers': { 'Content-Type': 'application/json', }, - 'body': { - 'data': [ - { - 'event_name': inputs.eventName, - 'event_time': inputs.eventTime, - 'action_source': inputs.actionSource, - 'user_data': inputs.userData - } - ], - 'access_token': inputs.accessToken - } + 'body': body }) if (res.status >= 400) { throw Error(f'Error from graph.facebook.com (status {res.status}): {res.body}') @@ -118,9 +127,9 @@ "label": "User data", "description": "A map that contains customer information data. See this page for options: https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/customer-information-parameters", "default": { - "em": "{sha256Hex(person.properties.email)}", - "fn": "{sha256Hex(person.properties.first_name)}", - "ln": "{sha256Hex(person.properties.last_name)}", + "em": "{sha256Hex(person.properties.email ?? '')}", + "fn": "{sha256Hex(person.properties.first_name ?? '')}", + "ln": "{sha256Hex(person.properties.last_name ?? '')}", }, "secret": False, "required": True, diff --git a/posthog/cdp/templates/meta_ads/test_template_meta_ads.py b/posthog/cdp/templates/meta_ads/test_template_meta_ads.py index 5d14328cec39d..df2405e1d026c 100644 --- a/posthog/cdp/templates/meta_ads/test_template_meta_ads.py +++ b/posthog/cdp/templates/meta_ads/test_template_meta_ads.py @@ -15,7 +15,10 @@ def _inputs(self, **kwargs): "eventName": "checkout", "eventTime": "1728812163", "actionSource": "website", - "userData": {"em": "3edfaed7454eedb3c72bad566901af8bfbed1181816dde6db91dfff0f0cffa98"}, + "userData": { + "em": "3edfaed7454eedb3c72bad566901af8bfbed1181816dde6db91dfff0f0cffa98", + "fn": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + }, } inputs.update(kwargs) return inputs From 483358dd1f9edc2c4a0fbda35c804a72913cb005 Mon Sep 17 00:00:00 2001 From: Marcus Hof <13001502+MarconLP@users.noreply.github.com> Date: Tue, 29 Oct 2024 14:05:12 +0100 Subject: [PATCH 2/2] fix(cdp): run once per person per interval - correct person id (#25869) --- .../scenes/pipeline/hogfunctions/filters/HogFunctionFilters.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/scenes/pipeline/hogfunctions/filters/HogFunctionFilters.tsx b/frontend/src/scenes/pipeline/hogfunctions/filters/HogFunctionFilters.tsx index 50bf6bad4f4df..9dee4c767cc5e 100644 --- a/frontend/src/scenes/pipeline/hogfunctions/filters/HogFunctionFilters.tsx +++ b/frontend/src/scenes/pipeline/hogfunctions/filters/HogFunctionFilters.tsx @@ -158,7 +158,7 @@ export function HogFunctionFilters(): JSX.Element { label: 'Run once per interval', }, { - value: '{person.uuid}', + value: '{person.id}', label: 'Run once per person per interval', }, ]}