: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
import { PluginEvent } from '~/plugin-scaffold'
import { LegacyTransformationPluginMeta } from '../../types'
function normalizeUrl(url: string): string {
try {
const parsedUrl = new URL(url.toLocaleLowerCase())
parsedUrl.pathname = parsedUrl.pathname.replace(/\/$/, '')
return parsedUrl.toString()
} catch {
throw new Error(`Unable to normalize invalid URL: "${url}"`)
}
}
export function processEvent(event: PluginEvent, { logger }: LegacyTransformationPluginMeta) {
const $current_url = event?.properties?.$current_url
if (event?.properties && $current_url) {
const normalized_url = normalizeUrl($current_url)
event.properties.$current_url = normalized_url
logger.debug(`event.$current_url: "${$current_url}" normalized to "${normalized_url}"`)
}
return event
}