Skip to content

Commit

Permalink
Confirm that urls are lowercased.
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkBennett authored Jun 17, 2022
1 parent c60f706 commit 1a0d596
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
16 changes: 15 additions & 1 deletion index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
11 changes: 9 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
@@ -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<PluginInput>
) {
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;
}

0 comments on commit 1a0d596

Please sign in to comment.