diff --git a/packages/gitbook/src/components/PageBody/PageBody.tsx b/packages/gitbook/src/components/PageBody/PageBody.tsx
index 99eccccf7..c5aaf6f1b 100644
--- a/packages/gitbook/src/components/PageBody/PageBody.tsx
+++ b/packages/gitbook/src/components/PageBody/PageBody.tsx
@@ -147,12 +147,7 @@ export function PageBody(props: {
{shouldTrackPageViews() ? (
-
+
) : null}
>
);
diff --git a/packages/gitbook/src/components/PageBody/TrackPageView.tsx b/packages/gitbook/src/components/PageBody/TrackPageView.tsx
index 772bdacf3..16b6dfddb 100644
--- a/packages/gitbook/src/components/PageBody/TrackPageView.tsx
+++ b/packages/gitbook/src/components/PageBody/TrackPageView.tsx
@@ -1,6 +1,6 @@
'use client';
-import type { RequestSiteTrackPageView, RequestSpaceTrackPageView } from '@gitbook/api';
+import type { RequestSiteTrackPageView } from '@gitbook/api';
import cookies from 'js-cookie';
import * as React from 'react';
@@ -13,36 +13,17 @@ import { SiteContentPointer } from '@/lib/api';
export function TrackPageView(props: {
apiHost: string;
sitePointer: SiteContentPointer;
- spaceId: string;
pageId: string | undefined;
}) {
- const { apiHost, sitePointer, spaceId, pageId } = props;
+ const { apiHost, sitePointer, pageId } = props;
React.useEffect(() => {
- trackPageView({ apiHost, sitePointer, spaceId, pageId });
- }, [apiHost, spaceId, pageId, sitePointer]);
+ trackPageView({ apiHost, sitePointer, pageId });
+ }, [apiHost, pageId, sitePointer]);
return null;
}
-async function sendSpaceTrackPageViewRequest(args: {
- apiHost: string;
- spaceId: string;
- body: RequestSpaceTrackPageView;
-}) {
- const { apiHost, spaceId, body } = args;
- const url = new URL(apiHost);
- url.pathname = `/v1/spaces/${spaceId}/insights/track_view`;
-
- await fetch(url, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify(body),
- });
-}
-
async function sendSiteTrackPageViewRequest(args: {
apiHost: string;
sitePointer: SiteContentPointer;
@@ -71,10 +52,9 @@ let latestPageId: string | undefined | null = null;
async function trackPageView(args: {
apiHost: string;
sitePointer: SiteContentPointer;
- spaceId: string;
pageId: string | undefined;
}) {
- const { apiHost, sitePointer, pageId, spaceId } = args;
+ const { apiHost, sitePointer, pageId } = args;
if (pageId === latestPageId) {
// The hook can be called multiple times, we only want to track once.
return;
@@ -96,17 +76,14 @@ async function trackPageView(args: {
};
try {
- sitePointer
- ? await sendSiteTrackPageViewRequest({
- apiHost,
- sitePointer,
- body: {
- ...sharedTrackedProps,
- spaceId,
- siteSpaceId: sitePointer.siteSpaceId,
- },
- })
- : await sendSpaceTrackPageViewRequest({ apiHost, spaceId, body: sharedTrackedProps });
+ await sendSiteTrackPageViewRequest({
+ apiHost,
+ sitePointer,
+ body: {
+ ...sharedTrackedProps,
+ siteSpaceId: sitePointer.siteSpaceId,
+ },
+ });
} catch (error) {
console.error('Failed to track page view', error);
}