Skip to Content

Audit API

⚡ 5 min read

The trackUserAction() method records actions for audit logs (method name is fixed; tag identifies the event). Use it for sensitive operations, compliance, and activity trails


trackUserAction()

Records a user action for audit logging. Supports severity levels, success/failure status, and optional metadata

transcodes.trackUserAction( event: { tag: string; severity?: 'low' | 'medium' | 'high'; status?: boolean; error?: string; metadata?: Record<string, unknown>; }, options?: { requireAuth?: boolean; webhookNotification?: boolean; } ): Promise<void>

Event Parameters

ParameterTypeRequiredDescription
tagstringYesTag identifying the action (e.g., ‘user:login’, ‘document:create’)
severity'low' | 'medium' | 'high'NoSeverity level. Default: 'low'
statusbooleanNoSuccess/failure. Default: true
errorstringNoError message when status: false
metadataRecord<string, unknown>NoAdditional metadata (e.g., { method: 'passkey' })

Options

ParameterTypeRequiredDescription
requireAuthbooleanNoIf true, opens login modal when user not authenticated. Default: true. Set false to skip the modal — the call then no-ops when unauthenticated (not logged anonymously)
webhookNotificationbooleanNoSend Slack webhook regardless of severity. Default: false

Examples

Basic usage

await transcodes.trackUserAction({ tag: 'user:login', metadata: { method: 'passkey' }, });

With severity and status

await transcodes.trackUserAction({ tag: 'document:delete', severity: 'high', status: true, metadata: { documentId: 'doc_123' }, });

Failed action with error

await transcodes.trackUserAction( { tag: 'payment:process', severity: 'high', status: false, error: 'Payment gateway timeout', metadata: { amount: 99.99 }, }, { webhookNotification: true } );

Require authentication

// Opens login modal if user not authenticated await transcodes.trackUserAction( { tag: 'sensitive:action', severity: 'medium' }, { requireAuth: true } );

Common Tags

Tag PatternExample Use Case
user:loginMember login event (example tag)
user:registerNew member registration (example)
user:logoutMember sign-out (example tag)
document:createDocument created
document:deleteDocument deleted
payment:*Payment-related actions

Last updated on