diff --git a/index.test.ts b/index.test.ts index c3e5d5a..b6c13fa 100644 --- a/index.test.ts +++ b/index.test.ts @@ -38,7 +38,21 @@ describe("processEvent", () => { "http://www.google.com" ); }); - it.todo("should convert the current_url to lowercase"); + + it("should convert the current_url to lowercase", async () => { + const sourceEvent = buildPageViewEvent( + "http://www.GoOGle.com/WhatAreYouThinking" + ); + + const processedEvent = await processEvent(sourceEvent, getMeta()); + + console.log("processedEvent = ", processedEvent); + + expect(processedEvent?.properties?.current_url).toEqual( + "http://www.google.com/whatareyouthinking" + ); + }); + it.todo("should remove the trailing slash from the current_url"); it.todo("should preserve trailing id anchors"); it.todo("shouldn't modify events that don't have a current_url set"); diff --git a/index.ts b/index.ts index 9dd859e..f2082df 100644 --- a/index.ts +++ b/index.ts @@ -1,11 +1,18 @@ import { PluginEvent, PluginInput, PluginMeta } from "@posthog/plugin-scaffold"; +function normalizeUrl(url: string): string { + return url.toLowerCase().replace(/\/$/, ""); +} + export function processEvent( event: PluginEvent, meta: PluginMeta ) { - if (event.properties) { - event.properties["hello"] = "world"; + const current_url = event?.properties?.current_url; + if (event?.properties && current_url) { + const normalized_url = normalizeUrl(current_url); + event.properties.current_url = normalized_url; } + return event; }