Skip to content

Commit

Permalink
add pageview to onedollar
Browse files Browse the repository at this point in the history
  • Loading branch information
guitavano committed Jan 27, 2025
1 parent 0246e5e commit 3f4e563
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion website/components/OneDollarStats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const snippet = () => {
// Flags and additional dimentions
const props: Record<string, string> = {};
const trackPageview = () =>
globalThis.window.trackCustomEvent?.("pageview", props);
globalThis.window.trackCustomEvent?.("PageView", props);
// Attach pushState and popState listeners
const originalPushState = history.pushState;
if (originalPushState) {
Expand All @@ -44,6 +44,22 @@ const snippet = () => {
// 2000 bytes limit
const truncate = (str: string) => `${str}`.slice(0, 990);

globalThis.window.DECO.events.subscribe((event) => {
if (!event || event.name !== "deco") {
return;
}
if (event.params) {
const { flags, page } = event.params;
if (Array.isArray(flags)) {
for (const flag of flags) {
props[flag.name] = truncate(flag.value.toString());
}
}
props["pageId"] = truncate(`${page.id}`);
}
trackPageview();
})();

globalThis.window.DECO.events.subscribe((event) => {
if (!event) {
return;
Expand Down

0 comments on commit 3f4e563

Please sign in to comment.