Setu Recipes: reusable digital workers across every app.Browse templates

Integrations / PostHog

PostHog

Product analytics (US cloud): run HogQL queries, list events, persons and feature flags.

6 actions API key 6 read0 write Calls us.posthog.com

Connect

TypeScript
const conn = await setu.connections.initiate({ userId: "user_1", toolkit: "posthog" });
console.log(conn.connectUrl); // show this to your user
await conn.waitUntilActive();

Permissions requested

This toolkit uses a single credential and requests no scopes.

Actions

List eventsreadposthog.list_eventsList recent raw events of a project, optionally for one event name or person. Prefer run_hogql_query for anything analytic.
InputTypeDescription
project_idstringRequiredProject id
eventstringOptionalEvent name, e.g. $pageview
distinct_idstringOptionalOnly this person's distinct id
afterstringOptionalISO time: only events after this
beforestringOptionalISO time: only events before this
limitintegerOptionalPage size
TypeScript
await setu.execute({
  userId: "user_1",
  action: "posthog.list_events",
  input: {
    "project_id": "<project_id>"
  },
});
List feature flagsreadposthog.list_feature_flagsList a project's feature flags: id, key, name, whether active and rollout filters.
InputTypeDescription
limitintegerOptionalPage size
offsetintegerOptionalItems to skip
project_idstringRequiredProject id
searchstringOptionalSearch by key or name
activestringOptionalFilter on serving state
TypeScript
await setu.execute({
  userId: "user_1",
  action: "posthog.list_feature_flags",
  input: {
    "project_id": "<project_id>"
  },
});
List organizationsreadposthog.list_organizationsList the PostHog organizations the key can access. Organization ids are needed to list projects.
InputTypeDescription
limitintegerOptionalPage size
offsetintegerOptionalItems to skip
TypeScript
await setu.execute({
  userId: "user_1",
  action: "posthog.list_organizations",
  input: {},
});
List personsreadposthog.list_personsList or search the people tracked in a project by email, name or distinct id.
InputTypeDescription
limitintegerOptionalPage size
offsetintegerOptionalItems to skip
project_idstringRequiredProject id
searchstringOptionalSearch by email, name, person id or distinct id
emailstringOptionalExact email
distinct_idstringOptionalExact distinct id
TypeScript
await setu.execute({
  userId: "user_1",
  action: "posthog.list_persons",
  input: {
    "project_id": "<project_id>"
  },
});
List projectsreadposthog.list_projectsList the projects of a PostHog organization: numeric project id and name. The project id is used by every other action.
InputTypeDescription
limitintegerOptionalPage size
offsetintegerOptionalItems to skip
organization_idstringRequiredOrganization id (uuid)
TypeScript
await setu.execute({
  userId: "user_1",
  action: "posthog.list_projects",
  input: {
    "organization_id": "<organization_id>"
  },
});
Run HogQL queryreadposthog.run_hogql_queryRun a read-only HogQL (SQL-like) query against a project's analytics data, e.g. counts of events by day. Add your own LIMIT; without one at most 100 rows return.
InputTypeDescription
project_idstringRequiredProject id
querystringRequiredHogQL text, e.g. select event, count() from events group by event limit 20
namestringOptionalLabel for the query log
TypeScript
await setu.execute({
  userId: "user_1",
  action: "posthog.run_hogql_query",
  input: {
    "project_id": "<project_id>",
    "query": "<query>"
  },
});