Skip to content

Commit 958245d

Browse files
authored
chore: aggregate www and apex domains, and fix duplicate key error (#4644)
1 parent 4be08ee commit 958245d

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

packages/fern-dashboard/src/app/services/posthog/analytics.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export class AnalyticsService {
5353
FROM events
5454
WHERE
5555
event = '$pageview'
56-
AND properties.$host = '${this.config.baseSiteUrl}'
56+
AND (properties.$host = '${this.config.baseSiteUrl}' OR properties.$host = 'www.${this.config.baseSiteUrl}')
5757
${whereClause}
5858
`;
5959

@@ -118,7 +118,7 @@ export class AnalyticsService {
118118
FROM events
119119
WHERE
120120
event = '$pageview'
121-
AND properties.$host = '${this.config.baseSiteUrl}'
121+
AND (properties.$host = '${this.config.baseSiteUrl}' OR properties.$host = 'www.${this.config.baseSiteUrl}')
122122
${whereClause}
123123
${groupByClause}
124124
ORDER BY date
@@ -184,7 +184,7 @@ export class AnalyticsService {
184184
FROM events
185185
WHERE
186186
event = '$pageview'
187-
AND properties.$host = '${this.config.baseSiteUrl}'
187+
AND (properties.$host = '${this.config.baseSiteUrl}' OR properties.$host = 'www.${this.config.baseSiteUrl}')
188188
${whereClause}
189189
${groupByClause}
190190
ORDER BY date
@@ -237,7 +237,7 @@ export class AnalyticsService {
237237
FROM events
238238
WHERE
239239
event = '$pageview'
240-
AND properties.$host = '${this.config.baseSiteUrl}'
240+
AND (properties.$host = '${this.config.baseSiteUrl}' OR properties.$host = 'www.${this.config.baseSiteUrl}')
241241
${whereClause}
242242
GROUP BY properties.$pathname
243243
ORDER BY ${orderBy} ${order.toUpperCase()}
@@ -276,7 +276,7 @@ export class AnalyticsService {
276276
FROM events
277277
WHERE
278278
event = '$pageview'
279-
AND properties.$host = '${this.config.baseSiteUrl}'
279+
AND (properties.$host = '${this.config.baseSiteUrl}' OR properties.$host = 'www.${this.config.baseSiteUrl}')
280280
AND properties.$geoip_country_code IS NOT NULL
281281
AND properties.$geoip_country_code != ''
282282
${whereClause}
@@ -449,7 +449,7 @@ export class AnalyticsService {
449449
FROM events
450450
WHERE
451451
event = '$pageview'
452-
AND properties.$host = '${this.config.baseSiteUrl}'
452+
AND (properties.$host = '${this.config.baseSiteUrl}' OR properties.$host = 'www.${this.config.baseSiteUrl}')
453453
${whereClause}
454454
GROUP BY channel
455455
ORDER BY ${orderBy} ${order.toUpperCase()}
@@ -495,7 +495,7 @@ export class AnalyticsService {
495495
FROM events
496496
WHERE
497497
event = '$pageview'
498-
AND properties.$host = '${this.config.baseSiteUrl}'
498+
AND (properties.$host = '${this.config.baseSiteUrl}' OR properties.$host = 'www.${this.config.baseSiteUrl}')
499499
AND properties.$referring_domain IS NOT NULL
500500
AND properties.$referring_domain != ''
501501
AND properties.$referring_domain != '$direct'
@@ -550,7 +550,7 @@ export class AnalyticsService {
550550
FROM events
551551
WHERE
552552
event = '$pageview'
553-
AND properties.$host = '${this.config.baseSiteUrl}'
553+
AND (properties.$host = '${this.config.baseSiteUrl}' OR properties.$host = 'www.${this.config.baseSiteUrl}')
554554
AND properties.$device_type IS NOT NULL
555555
AND properties.$device_type != ''
556556
-- Filter out malicious SQL injection attempts (case-insensitive)
@@ -698,7 +698,7 @@ export class AnalyticsService {
698698
FROM events
699699
WHERE
700700
event = 'not_found'
701-
AND properties.$host = '${this.config.baseSiteUrl}'
701+
AND (properties.$host = '${this.config.baseSiteUrl}' OR properties.$host = 'www.${this.config.baseSiteUrl}')
702702
AND properties.pathname IS NOT NULL
703703
AND properties.pathname != ''
704704
${whereClause}
@@ -726,15 +726,18 @@ export class AnalyticsService {
726726
const { whereClause } = this.buildDateAndFilterClause(options);
727727

728728
// Build host filter - if provided, filter by specific host, otherwise use baseSiteUrl
729-
const hostFilter = host ? `properties.$host = '${host}'` : `properties.$host = '${this.config.baseSiteUrl}'`;
729+
const hostFilter = host
730+
? `properties.$host = '${host}'`
731+
: `(properties.$host = '${this.config.baseSiteUrl}' OR properties.$host = 'www.${this.config.baseSiteUrl}')`;
730732

731733
const query = `
732734
SELECT
733735
properties.$host as host,
734736
properties.method as method,
735737
properties.endpointRoute as endpoint,
736738
properties.endpointName as name,
737-
COUNT(*) as count
739+
COUNT(*) as count,
740+
any(properties.$current_url) as currentUrl
738741
FROM events
739742
WHERE
740743
event = 'api_playground_request_sent'
@@ -752,7 +755,7 @@ export class AnalyticsService {
752755
LIMIT ${limit}
753756
`;
754757

755-
const response = await this.client.query<[string, string, string, string, number]>(query, {
758+
const response = await this.client.query<[string, string, string, string, number, string]>(query, {
756759
name: `api-explorer-requests-${this.getQueryNameSuffix(options)}-${host || this.config.baseSiteUrl}`
757760
});
758761

@@ -761,7 +764,8 @@ export class AnalyticsService {
761764
method: row[1] || "",
762765
endpoint: row[2] || "",
763766
name: row[3] || "",
764-
count: row[4]
767+
count: row[4],
768+
currentUrl: row[5] || ""
765769
}));
766770
}
767771

@@ -816,7 +820,7 @@ export class AnalyticsService {
816820
FROM events
817821
WHERE
818822
event = 'feedback_submitted'
819-
AND properties.$host = '${this.config.baseSiteUrl}'
823+
AND (properties.$host = '${this.config.baseSiteUrl}' OR properties.$host = 'www.${this.config.baseSiteUrl}')
820824
${whereClause}
821825
ORDER BY timestamp DESC
822826
LIMIT ${limit}

packages/fern-dashboard/src/app/services/posthog/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export interface APIExplorerEndpoint {
8080
endpoint: string;
8181
name: string;
8282
count: number;
83+
currentUrl: string;
8384
}
8485

8586
export interface APIExplorerOptions extends AnalyticsQueryOptions {

packages/fern-dashboard/src/components/web-analytics/Tables/APIExplorerRequestsTable.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export default function APIExplorerRequestsTable({
4848
key: "endpoint",
4949
label: "",
5050
width: "auto",
51-
render: (item: { method: string; endpoint: string; name: string }, _index: number) => {
51+
render: (item: { host: string; method: string; endpoint: string; name: string }, _index: number) => {
5252
const methodColor = METHOD_COLORS[item.method] || "blue";
5353

5454
// Map to specific hex colors
@@ -69,7 +69,7 @@ export default function APIExplorerRequestsTable({
6969
>
7070
{item.method}
7171
</span>
72-
<span className="relative z-10 truncate">{item.endpoint}</span>
72+
<span className="relative z-10 truncate">{item.name || item.endpoint}</span>
7373
</div>
7474
);
7575
}
@@ -96,7 +96,7 @@ export default function APIExplorerRequestsTable({
9696
isLoading={isLoading}
9797
error={error}
9898
columns={columns}
99-
getItemKey={(item) => `${item.method}-${item.endpoint}`}
99+
getItemKey={(item) => `${item.method}-${item.endpoint}-${item.name}`}
100100
showGradient={true}
101101
gradientKey="count"
102102
onSort={handleSort}

0 commit comments

Comments
 (0)