Control tracking of page views with env/header variables (#2380)

This commit is contained in:
Valentino Hudhra
2024-08-02 16:10:28 +02:00
committed by GitHub
parent 094e9cdac2
commit ccbcab8822
2 changed files with 20 additions and 2 deletions
@@ -13,6 +13,7 @@ import { ContentPointer, ContentTarget, SiteContentPointer, api } from '@/lib/ap
import { hasFullWidthBlock, isNodeEmpty } from '@/lib/document';
import { ContentRefContext, resolveContentRef } from '@/lib/references';
import { tcls } from '@/lib/tailwind';
import { shouldTrackPageViews } from '@/lib/tracking';
import { PageBodyBlankslate } from './PageBodyBlankslate';
import { PageCover } from './PageCover';
@@ -141,14 +142,14 @@ export function PageBody(props: {
) : null}
</div>
</main>
<React.Suspense fallback={null}>
{shouldTrackPageViews() ? (
<TrackPageView
sitePointer={sitePointer}
spaceId={space.id}
pageId={page.id}
apiHost={api().endpoint}
/>
</React.Suspense>
) : null}
</>
);
}
+17
View File
@@ -0,0 +1,17 @@
import { headers } from 'next/headers';
/**
* Return true if a space track page views.
*/
export function shouldTrackPageViews(): boolean {
const headerSet = headers();
if (
process.env.GITBOOK_BLOCK_PAGE_VIEWS_TRACKING &&
!headerSet.has('x-gitbook-track-page-views')
) {
return false;
}
return true;
}