Skip to content

Commit 17bc227

Browse files
authored
Add google analytics to 404 pages so they can be tracked with additional details (#1852)
* Add google analytics to 404 pages so they can be tracked with additional details * Removed require wrapper in prettier config. No longer needed in V3 and can sometimes cause problems for prettier IDE extensions
1 parent 534fc75 commit 17bc227

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

.prettierrc.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ const config = require('@theguild/prettier-config');
22

33
module.exports = {
44
...config,
5-
plugins: [...config.plugins, require('prettier-plugin-tailwindcss')],
5+
plugins: [...config.plugins, 'prettier-plugin-tailwindcss'],
66
};

packages/website-router/src/routing.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ async function handleErrorResponse(options: {
99
endpoint: string;
1010
cfFetchCacheTtl: number;
1111
fallbackRoute: RewriteRecord;
12+
manipulateResponse: ManipulateResponseFn;
1213
}) {
1314
const requestedEndpoint = options.request.url;
1415

@@ -64,10 +65,15 @@ async function handleErrorResponse(options: {
6465
},
6566
});
6667

67-
return new Response(errorResponseContent.body, {
68-
status: options.response.status,
69-
headers: errorResponseContent.headers,
70-
});
68+
// Inject analytics and other HTMLRewriter handlers
69+
const rewrittenNotFound = await options.manipulateResponse(
70+
options.fallbackRoute,
71+
new Response(errorResponseContent.body, {
72+
status: options.response.status,
73+
headers: errorResponseContent.headers,
74+
}),
75+
);
76+
return rewrittenNotFound;
7177
}
7278

7379
return options.response;
@@ -197,6 +203,7 @@ export async function handleRewrite(options: {
197203
response: freshResponse,
198204
cfFetchCacheTtl: options.cfFetchCacheTtl,
199205
fallbackRoute: options.fallbackRoute,
206+
manipulateResponse: options.manipulateResponse,
200207
});
201208
}
202209

0 commit comments

Comments
 (0)