Capture
Auto-capture collection create/update/delete via hooks.
collections controls which collections participate and how. It accepts a
plain slug array as shorthand for "enable defaults", or a map for
per-collection control:
payloadPosthog({
apiKey: process.env.POSTHOG_API_KEY!,
collections: {
// shorthand: enable defaults for all three operations
posts: true,
// per-operation control, including a custom event name
orders: {
create: 'order_placed',
update: true,
delete: false, // don't capture deletes for this collection
},
},
capture: {
// Applies across every enabled collection unless a collection-level
// override takes precedence.
properties: ({ collection, doc, operation }) => ({
collection,
title: doc.title,
}),
eventName: ({ collection, operation }) =>
operation === 'delete' ? false : `payload:${collection}.${operation}`,
},
})Defaults
- Event name:
payload:{collection}.{operation}— e.g.payload:posts.create - Properties:
{ collection, id: doc.id } - distinctId: see distinctId resolution
Returning false from eventName (globally or per-collection) skips
capturing that operation entirely.
Groups
If a groups.mapper is configured, every captured event is
automatically tagged with $groups — no extra wiring needed here.