Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
Salakar committed Feb 24, 2024
1 parent cce4765 commit 59f23ca
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion website/src/pages/[owner]/[repository]/[...path].astro
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ if (response?.code === 'OK') {
if (import.meta.env.PROD) {
// Track the page request
await trackPageRequest(Astro.request);
await trackPageRequest(Astro.request, owner, repository);
// Set the cache headers - see https://vercel.com/docs/concepts/edge-network/caching
Astro.response.headers.set('Cache-Control', 's-maxage=1, stale-while-revalidate=59');
Expand Down
10 changes: 9 additions & 1 deletion website/src/plausible.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { getClientIp } from 'request-ip';

export async function trackPageRequest(request: Request): Promise<void> {
export async function trackPageRequest(
request: Request,
owner: string,
repository: string,
): Promise<void> {
try {
await fetch(`https://plausible.io/api/event`, {
method: 'POST',
Expand All @@ -14,6 +18,10 @@ export async function trackPageRequest(request: Request): Promise<void> {
name: 'pageview',
url: request.url,
domain: 'docs.page',
props: {
owner,
repository: `${owner}/${repository}`,
},
}),
});
} catch (e) {
Expand Down

0 comments on commit 59f23ca

Please sign in to comment.