Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

833 B
Raw Blame
import { PluginEvent } from '~/plugin-scaffold'

import { LegacyTransformationPluginMeta } from '../../types'

export function processEvent(event: PluginEvent, { config }: LegacyTransformationPluginMeta) {
    const { pattern, matchGroup, property, replacePattern, replaceKey, replaceValue } = config
    if (event.properties && typeof event.properties['$pathname'] === 'string') {
        const regexp = new RegExp(pattern)
        const match = event.properties['$pathname'].match(regexp)
        if (match) {
            event.properties[property] = match[matchGroup]
            if (replacePattern) {
                const replaceRegexp = new RegExp(replacePattern)
                event.properties[replaceKey] = event.properties['$pathname'].replace(replaceRegexp, replaceValue)
            }
        }
    }
    return event
}