From eb6ab267694609bd310209f9880ffa55712d2f97 Mon Sep 17 00:00:00 2001 From: Marius Andra Date: Thu, 19 Sep 2024 16:10:02 +0200 Subject: [PATCH] feat(hog): standardize event fields (#24882) Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> --- .github/workflows/rust-docker-build.yml | 90 +++++++++---------- .../hogFunctionConfigurationLogic.tsx | 31 ++++--- frontend/src/types.ts | 7 +- plugin-server/src/cdp/types.ts | 15 +++- plugin-server/src/cdp/utils.ts | 13 ++- plugin-server/tests/cdp/hog-executor.test.ts | 7 +- .../test_template_activecampaign.py | 2 +- posthog/cdp/templates/avo/template_avo.py | 4 +- .../cdp/templates/avo/test_template_avo.py | 8 +- posthog/cdp/templates/braze/template_braze.py | 2 +- .../templates/braze/test_template_braze.py | 4 +- .../templates/clearbit/template_clearbit.py | 2 +- .../customerio/template_customerio.py | 11 ++- .../customerio/test_template_customerio.py | 6 +- .../cdp/templates/engage/template_engage.py | 6 +- posthog/cdp/templates/gleap/template_gleap.py | 4 +- .../templates/gleap/test_template_gleap.py | 2 +- .../template_google_cloud_storage.py | 2 +- .../test_template_google_cloud_storage.py | 4 +- .../google_pubsub/template_google_pubsub.py | 3 +- .../test_template_google_pubsub.py | 6 +- posthog/cdp/templates/helpers.py | 2 + .../templates/intercom/template_intercom.py | 2 +- posthog/cdp/templates/knock/template_knock.py | 7 +- .../templates/knock/test_knock_template.py | 6 +- posthog/cdp/templates/loops/template_loops.py | 2 +- .../templates/loops/test_template_loops.py | 4 +- .../cdp/templates/posthog/template_posthog.py | 3 +- .../posthog/test_template_posthog.py | 1 + .../rudderstack/template_rudderstack.py | 14 +-- .../rudderstack/test_template_rudderstack.py | 6 +- .../salesforce/template_salesforce.py | 3 + posthog/cdp/templates/slack/template_slack.py | 2 +- .../cdp/templates/zapier/template_zapier.py | 5 +- .../zendesk/test_template_zendesk.py | 2 +- 35 files changed, 156 insertions(+), 132 deletions(-) diff --git a/.github/workflows/rust-docker-build.yml b/.github/workflows/rust-docker-build.yml index 892b492bad6bf..c13879481c5d1 100644 --- a/.github/workflows/rust-docker-build.yml +++ b/.github/workflows/rust-docker-build.yml @@ -15,22 +15,22 @@ jobs: strategy: matrix: include: - - image: capture - dockerfile: ./rust/Dockerfile - - image: hook-api - dockerfile: ./rust/Dockerfile - - image: hook-janitor - dockerfile: ./rust/Dockerfile - - image: hook-worker - dockerfile: ./rust/Dockerfile - - image: hook-migrator - dockerfile: ./rust/Dockerfile.migrate-hooks - - image: cyclotron-janitor - dockerfile: ./rust/Dockerfile - - image: cyclotron-fetch - dockerfile: ./rust/Dockerfile - - image: property-defs-rs - dockerfile: ./rust/Dockerfile + - image: capture + dockerfile: ./rust/Dockerfile + - image: hook-api + dockerfile: ./rust/Dockerfile + - image: hook-janitor + dockerfile: ./rust/Dockerfile + - image: hook-worker + dockerfile: ./rust/Dockerfile + - image: hook-migrator + dockerfile: ./rust/Dockerfile.migrate-hooks + - image: cyclotron-janitor + dockerfile: ./rust/Dockerfile + - image: cyclotron-fetch + dockerfile: ./rust/Dockerfile + - image: property-defs-rs + dockerfile: ./rust/Dockerfile runs-on: depot-ubuntu-22.04-4 permissions: id-token: write # allow issuing OIDC tokens for this workflow run @@ -122,35 +122,35 @@ jobs: if: github.ref == 'refs/heads/master' strategy: matrix: - include: - - release: capture - values: - image: - sha: "${{ needs.build.outputs.capture_digest }}" - - release: capture-replay - values: - image: - sha: "${{ needs.build.outputs.capture_digest }}" - - release: cyclotron - values: - fetch_image: - sha: "${{ needs.build.outputs.cyclotron-fetch_digest }}" - janitor_image: - sha: "${{ needs.build.outputs.cyclotron-janitor_digest }}" - - release: property-defs-rs - values: - image: - sha: "${{ needs.build.outputs.property-defs-rs_digest }}" - - release: hoghooks - values: - api_image: - sha: "${{ needs.build.outputs.hook-api_digest }}" - janitor_image: - sha: "${{ needs.build.outputs.hook-janitor_digest }}" - worker_image: - sha: "${{ needs.build.outputs.hook-worker_digest }}" - migrator_image: - sha: "${{ needs.build.outputs.hook-migrator_digest }}" + include: + - release: capture + values: + image: + sha: '${{ needs.build.outputs.capture_digest }}' + - release: capture-replay + values: + image: + sha: '${{ needs.build.outputs.capture_digest }}' + - release: cyclotron + values: + fetch_image: + sha: '${{ needs.build.outputs.cyclotron-fetch_digest }}' + janitor_image: + sha: '${{ needs.build.outputs.cyclotron-janitor_digest }}' + - release: property-defs-rs + values: + image: + sha: '${{ needs.build.outputs.property-defs-rs_digest }}' + - release: hoghooks + values: + api_image: + sha: '${{ needs.build.outputs.hook-api_digest }}' + janitor_image: + sha: '${{ needs.build.outputs.hook-janitor_digest }}' + worker_image: + sha: '${{ needs.build.outputs.hook-worker_digest }}' + migrator_image: + sha: '${{ needs.build.outputs.hook-migrator_digest }}' steps: - name: get deployer token id: deployer diff --git a/frontend/src/scenes/pipeline/hogfunctions/hogFunctionConfigurationLogic.tsx b/frontend/src/scenes/pipeline/hogfunctions/hogFunctionConfigurationLogic.tsx index 7881b08e1816f..2d092c744e0fd 100644 --- a/frontend/src/scenes/pipeline/hogfunctions/hogFunctionConfigurationLogic.tsx +++ b/frontend/src/scenes/pipeline/hogfunctions/hogFunctionConfigurationLogic.tsx @@ -137,26 +137,28 @@ export function convertToHogFunctionInvocationGlobals( return { project: { id: team?.id ?? 0, + name: team?.name ?? 'Default project', url: projectUrl, }, event: { uuid: event.uuid ?? '', - name: event.event, // TODO: rename back to "event"? + event: event.event, distinct_id: event.distinct_id, - // TODO: add back elements_chain? + elements_chain: event.elements_chain ?? '', + properties: event.properties, timestamp: event.timestamp, + + name: event.event, url: `${projectUrl}/events/${encodeURIComponent(event.uuid ?? '')}/${encodeURIComponent(event.timestamp)}`, - properties: { - ...event.properties, - ...(event.elements_chain ? { $elements_chain: event.elements_chain } : {}), - }, }, person: { - uuid: person.uuid ?? person.id ?? '', // TODO: rename back to "id"? + id: person.uuid ?? person.id ?? '', + uuid: person.uuid ?? person.id ?? '', // TODO: remove + properties: person.properties, + name: asDisplay(person), url: `${projectUrl}/person/${encodeURIComponent(event.distinct_id)}`, - properties: person.properties, }, groups: {}, } @@ -465,21 +467,24 @@ export const hogFunctionConfigurationLogic = kea timestamp: string + name: string url: string } person?: { + id: string + properties: Record uuid: string name: string url: string - properties: Record } groups?: Record< string, diff --git a/plugin-server/src/cdp/types.ts b/plugin-server/src/cdp/types.ts index 8fcb7c2fe9e47..a86889134eb38 100644 --- a/plugin-server/src/cdp/types.ts +++ b/plugin-server/src/cdp/types.ts @@ -66,18 +66,27 @@ export type HogFunctionInvocationGlobals = { url: string } event: { + /* Database fields */ uuid: string - name: string + event: string distinct_id: string properties: Record + elements_chain: string timestamp: string + + /* Special fields in Hog */ + name: string url: string } person?: { - uuid: string + /** Database fields */ + id: string + properties: Record + + /** Special fields in Hog */ + uuid: string // TODO: remove? name: string url: string - properties: Record } groups?: Record } diff --git a/plugin-server/src/cdp/utils.ts b/plugin-server/src/cdp/utils.ts index 11a461f6c1ad0..1d1229dd2bcb6 100644 --- a/plugin-server/src/cdp/utils.ts +++ b/plugin-server/src/cdp/utils.ts @@ -50,10 +50,6 @@ export function convertToHogFunctionInvocationGlobals( siteUrl: string ): HogFunctionInvocationGlobals { const properties = event.properties ? JSON.parse(event.properties) : {} - if (event.elements_chain) { - properties['$elements_chain'] = event.elements_chain - } - const projectUrl = `${siteUrl}/project/${team.id}` let person: HogFunctionInvocationGlobals['person'] @@ -63,9 +59,10 @@ export function convertToHogFunctionInvocationGlobals( const personDisplayName = getPersonDisplayName(team, event.distinct_id, personProperties) person = { + id: event.person_id, + properties: personProperties, uuid: event.person_id, name: personDisplayName, - properties: personProperties, url: `${projectUrl}/person/${encodeURIComponent(event.distinct_id)}`, } } @@ -80,10 +77,12 @@ export function convertToHogFunctionInvocationGlobals( }, event: { uuid: event.uuid, - name: event.event!, + event: event.event!, + elements_chain: event.elements_chain, distinct_id: event.distinct_id, properties, timestamp: eventTimestamp, + name: event.event!, url: `${projectUrl}/events/${encodeURIComponent(event.uuid)}/${encodeURIComponent(eventTimestamp)}`, }, person, @@ -141,7 +140,7 @@ export function convertToHogFunctionFilterGlobal(globals: HogFunctionInvocationG } } - const elementsChain = globals.event.properties['$elements_chain'] + const elementsChain = globals.event.elements_chain ?? globals.event.properties['$elements_chain'] const response = { event: globals.event.name, elements_chain: elementsChain, diff --git a/plugin-server/tests/cdp/hog-executor.test.ts b/plugin-server/tests/cdp/hog-executor.test.ts index e917c09b563d9..d54da54657660 100644 --- a/plugin-server/tests/cdp/hog-executor.test.ts +++ b/plugin-server/tests/cdp/hog-executor.test.ts @@ -4,12 +4,7 @@ import { HogExecutor } from '../../src/cdp/hog-executor' import { HogFunctionManager } from '../../src/cdp/hog-function-manager' import { HogFunctionInvocation, HogFunctionType } from '../../src/cdp/types' import { HOG_EXAMPLES, HOG_FILTERS_EXAMPLES, HOG_INPUTS_EXAMPLES } from './examples' -import { - createHogExecutionGlobals, - createHogFunction, - createInvocation, - insertHogFunction as _insertHogFunction, -} from './fixtures' +import { createHogExecutionGlobals, createHogFunction, createInvocation } from './fixtures' const setupFetchResponse = (invocation: HogFunctionInvocation, options?: { status?: number; body?: string }): void => { invocation.queue = 'hog' diff --git a/posthog/cdp/templates/activecampaign/test_template_activecampaign.py b/posthog/cdp/templates/activecampaign/test_template_activecampaign.py index a8474496b56fb..c7730e9a70d91 100644 --- a/posthog/cdp/templates/activecampaign/test_template_activecampaign.py +++ b/posthog/cdp/templates/activecampaign/test_template_activecampaign.py @@ -25,7 +25,7 @@ def test_function_works(self): self.run_function( inputs=create_inputs(), globals={ - "event": {"name": "$identify"}, + "event": {"event": "$identify"}, }, ) diff --git a/posthog/cdp/templates/avo/template_avo.py b/posthog/cdp/templates/avo/template_avo.py index d9c1b4dde1277..7766ba07453b4 100644 --- a/posthog/cdp/templates/avo/template_avo.py +++ b/posthog/cdp/templates/avo/template_avo.py @@ -30,7 +30,7 @@ 'trackingId': '', 'samplingRate': 1, 'type': 'event', - 'eventName': event.name, + 'eventName': event.event, 'messageId': event.uuid, 'eventProperties': [] } @@ -157,7 +157,7 @@ def migrate(cls, obj): event_string = ", ".join(escape_hogql_string(event) for event in events_to_exclude) hf["filters"]["events"] = [ { - "id": "All events", + "id": None, "name": "All events", "type": "events", "order": 0, diff --git a/posthog/cdp/templates/avo/test_template_avo.py b/posthog/cdp/templates/avo/test_template_avo.py index fad1500c96031..34110faac1ecd 100644 --- a/posthog/cdp/templates/avo/test_template_avo.py +++ b/posthog/cdp/templates/avo/test_template_avo.py @@ -26,7 +26,7 @@ def test_function_works(self): "event": { "uuid": "0191c693-d93b-7516-b1e3-64ec33c96464", "distinct_id": "66e614bd-d9f2-491e-9e2c-eeab3090f72f", - "name": "sign up", + "event": "sign up", "properties": { "distinct_id": "66e614bd-d9f2-491e-9e2c-eeab3090f72f", "token": "phc_ex7Mnvi4DqeB6xSQoXU1UVPzAmUIpicMFKELQXGGTYQO", @@ -107,7 +107,7 @@ def test_automatic_type_mapping(self): self.run_function( inputs=self._inputs(), globals={ - "event": {"name": "sign up", "properties": {"test": property_value}}, + "event": {"event": "sign up", "properties": {"test": property_value}}, }, ) @@ -132,7 +132,7 @@ def test_property_filters(self): }, globals={ "event": { - "name": "sign up", + "event": "sign up", "properties": {"name": "Max", "company": "PostHog", "job": "Product Engineer"}, }, }, @@ -202,7 +202,7 @@ def test_exclude_events(self): assert template["filters"] == { "events": [ { - "id": "All events", + "id": None, "name": "All events", "type": "events", "order": 0, diff --git a/posthog/cdp/templates/braze/template_braze.py b/posthog/cdp/templates/braze/template_braze.py index a337357b6c45c..37bec6542c054 100644 --- a/posthog/cdp/templates/braze/template_braze.py +++ b/posthog/cdp/templates/braze/template_braze.py @@ -73,7 +73,7 @@ "default": { "properties": "{event.properties}", "external_id": "{event.distinct_id}", - "name": "{event.name}", + "name": "{event.event}", "time": "{event.timestamp}", }, "secret": False, diff --git a/posthog/cdp/templates/braze/test_template_braze.py b/posthog/cdp/templates/braze/test_template_braze.py index 1aa52d78269d5..fd109a6ad26df 100644 --- a/posthog/cdp/templates/braze/test_template_braze.py +++ b/posthog/cdp/templates/braze/test_template_braze.py @@ -14,7 +14,7 @@ def test_function_works(self): "apiKey": "my_secret_key", "attributes": {"email": "{person.properties.email}"}, "event": { - "name": "{event.name}", + "name": "{event.event}", "time": "{event.timestamp}", "properties": "{event.properties}", "external_id": "{event.distinct_id}", @@ -36,7 +36,7 @@ def test_function_works(self): "events": [ { "external_id": "{event.distinct_id}", - "name": "{event.name}", + "name": "{event.event}", "properties": "{event.properties}", "time": "{event.timestamp}", }, diff --git a/posthog/cdp/templates/clearbit/template_clearbit.py b/posthog/cdp/templates/clearbit/template_clearbit.py index 8b9ae6236b09c..d961d457e2f73 100644 --- a/posthog/cdp/templates/clearbit/template_clearbit.py +++ b/posthog/cdp/templates/clearbit/template_clearbit.py @@ -13,7 +13,7 @@ let api_key := inputs.api_key let email := inputs.email -if (empty(email) or event.name == '$set' or person.properties.clearbit_enriched) { +if (empty(email) or event.event == '$set' or person.properties.clearbit_enriched) { return false } diff --git a/posthog/cdp/templates/customerio/template_customerio.py b/posthog/cdp/templates/customerio/template_customerio.py index a9131f1bd47e0..23da61d0b3d9e 100644 --- a/posthog/cdp/templates/customerio/template_customerio.py +++ b/posthog/cdp/templates/customerio/template_customerio.py @@ -12,7 +12,7 @@ icon_url="/static/services/customerio.png", hog=""" let action := inputs.action -let name := event.name +let name := event.event let hasIdentifier := false @@ -28,13 +28,13 @@ } if (action == 'automatic') { - if (event.name in ('$identify', '$set')) { + if (event.event in ('$identify', '$set')) { action := 'identify' name := null - } else if (event.name == '$pageview') { + } else if (event.event == '$pageview') { action := 'page' name := event.properties.$current_url - } else if (event.name == '$screen') { + } else if (event.event == '$screen') { action := 'screen' name := event.properties.$screen_name } else { @@ -43,6 +43,9 @@ } let attributes := inputs.include_all_properties ? action == 'identify' ? person.properties : event.properties : {} +if (inputs.include_all_properties and action != 'identify' and not empty(event.elements_chain)) { + attributes['$elements_chain'] := event.elements_chain +} let timestamp := toInt(toUnixTimestamp(toDateTime(event.timestamp))) for (let key, value in inputs.attributes) { diff --git a/posthog/cdp/templates/customerio/test_template_customerio.py b/posthog/cdp/templates/customerio/test_template_customerio.py index 606590cd97d46..943c02684a09f 100644 --- a/posthog/cdp/templates/customerio/test_template_customerio.py +++ b/posthog/cdp/templates/customerio/test_template_customerio.py @@ -30,7 +30,7 @@ def test_function_works(self): self.run_function( inputs=create_inputs(), globals={ - "event": {"name": "$pageview", "properties": {"url": "https://example.com"}}, + "event": {"event": "$pageview", "properties": {"url": "https://example.com"}}, }, ) @@ -85,7 +85,7 @@ def test_automatic_action_mapping(self): self.run_function( inputs=create_inputs(), globals={ - "event": {"name": event_name, "properties": {"url": "https://example.com"}}, + "event": {"event": event_name, "properties": {"url": "https://example.com"}}, }, ) @@ -102,7 +102,7 @@ def test_enforced_action(self): self.run_function( inputs=create_inputs(action="event"), globals={ - "event": {"name": event_name, "properties": {"url": "https://example.com"}}, + "event": {"event": event_name, "properties": {"url": "https://example.com"}}, }, ) diff --git a/posthog/cdp/templates/engage/template_engage.py b/posthog/cdp/templates/engage/template_engage.py index f4e8ec90b50a6..5cebab402d99e 100644 --- a/posthog/cdp/templates/engage/template_engage.py +++ b/posthog/cdp/templates/engage/template_engage.py @@ -9,17 +9,13 @@ description="Send events to Engage.so", icon_url="/static/services/engage.png", hog=""" -let body := event - -body['event'] := event.name - fetch('https://api.engage.so/posthog', { 'method': 'POST', 'headers': { 'Authorization': f'Basic {base64Encode(f'{inputs.public_key}:{inputs.private_key}')}', 'Content-Type': 'application/json' }, - 'body': body + 'body': event }) """.strip(), inputs_schema=[ diff --git a/posthog/cdp/templates/gleap/template_gleap.py b/posthog/cdp/templates/gleap/template_gleap.py index a177ce42ce90c..cd709304b4789 100644 --- a/posthog/cdp/templates/gleap/template_gleap.py +++ b/posthog/cdp/templates/gleap/template_gleap.py @@ -8,7 +8,7 @@ icon_url="/static/services/gleap.png", hog=""" let action := inputs.action -let name := event.name +let name := event.event if (empty(inputs.userId)) { print('No User ID set. Skipping...') @@ -53,7 +53,7 @@ "type": "string", "label": "User ID", "description": "You can choose to fill this from an `email` property or an `id` property. If the value is empty nothing will be sent. See here for more information: https://docs.gleap.io/server/rest-api", - "default": "{person.uuid}", + "default": "{person.id}", "secret": False, "required": True, }, diff --git a/posthog/cdp/templates/gleap/test_template_gleap.py b/posthog/cdp/templates/gleap/test_template_gleap.py index 85769fad13fc1..941ed84725d63 100644 --- a/posthog/cdp/templates/gleap/test_template_gleap.py +++ b/posthog/cdp/templates/gleap/test_template_gleap.py @@ -24,7 +24,7 @@ def test_function_works(self): self.run_function( inputs=create_inputs(), globals={ - "event": {"name": "$identify"}, + "event": {"event": "$identify"}, }, ) diff --git a/posthog/cdp/templates/google_cloud_storage/template_google_cloud_storage.py b/posthog/cdp/templates/google_cloud_storage/template_google_cloud_storage.py index 7df92aae0797f..ef41e9dbacc44 100644 --- a/posthog/cdp/templates/google_cloud_storage/template_google_cloud_storage.py +++ b/posthog/cdp/templates/google_cloud_storage/template_google_cloud_storage.py @@ -103,7 +103,7 @@ def migrate(cls, obj): "bucketName": {"value": bucketName}, "payload": { "value": "uuid,event,properties,elements,people_set,people_set_once,distinct_id,team_id,ip,site_url,timestamp\n" - + "{event.uuid},{event.name},{jsonStringify(event.properties)},,,,{event.distinct_id},,,,{event.timestamp}" + + "{event.uuid},{event.event},{jsonStringify(event.properties)},{event.elements_chain},{jsonStringify(event.properties.$set)},{jsonStringify(event.properties.$set_once)},{event.distinct_id},,,,{event.timestamp}" }, "filename": { "value": "{toDate(event.timestamp)}/{replaceAll(replaceAll(replaceAll(toString(event.timestamp), '-', ''), ':', ''), 'T', '-')}-{event.uuid}.csv" diff --git a/posthog/cdp/templates/google_cloud_storage/test_template_google_cloud_storage.py b/posthog/cdp/templates/google_cloud_storage/test_template_google_cloud_storage.py index 268e0ed3b09fb..60b2cb4382cad 100644 --- a/posthog/cdp/templates/google_cloud_storage/test_template_google_cloud_storage.py +++ b/posthog/cdp/templates/google_cloud_storage/test_template_google_cloud_storage.py @@ -127,7 +127,7 @@ def test_integration(self, mock_credentials): "bucketName": {"value": "BUCKET_NAME"}, "payload": { "value": "uuid,event,properties,elements,people_set,people_set_once,distinct_id,team_id,ip,site_url,timestamp\n" - + "{event.uuid},{event.name},{jsonStringify(event.properties)},,,,{event.distinct_id},,,,{event.timestamp}" + + "{event.uuid},{event.event},{jsonStringify(event.properties)},{event.elements_chain},{jsonStringify(event.properties.$set)},{jsonStringify(event.properties.$set_once)},{event.distinct_id},,,,{event.timestamp}" }, "filename": { "value": "{toDate(event.timestamp)}/{replaceAll(replaceAll(replaceAll(toString(event.timestamp), '-', ''), ':', ''), 'T', '-')}-{event.uuid}.csv" @@ -172,7 +172,7 @@ def test_ignore_events(self, mock_credentials): "bucketName": {"value": "BUCKET_NAME"}, "payload": { "value": "uuid,event,properties,elements,people_set,people_set_once,distinct_id,team_id,ip,site_url,timestamp\n" - + "{event.uuid},{event.name},{jsonStringify(event.properties)},,,,{event.distinct_id},,,,{event.timestamp}" + + "{event.uuid},{event.event},{jsonStringify(event.properties)},{event.elements_chain},{jsonStringify(event.properties.$set)},{jsonStringify(event.properties.$set_once)},{event.distinct_id},,,,{event.timestamp}" }, "filename": { "value": "{toDate(event.timestamp)}/{replaceAll(replaceAll(replaceAll(toString(event.timestamp), '-', ''), ':', ''), 'T', '-')}-{event.uuid}.csv" diff --git a/posthog/cdp/templates/google_pubsub/template_google_pubsub.py b/posthog/cdp/templates/google_pubsub/template_google_pubsub.py index 022b3bb483236..c32fd3f7980f6 100644 --- a/posthog/cdp/templates/google_pubsub/template_google_pubsub.py +++ b/posthog/cdp/templates/google_pubsub/template_google_pubsub.py @@ -109,8 +109,9 @@ def migrate(cls, obj): "topicId": {"value": topicId}, "payload": { "value": { - "event": "{event.name}", + "event": "{event.event}", "distinct_id": "{event.distinct_id}", + "elements_chain": "{event.elements_chain}", "timestamp": "{event.timestamp}", "uuid": "{event.uuid}", "properties": "{event.properties}", diff --git a/posthog/cdp/templates/google_pubsub/test_template_google_pubsub.py b/posthog/cdp/templates/google_pubsub/test_template_google_pubsub.py index 077cdeae5d348..6aff353b9762b 100644 --- a/posthog/cdp/templates/google_pubsub/test_template_google_pubsub.py +++ b/posthog/cdp/templates/google_pubsub/test_template_google_pubsub.py @@ -127,7 +127,8 @@ def test_integration(self, mock_credentials): "topicId": {"value": "TOPIC_ID"}, "payload": { "value": { - "event": "{event.name}", + "event": "{event.event}", + "elements_chain": "{event.elements_chain}", "distinct_id": "{event.distinct_id}", "timestamp": "{event.timestamp}", "uuid": "{event.uuid}", @@ -177,7 +178,8 @@ def test_ignore_events(self, mock_credentials): "topicId": {"value": "TOPIC_ID"}, "payload": { "value": { - "event": "{event.name}", + "event": "{event.event}", + "elements_chain": "{event.elements_chain}", "distinct_id": "{event.distinct_id}", "timestamp": "{event.timestamp}", "uuid": "{event.uuid}", diff --git a/posthog/cdp/templates/helpers.py b/posthog/cdp/templates/helpers.py index 2dd77baaabb94..093c6ecbdb4ca 100644 --- a/posthog/cdp/templates/helpers.py +++ b/posthog/cdp/templates/helpers.py @@ -45,10 +45,12 @@ def createHogGlobals(self, globals=None) -> dict: data = { "event": { "uuid": "event-id", + "event": "event-name", "name": "event-name", "distinct_id": "distinct-id", "properties": {"$current_url": "https://example.com"}, "timestamp": "2024-01-01T00:00:00Z", + "elements_chain": "", }, "person": {"id": "person-id", "properties": {"email": "example@posthog.com"}}, "source": {"url": "https://us.posthog.com/hog_functions/1234"}, diff --git a/posthog/cdp/templates/intercom/template_intercom.py b/posthog/cdp/templates/intercom/template_intercom.py index fd97f2605759f..1690cb371dc8c 100644 --- a/posthog/cdp/templates/intercom/template_intercom.py +++ b/posthog/cdp/templates/intercom/template_intercom.py @@ -23,7 +23,7 @@ 'Accept': 'application/json' }, 'body': { - 'event_name': event.name, + 'event_name': event.event, 'created_at': toInt(toUnixTimestamp(toDateTime(event.timestamp))), 'email': inputs.email, 'id': event.distinct_id, diff --git a/posthog/cdp/templates/knock/template_knock.py b/posthog/cdp/templates/knock/template_knock.py index 8259644383f2d..c026f9c3dd8dd 100644 --- a/posthog/cdp/templates/knock/template_knock.py +++ b/posthog/cdp/templates/knock/template_knock.py @@ -14,12 +14,15 @@ let body := { 'type': 'track', - 'event': event.name, + 'event': event.event, 'userId': inputs.userId, 'properties': inputs.include_all_properties ? event.properties : {}, 'messageId': event.uuid, 'timestamp': event.timestamp } +if (inputs.include_all_properties and not empty(event.elements_chain)) { + body['properties']['$elements_chain'] := event.elements_chain +} for (let key, value in inputs.attributes) { if (not empty(value)) { @@ -53,7 +56,7 @@ "type": "string", "label": "User ID", "description": "You can choose to fill this from an `email` property or an `id` property. If the value is empty nothing will be sent. See here for more information: https://docs.gleap.io/server/rest-api", - "default": "{person.uuid}", + "default": "{person.id}", "secret": False, "required": True, }, diff --git a/posthog/cdp/templates/knock/test_knock_template.py b/posthog/cdp/templates/knock/test_knock_template.py index a10562a60164a..d7d70b948ac5c 100644 --- a/posthog/cdp/templates/knock/test_knock_template.py +++ b/posthog/cdp/templates/knock/test_knock_template.py @@ -27,7 +27,7 @@ def test_function_works(self): "event": { "uuid": "9d67cc3f-edf7-490d-b311-f03c21c64caf", "distinct_id": "8b9c729c-c59b-4c39-b5a6-af9fa1233054", - "name": "$pageview", + "event": "$pageview", "timestamp": "2024-09-16T16:11:48.577Z", "url": "http://localhost:8000/project/1/events/", "properties": { @@ -67,7 +67,7 @@ def test_body_includes_all_properties_if_set(self): "event": { "uuid": "9d67cc3f-edf7-490d-b311-f03c21c64caf", "distinct_id": "8b9c729c-c59b-4c39-b5a6-af9fa1233054", - "name": "$pageview", + "event": "$pageview", "timestamp": "2024-09-16T16:11:48.577Z", "url": "http://localhost:8000/project/1/events/", "properties": { @@ -87,7 +87,7 @@ def test_body_includes_all_properties_if_set(self): "event": { "uuid": "9d67cc3f-edf7-490d-b311-f03c21c64caf", "distinct_id": "8b9c729c-c59b-4c39-b5a6-af9fa1233054", - "name": "$pageview", + "event": "$pageview", "timestamp": "2024-09-16T16:11:48.577Z", "url": "http://localhost:8000/project/1/events/", "properties": { diff --git a/posthog/cdp/templates/loops/template_loops.py b/posthog/cdp/templates/loops/template_loops.py index 3b9d68b08573c..3ddba8ee5f92a 100644 --- a/posthog/cdp/templates/loops/template_loops.py +++ b/posthog/cdp/templates/loops/template_loops.py @@ -13,7 +13,7 @@ let payload := { 'userId': event.distinct_id, - 'eventName': event.name == '$set' ? '$identify' : event.name, + 'eventName': event.event == '$set' ? '$identify' : event.event, 'email': person.properties.email } for (let key, value in person.properties) { diff --git a/posthog/cdp/templates/loops/test_template_loops.py b/posthog/cdp/templates/loops/test_template_loops.py index c6d48b5228b14..3630909cd036d 100644 --- a/posthog/cdp/templates/loops/test_template_loops.py +++ b/posthog/cdp/templates/loops/test_template_loops.py @@ -15,7 +15,7 @@ def test_function_works(self): self.run_function( inputs=self._inputs(), globals={ - "event": {"distinct_id": "66e614bd-d9f2-491e-9e2c-eeab3090f72f", "name": "$pageview"}, + "event": {"distinct_id": "66e614bd-d9f2-491e-9e2c-eeab3090f72f", "event": "$pageview"}, "person": { "properties": {"email": "max@posthog.com", "name": "Max", "company": "PostHog"}, }, @@ -54,7 +54,7 @@ def test_automatic_action_mapping(self): self.run_function( inputs=self._inputs(), globals={ - "event": {"name": event_name, "properties": {"url": "https://example.com", "$browser": "Chrome"}}, + "event": {"event": event_name, "properties": {"url": "https://example.com", "$browser": "Chrome"}}, }, ) diff --git a/posthog/cdp/templates/posthog/template_posthog.py b/posthog/cdp/templates/posthog/template_posthog.py index 394a8e1b7450b..b600b17e3bc4a 100644 --- a/posthog/cdp/templates/posthog/template_posthog.py +++ b/posthog/cdp/templates/posthog/template_posthog.py @@ -28,9 +28,10 @@ }, 'body': { 'token': token, - 'event': event.name, + 'event': event.event, 'timestamp': event.timestamp, 'distinct_id': event.distinct_id, + 'elements_chain': event.elements_chain, 'properties': properties } }) diff --git a/posthog/cdp/templates/posthog/test_template_posthog.py b/posthog/cdp/templates/posthog/test_template_posthog.py index 547b417227c94..47347870657bb 100644 --- a/posthog/cdp/templates/posthog/test_template_posthog.py +++ b/posthog/cdp/templates/posthog/test_template_posthog.py @@ -27,6 +27,7 @@ def test_function_works(self): "headers": {"Content-Type": "application/json"}, "body": { "token": "TOKEN", + "elements_chain": "", "event": "event-name", "timestamp": "2024-01-01T00:00:00Z", "distinct_id": "distinct-id", diff --git a/posthog/cdp/templates/rudderstack/template_rudderstack.py b/posthog/cdp/templates/rudderstack/template_rudderstack.py index 81e1c49a731dd..59c47f5937ee5 100644 --- a/posthog/cdp/templates/rudderstack/template_rudderstack.py +++ b/posthog/cdp/templates/rudderstack/template_rudderstack.py @@ -48,15 +48,15 @@ if (not empty(inputs.identifier)) rudderPayload.userId := inputs.identifier if (not empty(event.properties.$anon_distinct_id ?? event.properties.$device_id ?? event.properties.distinct_id)) rudderPayload.anonymousId := event.properties.$anon_distinct_id ?? event.properties.$device_id ?? event.properties.distinct_id - if (event.name in ('$identify', '$set')) { + if (event.event in ('$identify', '$set')) { rudderPayload.type := 'identify' if (not empty(event.properties.$set)) rudderPayload.context.trait := event.properties.$set if (not empty(event.properties.$set)) rudderPayload.traits := event.properties.$set - } else if (event.name == '$create_alias') { + } else if (event.event == '$create_alias') { rudderPayload.type := 'alias' if (not empty(event.properties.alias)) rudderPayload.userId := event.properties.alias if (not empty(event.distinct_id)) rudderPayload.previousId := event.distinct_id - } else if (event.name == '$pageview') { + } else if (event.event == '$pageview') { rudderPayload.type := 'page' if (not empty(event.properties.name)) rudderPayload.name := event.properties.name if (not empty(event.properties.$host)) rudderPayload.properties.host := event.properties.$host @@ -66,12 +66,12 @@ if (not empty(event.properties.$initial_referrer)) rudderPayload.properties.initial_referrer := event.properties.$initial_referrer if (not empty(event.properties.$referring_domain)) rudderPayload.properties.referring_domain := event.properties.$referring_domain if (not empty(event.properties.$initial_referring_domain)) rudderPayload.properties.initial_referring_domain := event.properties.$initial_referring_domain - } else if (event.name == '$autocapture') { + } else if (event.event == '$autocapture') { rudderPayload.type := 'track' if (not empty(event.properties.$event_type)) rudderPayload.event := event.properties.$event_type } else { rudderPayload.type := 'track' - if (not empty(event.name)) rudderPayload.event := event.name + if (not empty(event.event)) rudderPayload.event := event.event } for (let key, value in event.properties) { @@ -117,7 +117,7 @@ "key": "identifier", "type": "string", "label": "Identifier", - "default": "{person.uuid}", + "default": "{person.id}", "secret": False, "required": True, }, @@ -138,7 +138,7 @@ def migrate(cls, obj): hf["inputs"] = { "host": {"value": host}, "token": {"value": token}, - "identifier": {"value": "{event.properties.$user_id ?? event.distinct_id ?? person.uuid}"}, + "identifier": {"value": "{event.properties.$user_id ?? event.distinct_id ?? person.id}"}, } hf["filters"] = {} diff --git a/posthog/cdp/templates/rudderstack/test_template_rudderstack.py b/posthog/cdp/templates/rudderstack/test_template_rudderstack.py index 85d5ecf1f6dbe..907843cf629e9 100644 --- a/posthog/cdp/templates/rudderstack/test_template_rudderstack.py +++ b/posthog/cdp/templates/rudderstack/test_template_rudderstack.py @@ -29,7 +29,7 @@ def test_function_works(self): "uuid": "96a04bdc-6021-4120-a3e3-f1988f59ba5f", "timestamp": "2024-08-29T13:40:22.713Z", "distinct_id": "85bcd2e4-d10d-4a99-9dc8-43789b7226a1", - "name": "$pageview", + "event": "$pageview", "properties": {"$current_url": "https://example.com", "$browser": "Chrome"}, }, "person": {"uuid": "a08ff8e1-a5ee-49cc-99e9-564e455c33f0"}, @@ -88,7 +88,7 @@ def test_automatic_action_mapping(self): self.run_function( inputs=self._inputs(), globals={ - "event": {"name": event_name, "properties": {"url": "https://example.com", "$browser": "Chrome"}}, + "event": {"event": event_name, "properties": {"url": "https://example.com", "$browser": "Chrome"}}, }, ) @@ -111,7 +111,7 @@ def test_default_config(self): { "host": {"value": "us.i.example.com"}, "token": {"value": "ignored"}, - "identifier": {"value": "{event.properties.$user_id ?? event.distinct_id ?? person.uuid}"}, + "identifier": {"value": "{event.properties.$user_id ?? event.distinct_id ?? person.id}"}, } ) assert template["filters"] == {} diff --git a/posthog/cdp/templates/salesforce/template_salesforce.py b/posthog/cdp/templates/salesforce/template_salesforce.py index 15b0f1c0c5777..201d39075a403 100644 --- a/posthog/cdp/templates/salesforce/template_salesforce.py +++ b/posthog/cdp/templates/salesforce/template_salesforce.py @@ -30,6 +30,9 @@ let getPayload := () -> { let properties := {} if (inputs.include_all_event_properties) { + if (not empty(event.elements_chain)) { + properties['$elements_chain'] := event.elements_chain + } for (let key, value in event.properties) { properties[key] := value } diff --git a/posthog/cdp/templates/slack/template_slack.py b/posthog/cdp/templates/slack/template_slack.py index 3158d82707958..e739859a8407b 100644 --- a/posthog/cdp/templates/slack/template_slack.py +++ b/posthog/cdp/templates/slack/template_slack.py @@ -69,7 +69,7 @@ "default": [ { "text": { - "text": "*{person.name}* triggered event: '{event.name}'", + "text": "*{person.name}* triggered event: '{event.event}'", "type": "mrkdwn", }, "type": "section", diff --git a/posthog/cdp/templates/zapier/template_zapier.py b/posthog/cdp/templates/zapier/template_zapier.py index 8203fefb2dc56..26228c64d676f 100644 --- a/posthog/cdp/templates/zapier/template_zapier.py +++ b/posthog/cdp/templates/zapier/template_zapier.py @@ -39,12 +39,13 @@ }, "data": { "eventUuid": "{event.uuid}", - "event": "{event.name}", + "event": "{event.event}", "teamId": "{project.id}", "distinctId": "{event.distinct_id}", "properties": "{event.properties}", + "elementsChain": "{event.elementsChain}", "timestamp": "{event.timestamp}", - "person": {"uuid": "{person.uuid}", "properties": "{person.properties}"}, + "person": {"uuid": "{person.id}", "properties": "{person.properties}"}, }, }, "secret": False, diff --git a/posthog/cdp/templates/zendesk/test_template_zendesk.py b/posthog/cdp/templates/zendesk/test_template_zendesk.py index 02a6c21e8e99f..ec0ffc49dd696 100644 --- a/posthog/cdp/templates/zendesk/test_template_zendesk.py +++ b/posthog/cdp/templates/zendesk/test_template_zendesk.py @@ -26,7 +26,7 @@ def test_function_works(self): self.run_function( inputs=create_inputs(), globals={ - "event": {"name": "$identify"}, + "event": {"event": "$identify"}, }, )