mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-16 15:45:13 +00:00
Control tracking of page views with env/header variables (#2380)
This commit is contained in:
@@ -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}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user