
PostHog NewEvent
CertifiedTrigger a flow when new PostHog events appear
PostHog NewEvent
Trigger a flow when new PostHog events appear
Polls the PostHog Query API (HogQL) for events that appeared since the previous poll, and starts one execution with the new events. Uses a personal API key and the numeric project ID, which are different from the project API key (phc_) of the other PostHog tasks: the personal key needs the Query Read permission, and host is the PostHog app host (https://us.posthog.com, https://eu.posthog.com or your self-hosted URL), not the ingestion host.
Events are read in order of their timestamp (the time the event happened, not the time PostHog received it), using the pair timestamp and uuid as a cursor stored in the namespace KV store, so that events sharing a timestamp are neither repeated nor skipped. The first poll only records the current time: events that happened before it are not returned. An event with a timestamp earlier than the cursor, such as a backdated one, is never returned. If more than maxEvents events are new, the oldest ones are returned and the others are returned by the following polls.
PostHog rate-limits its Query API per project (240 requests per minute and 2400 per hour, plus an hourly read budget), and does not support the Query API as a bulk export mechanism: this is why the default interval is five minutes. Keep it at PT5M or longer.
type: io.kestra.plugin.posthog.NewEventExamples
Start a flow for each batch of new user_signed_up events
id: react_to_posthog_event
namespace: company.analytics
triggers:
- id: on_new_signup_event
type: io.kestra.plugin.posthog.NewEvent
personalApiKey: "{{ secret('POSTHOG_PERSONAL_API_KEY') }}"
projectId: "{{ secret('POSTHOG_PROJECT_ID') }}"
host: "https://us.posthog.com"
eventName: user_signed_up
maxEvents: 100
interval: PT5M
tasks:
- id: handle_events
type: io.kestra.plugin.core.flow.EachParallel
value: "{{ trigger.events }}"
tasks:
- id: log_event
type: io.kestra.plugin.core.log.Log
message: "New {{ fromJson(taskrun.value).event }} event for {{ fromJson(taskrun.value).distinctId }} at {{ fromJson(taskrun.value).timestamp }}"
Properties
personalApiKey *string
PostHog personal API key
A personal API key (phx_) with the Query Read permission. This is not the project API key (phc_) used by the other PostHog tasks. Use a Kestra secret.
projectId *integerstring
PostHog project ID
The numeric ID of the PostHog project, as found in the project settings or in the URL of the PostHog app. Must be greater than 0.
allowConcurrent boolean
falseSpecifies whether a trigger is allowed to start a new execution even if a previous run is still in progress.
eventName string
Event name
Optional name of the events to watch, e.g. user_signed_up. By default, events with any name are returned.
host string
https://us.posthog.comPostHog app host
The PostHog app host: https://us.posthog.com (US Cloud), https://eu.posthog.com (EU Cloud) or the URL of a self-hosted instance. This is not the ingestion host (us.i.posthog.com) used by the other PostHog tasks.
interval string
PT5MdurationInterval between two polls
The interval between two polls of the PostHog Query API. Defaults to five minutes because of the PostHog rate limits: keep PT5M or longer.
maxEvents integerstring
100Maximum number of events per poll
The maximum number of events returned by a poll, between 1 and 50000. When more events are new, the oldest are returned first and the others by the following polls.
stopAfter array
CREATEDSUBMITTEDRUNNINGPAUSEDRESTARTEDKILLINGSUCCESSWARNINGFAILEDKILLEDCANCELLEDQUEUEDRETRYINGRETRIEDSKIPPEDBREAKPOINTRESUBMITTEDList of execution states after which a trigger should be stopped (a.k.a. disabled).
when string
trueA condition that determines whether the trigger should run.
A Pebble expression evaluated at trigger time. The trigger fires only when the expression evaluates to a truthy value (true, a non-empty string, a non-zero number). Use this to gate trigger execution on dynamic runtime values such as execution labels, flow variables, or environment conditions.
Outputs
count integer
Number of new events
The number of events in events.
events array
New events
The new events, from the oldest to the newest. Use {{ trigger.events }}.
io.kestra.plugin.posthog.NewEvent-Output-Event
Distinct ID
The distinct ID of the user that sent the event.
Event name
Event ID
The UUID of the event.
Properties
The properties of the event.
date-timeTimestamp
When the event happened, as reported by the client that sent it.