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.

787 B
Raw Blame
import { URLSearchParams } from 'url'

import { PluginEvent } from '~/plugin-scaffold'

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

// Processes each event, optionally transforming it
export function processEvent(event: PluginEvent, { logger }: LegacyTransformationPluginMeta) {
    try {
        // Some events (such as $identify) don't have properties
        if (event.properties && event.properties.$current_url) {
            const url = new URL(event.properties.$current_url)
            const params = new URLSearchParams(url.searchParams)
            for (const [key, val] of params.entries()) {
                event.properties[`url_${key}`] = val
            }
        }
    } catch (e) {
        logger.error('Error parsing URL', e)
    }
    return event
}