diff --git a/posthog/cdp/site_functions.py b/posthog/cdp/site_functions.py index f6ece18e28792..fa77c20a8f881 100644 --- a/posthog/cdp/site_functions.py +++ b/posthog/cdp/site_functions.py @@ -122,9 +122,13 @@ def get_transpiled_function(hog_function: HogFunction) -> str: callback(true); } - return { - processEvent: (globals) => processEvent(globals, posthog) + const response = {} + + if (processEvent) { + response.processEvent = (globals) => processEvent(globals, posthog) } + + return response } return { init: init };""" diff --git a/posthog/cdp/test/test_site_functions.py b/posthog/cdp/test/test_site_functions.py index 0b6c0bc1bb8a6..658b16ba41be0 100644 --- a/posthog/cdp/test/test_site_functions.py +++ b/posthog/cdp/test/test_site_functions.py @@ -98,9 +98,13 @@ def test_get_transpiled_function_basic(self): callback(true); } - return { - processEvent: (globals) => processEvent(globals, posthog) + const response = {} + + if (processEvent) { + response.processEvent = (globals) => processEvent(globals, posthog) } + + return response } return { init: init }; diff --git a/posthog/models/test/test_remote_config.py b/posthog/models/test/test_remote_config.py index f83b6fef5ea86..d06ec45dcdc69 100644 --- a/posthog/models/test/test_remote_config.py +++ b/posthog/models/test/test_remote_config.py @@ -747,9 +747,13 @@ def test_renders_js_including_site_functions(self): callback(true); } - return { - processEvent: (globals) => processEvent(globals, posthog) + const response = {} + + if (processEvent) { + response.processEvent = (globals) => processEvent(globals, posthog) } + + return response } return { init: init }; @@ -793,9 +797,13 @@ def test_renders_js_including_site_functions(self): callback(true); } - return { - processEvent: (globals) => processEvent(globals, posthog) + const response = {} + + if (processEvent) { + response.processEvent = (globals) => processEvent(globals, posthog) } + + return response } return { init: init };