Skip to content

Commit 9d83bd9

Browse files
committed
fix: custom events bloated values
1 parent 62b1c28 commit 9d83bd9

File tree

15 files changed

+171
-743
lines changed

15 files changed

+171
-743
lines changed

apps/api/src/query/builders/custom-events.ts

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ export const CustomEventsBuilders: Record<string, SimpleQueryConfig> = {
2929
ce.timestamp,
3030
ce.properties,
3131
-- Get context from events table using session_id
32-
e.path,
33-
e.country,
34-
e.device_type,
35-
e.browser_name,
36-
e.os_name,
37-
e.referrer,
38-
e.utm_source,
39-
e.utm_medium,
40-
e.utm_campaign
32+
any(e.path) as path,
33+
any(e.country) as country,
34+
any(e.device_type) as device_type,
35+
any(e.browser_name) as browser_name,
36+
any(e.os_name) as os_name,
37+
any(e.referrer) as referrer,
38+
any(e.utm_source) as utm_source,
39+
any(e.utm_medium) as utm_medium,
40+
any(e.utm_campaign) as utm_campaign
4141
FROM analytics.custom_events ce
4242
LEFT JOIN analytics.events e ON (
4343
ce.session_id = e.session_id
@@ -50,6 +50,12 @@ export const CustomEventsBuilders: Record<string, SimpleQueryConfig> = {
5050
AND ce.timestamp <= parseDateTimeBestEffort(concat({endDate:String}, ' 23:59:59'))
5151
AND ce.event_name != ''
5252
${combinedWhereClause}
53+
GROUP BY
54+
ce.event_name,
55+
ce.anonymous_id,
56+
ce.session_id,
57+
ce.timestamp,
58+
ce.properties
5359
)
5460
SELECT
5561
event_name as name,
@@ -120,15 +126,16 @@ export const CustomEventsBuilders: Record<string, SimpleQueryConfig> = {
120126
ce.timestamp,
121127
ce.properties,
122128
-- Get context from events table using session_id
123-
e.path,
124-
e.country,
125-
e.device_type,
126-
e.browser_name,
127-
e.os_name,
128-
e.referrer,
129-
e.utm_source,
130-
e.utm_medium,
131-
e.utm_campaign
129+
-- Use any() to pick one matching event and prevent duplicates
130+
any(e.path) as path,
131+
any(e.country) as country,
132+
any(e.device_type) as device_type,
133+
any(e.browser_name) as browser_name,
134+
any(e.os_name) as os_name,
135+
any(e.referrer) as referrer,
136+
any(e.utm_source) as utm_source,
137+
any(e.utm_medium) as utm_medium,
138+
any(e.utm_campaign) as utm_campaign
132139
FROM analytics.custom_events ce
133140
LEFT JOIN analytics.events e ON (
134141
ce.session_id = e.session_id
@@ -143,6 +150,12 @@ export const CustomEventsBuilders: Record<string, SimpleQueryConfig> = {
143150
AND ce.properties != '{}'
144151
AND isValidJSON(ce.properties)
145152
${combinedWhereClause}
153+
GROUP BY
154+
ce.event_name,
155+
ce.anonymous_id,
156+
ce.session_id,
157+
ce.timestamp,
158+
ce.properties
146159
)
147160
SELECT
148161
event_name as name,

apps/dashboard/app/(main)/websites/[id]/_components/shared/tracking-components.tsx

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -308,22 +308,12 @@ export function TrackingStatusCard({
308308
</div>
309309
<div className="flex flex-col gap-0.5">
310310
<span className="font-medium text-sm">
311-
{isSetup
312-
? integrationType === "vercel"
313-
? "Vercel Integration Active"
314-
: "Tracking Active"
315-
: integrationType === "vercel"
316-
? "Vercel Integration Ready"
317-
: "Tracking Not Setup"}
311+
{isSetup ? "Tracking Active" : "Tracking Not Setup"}
318312
</span>
319313
<span className="text-muted-foreground text-xs">
320314
{isSetup
321-
? integrationType === "vercel"
322-
? "Data is being collected via Vercel integration"
323-
: "Data is being collected successfully"
324-
: integrationType === "vercel"
325-
? "Environment variables configured, waiting for traffic"
326-
: "Install the tracking script to start collecting data"}
315+
? "Data is being collected successfully"
316+
: "Install the tracking script to start collecting data"}
327317
</span>
328318
</div>
329319
</div>

apps/dashboard/app/(main)/websites/[id]/_components/tabs/tracking-setup-tab.tsx

Lines changed: 18 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
trackingOptionsAtom,
1313
} from "@/stores/jotai/filterAtoms";
1414
import {
15-
CodeBlock,
1615
InfoSection,
1716
InstallationTabs,
1817
TrackingOptionsGrid,
@@ -23,11 +22,7 @@ import {
2322
BASIC_TRACKING_OPTIONS,
2423
COPY_SUCCESS_TIMEOUT,
2524
} from "../shared/tracking-constants";
26-
import {
27-
generateNpmCode,
28-
generateScriptTag,
29-
generateVercelNpmCode,
30-
} from "../utils/code-generators";
25+
import { generateNpmCode, generateScriptTag } from "../utils/code-generators";
3126

3227
import type { TrackingOptions, WebsiteDataTabProps } from "../utils/types";
3328

@@ -62,23 +57,11 @@ export function WebsiteTrackingSetupTab({ websiteId }: WebsiteDataTabProps) {
6257
const result = await refetchTrackingSetup();
6358

6459
if (result.data?.tracking_setup) {
65-
const integrationType = result.data.integration_type;
66-
if (integrationType === "vercel") {
67-
toast.success("Vercel integration active! Data is being collected.");
68-
} else {
69-
toast.success("Tracking setup correctly! Data is being collected.");
70-
}
60+
toast.success("Tracking setup correctly! Data is being collected.");
7161
} else {
72-
const integrationType = result.data?.integration_type;
73-
if (integrationType === "vercel") {
74-
toast.error(
75-
"Vercel integration detected but no events yet. Make sure your site is deployed and receiving traffic."
76-
);
77-
} else {
78-
toast.error(
79-
"Tracking not found. Please verify the script installation."
80-
);
81-
}
62+
toast.error(
63+
"Tracking not found. Please verify the script installation."
64+
);
8265
}
8366
} catch (error) {
8467
console.error("Failed to check tracking status:", error);
@@ -96,56 +79,19 @@ export function WebsiteTrackingSetupTab({ websiteId }: WebsiteDataTabProps) {
9679
/>
9780

9881
{/* Installation Instructions */}
99-
{trackingSetupData?.integration_type === "vercel" ? (
100-
<InfoSection title="Vercel Integration Setup">
101-
<div className="space-y-4">
102-
<p className="text-muted-foreground text-sm">
103-
Your website is integrated with Vercel - no manual setup required!
104-
</p>
105-
106-
<div className="rounded border bg-muted/30 p-3">
107-
<p className="font-medium text-sm">Automatic SDK Detection</p>
108-
<p className="text-muted-foreground text-xs leading-relaxed">
109-
The Databuddy SDK will automatically detect the{" "}
110-
<code className="rounded bg-muted px-1 py-0.5 font-mono text-xs">
111-
NEXT_PUBLIC_DATABUDDY_CLIENT_ID
112-
</code>{" "}
113-
environment variable set by your Vercel integration.
114-
</p>
115-
</div>
116-
117-
<div className="space-y-2">
118-
<p className="font-medium text-sm">Add the SDK to your app:</p>
119-
<CodeBlock
120-
code={generateVercelNpmCode(trackingOptions)}
121-
copied={copiedBlockId === "vercel-setup"}
122-
description="Add this to your root layout or _app.js file:"
123-
onCopy={() =>
124-
handleCopyCode(
125-
generateVercelNpmCode(trackingOptions),
126-
"vercel-setup",
127-
"Vercel setup code copied to clipboard!"
128-
)
129-
}
130-
/>
131-
</div>
132-
</div>
133-
</InfoSection>
134-
) : (
135-
<InfoSection title="Installation">
136-
<div className="space-y-4">
137-
<p className="text-muted-foreground text-sm">
138-
Choose your preferred installation method
139-
</p>
140-
<InstallationTabs
141-
copiedBlockId={copiedBlockId}
142-
npmCode={npmCode}
143-
onCopyCode={handleCopyCode}
144-
trackingCode={trackingCode}
145-
/>
146-
</div>
147-
</InfoSection>
148-
)}
82+
<InfoSection title="Installation">
83+
<div className="space-y-4">
84+
<p className="text-muted-foreground text-sm">
85+
Choose your preferred installation method
86+
</p>
87+
<InstallationTabs
88+
copiedBlockId={copiedBlockId}
89+
npmCode={npmCode}
90+
onCopyCode={handleCopyCode}
91+
trackingCode={trackingCode}
92+
/>
93+
</div>
94+
</InfoSection>
14995

15096
<InfoSection title="Configuration">
15197
<p className="mb-4 text-muted-foreground text-xs">

apps/dashboard/app/(main)/websites/[id]/_components/utils/code-generators.ts

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -124,49 +124,3 @@ export function generateNpmComponentCode(
124124
return `<Databuddy
125125
clientId="${websiteId}"${propsString}/>`;
126126
}
127-
128-
/**
129-
* Generate NPM code for Vercel integration (auto-detects clientId)
130-
*/
131-
export function generateVercelNpmCode(
132-
trackingOptions: TrackingOptions
133-
): string {
134-
const meaningfulProps = Object.entries(trackingOptions)
135-
.filter(([key, value]) => {
136-
const actualDefault =
137-
ACTUAL_LIBRARY_DEFAULTS[key as keyof TrackingOptions];
138-
if (value === actualDefault) {
139-
return false;
140-
}
141-
if (typeof value === "boolean" && !value && !actualDefault) {
142-
return false;
143-
}
144-
return true;
145-
})
146-
.map(([key, value]) => {
147-
if (typeof value === "boolean") {
148-
return ` ${key}={${value}}`;
149-
}
150-
if (typeof value === "string") {
151-
return ` ${key}="${value}"`;
152-
}
153-
return ` ${key}={${value}}`;
154-
});
155-
156-
const propsString =
157-
meaningfulProps.length > 0 ? `\n${meaningfulProps.join("\n")}\n ` : "";
158-
159-
return `import { Databuddy } from '@databuddy/sdk/react';
160-
161-
export default function RootLayout({ children }) {
162-
return (
163-
<html>
164-
<head>
165-
{/* No clientId needed - auto-detected from env vars */}
166-
<Databuddy${propsString}/>
167-
</head>
168-
<body>{children}</body>
169-
</html>
170-
);
171-
}`;
172-
}

apps/dashboard/hooks/use-integrations.ts

Lines changed: 0 additions & 50 deletions
This file was deleted.

packages/env/src/base.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ export const authEnvSchema = {
4444
* External service environment variables
4545
*/
4646
export const externalServiceEnvSchema = {
47-
VERCEL_CLIENT_ID: z.string(),
48-
VERCEL_CLIENT_SECRET: z.string(),
4947
RESEND_API_KEY: z.string(),
5048
} as const;
5149

packages/rpc/src/orpc.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ const os = createOS.$context<Context>();
2323
export const publicProcedure = os;
2424

2525
export const protectedProcedure = os.use(({ context, next }) => {
26+
if (context.user?.role === "ADMIN") {
27+
return next({
28+
context: {
29+
...context,
30+
session: context.session,
31+
user: context.user,
32+
},
33+
});
34+
}
35+
2636
if (!(context.user && context.session)) {
2737
throw new ORPCError("UNAUTHORIZED");
2838
}

packages/rpc/src/root.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { chatRouter } from "./routers/chat";
77
import { flagsRouter } from "./routers/flags";
88
import { funnelsRouter } from "./routers/funnels";
99
import { goalsRouter } from "./routers/goals";
10-
import { integrationsRouter } from "./routers/integrations";
1110
import { miniChartsRouter } from "./routers/mini-charts";
1211
import { organizationsRouter } from "./routers/organizations";
1312
import { preferencesRouter } from "./routers/preferences";
@@ -26,7 +25,6 @@ export const appRouter = {
2625
assistant: assistantRouter,
2726
chat: chatRouter,
2827
organizations: organizationsRouter,
29-
integrations: integrationsRouter,
3028
billing: billingRouter,
3129
};
3230

0 commit comments

Comments
 (0)