{ad ? (
<>
- {ad}
+ {ad.children}
>
) : null}
@@ -132,6 +153,7 @@ export function Ad({
function AdSponsoredLink(props: { spaceId: string }) {
const { spaceId } = props;
const language = useLanguage();
+ const trackEvent = useTrackEvent();
const viaUrl = new URL('https://www.gitbook.com');
viaUrl.searchParams.set('utm_source', 'content');
@@ -149,9 +171,17 @@ function AdSponsoredLink(props: { spaceId: string }) {
'dark:text-light/5',
)}
>
-
+
);
}
diff --git a/packages/gitbook/src/components/Ads/AdClassicRendering.tsx b/packages/gitbook/src/components/Ads/AdClassicRendering.tsx
index dc2859a5b..3673f82e3 100644
--- a/packages/gitbook/src/components/Ads/AdClassicRendering.tsx
+++ b/packages/gitbook/src/components/Ads/AdClassicRendering.tsx
@@ -1,20 +1,38 @@
+import { SiteInsightsAd } from '@gitbook/api';
import * as React from 'react';
import { getResizedImageURL } from '@/lib/images';
import { tcls } from '@/lib/tailwind';
import { AdItem } from './types';
+import { Link } from '../primitives';
/**
* Classic rendering for an ad.
*/
-export async function AdClassicRendering({ ad }: { ad: AdItem }) {
+export async function AdClassicRendering({
+ ad,
+ insightsAd,
+}: {
+ ad: AdItem;
+ insightsAd: SiteInsightsAd | null;
+}) {
const smallImgSrc =
'smallImage' in ad ? await getResizedImageURL(ad.smallImage, { width: 192, dpr: 2 }) : null;
const logoSrc =
'logo' in ad ? await getResizedImageURL(ad.logo, { width: 192 - 48, dpr: 2 }) : null;
return (
-
{smallImgSrc && 'smallImage' in ad ? (
@@ -47,6 +63,6 @@ export async function AdClassicRendering({ ad }: { ad: AdItem }) {
-
+
);
}
diff --git a/packages/gitbook/src/components/Ads/AdCoverRendering.tsx b/packages/gitbook/src/components/Ads/AdCoverRendering.tsx
index e5d8d1c47..5a78e61e4 100644
--- a/packages/gitbook/src/components/Ads/AdCoverRendering.tsx
+++ b/packages/gitbook/src/components/Ads/AdCoverRendering.tsx
@@ -1,3 +1,4 @@
+import { SiteInsightsAd } from '@gitbook/api';
import * as React from 'react';
import { hexToRgba } from '@/lib/colors';
@@ -5,15 +6,32 @@ import { getResizedImageURL } from '@/lib/images';
import { tcls } from '@/lib/tailwind';
import { AdCover } from './types';
+import { Link } from '../primitives';
/**
* Cover rendering for an ad.
*/
-export async function AdCoverRendering({ ad }: { ad: AdCover }) {
+export async function AdCoverRendering({
+ ad,
+ insightsAd,
+}: {
+ ad: AdCover;
+ insightsAd: SiteInsightsAd | null;
+}) {
const largeImage = await getResizedImageURL(ad.largeImage, { width: 128, dpr: 2 });
return (
-
-
+
);
}
diff --git a/packages/gitbook/src/components/Ads/renderAd.tsx b/packages/gitbook/src/components/Ads/renderAd.tsx
index 63699bcf6..a02c20d92 100644
--- a/packages/gitbook/src/components/Ads/renderAd.tsx
+++ b/packages/gitbook/src/components/Ads/renderAd.tsx
@@ -1,5 +1,6 @@
'use server';
+import { SiteInsightsAd, SiteInsightsAdPlacement } from '@gitbook/api';
import { headers } from 'next/headers';
import { AdClassicRendering } from './AdClassicRendering';
@@ -20,7 +21,7 @@ interface FetchLiveAdOptions {
/** Mode to render the Ad */
mode: 'classic' | 'auto' | 'cover';
/** Name of the placement for the ad */
- placement: string;
+ placement: SiteInsightsAdPlacement;
/** If true, we'll not track it as an impression */
ignore: boolean;
}
@@ -47,16 +48,28 @@ export async function renderAd(options: FetchAdOptions) {
const { ad } = result;
- return (
- <>
- {mode === 'classic' || !('callToAction' in ad) ? (
-
- ) : (
-
- )}
- {ad.pixel ?
: null}
- >
- );
+ const insightsAd: SiteInsightsAd | null =
+ options.source === 'live'
+ ? {
+ placement: options.placement,
+ zoneId: options.zoneId,
+ domain: 'company' in ad ? ad.company : '',
+ }
+ : null;
+
+ return {
+ children: (
+ <>
+ {mode === 'classic' || !('callToAction' in ad) ? (
+
+ ) : (
+
+ )}
+ {ad.pixel ?
: null}
+ >
+ ),
+ insightsAd,
+ };
}
async function fetchAd({
diff --git a/packages/gitbook/src/components/DocumentView/BlockContentRef.tsx b/packages/gitbook/src/components/DocumentView/BlockContentRef.tsx
index 228207a25..d928de7fa 100644
--- a/packages/gitbook/src/components/DocumentView/BlockContentRef.tsx
+++ b/packages/gitbook/src/components/DocumentView/BlockContentRef.tsx
@@ -35,8 +35,11 @@ export async function BlockContentRef(props: BlockProps
title={resolved.text}
style={style}
insights={{
- target: block.data.ref,
- position: SiteInsightsLinkPosition.Content,
+ type: 'link_click',
+ link: {
+ target: block.data.ref,
+ position: SiteInsightsLinkPosition.Content,
+ },
}}
/>
);
diff --git a/packages/gitbook/src/components/DocumentView/File.tsx b/packages/gitbook/src/components/DocumentView/File.tsx
index 923e35f38..8c78bd2bc 100644
--- a/packages/gitbook/src/components/DocumentView/File.tsx
+++ b/packages/gitbook/src/components/DocumentView/File.tsx
@@ -26,8 +26,11 @@ export async function File(props: BlockProps) {
href={file.downloadURL}
download={file.name}
insights={{
- target: block.data.ref,
- position: SiteInsightsLinkPosition.Content,
+ type: 'link_click',
+ link: {
+ target: block.data.ref,
+ position: SiteInsightsLinkPosition.Content,
+ },
}}
className={tcls(
'group/file',
diff --git a/packages/gitbook/src/components/DocumentView/InlineLink.tsx b/packages/gitbook/src/components/DocumentView/InlineLink.tsx
index ebe9b0e66..6f0262e0f 100644
--- a/packages/gitbook/src/components/DocumentView/InlineLink.tsx
+++ b/packages/gitbook/src/components/DocumentView/InlineLink.tsx
@@ -27,8 +27,11 @@ export async function InlineLink(props: InlineProps) {
href={resolved.href}
className="underline underline-offset-2 text-primary hover:text-primary-700 transition-colors"
insights={{
- target: inline.data.ref,
- position: SiteInsightsLinkPosition.Content,
+ type: 'link_click',
+ link: {
+ target: inline.data.ref,
+ position: SiteInsightsLinkPosition.Content,
+ },
}}
>
) {
{resolved.text}
diff --git a/packages/gitbook/src/components/DocumentView/Table/RecordCard.tsx b/packages/gitbook/src/components/DocumentView/Table/RecordCard.tsx
index 5edb42142..4e14c7758 100644
--- a/packages/gitbook/src/components/DocumentView/Table/RecordCard.tsx
+++ b/packages/gitbook/src/components/DocumentView/Table/RecordCard.tsx
@@ -166,8 +166,11 @@ export async function RecordCard(
'dark:hover:before:ring-light/4',
])}
insights={{
- target: targetRef,
- position: SiteInsightsLinkPosition.Content,
+ type: 'link_click',
+ link: {
+ target: targetRef,
+ position: SiteInsightsLinkPosition.Content,
+ },
}}
>
{body}
diff --git a/packages/gitbook/src/components/DocumentView/Table/RecordColumnValue.tsx b/packages/gitbook/src/components/DocumentView/Table/RecordColumnValue.tsx
index fae743b2b..e525499f9 100644
--- a/packages/gitbook/src/components/DocumentView/Table/RecordColumnValue.tsx
+++ b/packages/gitbook/src/components/DocumentView/Table/RecordColumnValue.tsx
@@ -168,11 +168,14 @@ export async function RecordColumnValue(
insights={
ref.file
? {
- target: {
- kind: 'file',
- file: ref.file.id,
+ type: 'link_click',
+ link: {
+ target: {
+ kind: 'file',
+ file: ref.file.id,
+ },
+ position: SiteInsightsLinkPosition.Content,
},
- position: SiteInsightsLinkPosition.Content,
}
: undefined
}
@@ -225,8 +228,11 @@ export async function RecordColumnValue(
insights={
contentRef
? {
- target: contentRef,
- position: SiteInsightsLinkPosition.Content,
+ type: 'link_click',
+ link: {
+ target: contentRef,
+ position: SiteInsightsLinkPosition.Content,
+ },
}
: undefined
}
@@ -260,8 +266,11 @@ export async function RecordColumnValue(
key={index}
href={resolved.href}
insights={{
- target: contentRef,
- position: SiteInsightsLinkPosition.Content,
+ type: 'link_click',
+ link: {
+ target: contentRef,
+ position: SiteInsightsLinkPosition.Content,
+ },
}}
>
{resolved.text}
diff --git a/packages/gitbook/src/components/Footer/FooterLinksGroup.tsx b/packages/gitbook/src/components/Footer/FooterLinksGroup.tsx
index bcb12615e..20096b980 100644
--- a/packages/gitbook/src/components/Footer/FooterLinksGroup.tsx
+++ b/packages/gitbook/src/components/Footer/FooterLinksGroup.tsx
@@ -54,8 +54,11 @@ async function FooterLink(props: { link: CustomizationContentLink; context: Cont
'underline-offset-2',
)}
insights={{
- target: link.to,
- position: SiteInsightsLinkPosition.Footer,
+ type: 'link_click',
+ link: {
+ target: link.to,
+ position: SiteInsightsLinkPosition.Footer,
+ },
}}
>
{link.title}
diff --git a/packages/gitbook/src/components/Header/HeaderLink.tsx b/packages/gitbook/src/components/Header/HeaderLink.tsx
index f844c86ee..3a979d8e0 100644
--- a/packages/gitbook/src/components/Header/HeaderLink.tsx
+++ b/packages/gitbook/src/components/Header/HeaderLink.tsx
@@ -145,8 +145,11 @@ function HeaderItemButton(
}[linkStyle],
)}
insights={{
- target: linkTarget,
- position: SiteInsightsLinkPosition.Header,
+ type: 'link_click',
+ link: {
+ target: linkTarget,
+ position: SiteInsightsLinkPosition.Header,
+ },
}}
{...rest}
>
@@ -175,8 +178,11 @@ function HeaderItemLink(props: Omit) {
href={href}
className={getHeaderLinkClassName({ headerPreset })}
insights={{
- target: linkTarget,
- position: SiteInsightsLinkPosition.Header,
+ type: 'link_click',
+ link: {
+ target: linkTarget,
+ position: SiteInsightsLinkPosition.Header,
+ },
}}
{...rest}
>
@@ -219,7 +225,13 @@ async function SubHeaderLink(props: {
return (
{link.title}
diff --git a/packages/gitbook/src/components/Header/HeaderLinkMore.tsx b/packages/gitbook/src/components/Header/HeaderLinkMore.tsx
index e6a3f6b6b..1e31fc938 100644
--- a/packages/gitbook/src/components/Header/HeaderLinkMore.tsx
+++ b/packages/gitbook/src/components/Header/HeaderLinkMore.tsx
@@ -82,8 +82,11 @@ async function MoreMenuLink(props: {
insights={
link.to
? {
- target: link.to,
- position: SiteInsightsLinkPosition.Header,
+ type: 'link_click',
+ link: {
+ target: link.to,
+ position: SiteInsightsLinkPosition.Header,
+ },
}
: undefined
}
diff --git a/packages/gitbook/src/components/Insights/InsightsProvider.tsx b/packages/gitbook/src/components/Insights/InsightsProvider.tsx
index 2e65ab8c5..86ca87a2a 100644
--- a/packages/gitbook/src/components/Insights/InsightsProvider.tsx
+++ b/packages/gitbook/src/components/Insights/InsightsProvider.tsx
@@ -10,7 +10,7 @@ import * as cookies from '@/lib/cookies';
import { getSession } from './sessions';
import { getVisitorId } from './visitorId';
-type SiteEventName = api.SiteInsightsEvent['type'];
+export type InsightsEventName = api.SiteInsightsEvent['type'];
/**
* Global context for all events in the session.
@@ -46,15 +46,14 @@ interface InsightsEventOptions {
/**
* Input data for an event.
*/
-type TrackEventInput = { type: EventName } & Omit<
- Extract,
- 'location' | 'session'
->;
+export type TrackEventInput = {
+ type: EventName;
+} & Omit, 'location' | 'session'>;
/**
* Callback to track an event.
*/
-type TrackEventCallback = (
+type TrackEventCallback = (
event: TrackEventInput,
ctx?: InsightsEventPageContext,
options?: InsightsEventOptions,
@@ -80,7 +79,7 @@ export function InsightsProvider(props: InsightsProviderProps) {
[pathname: string]:
| {
url: string;
- events: TrackEventInput[];
+ events: TrackEventInput[];
context: InsightsEventContext;
pageContext?: InsightsEventPageContext;
}
@@ -152,7 +151,7 @@ export function InsightsProvider(props: InsightsProviderProps) {
const trackEvent: TrackEventCallback = useEventCallback(
(
- event: TrackEventInput,
+ event: TrackEventInput,
ctx?: InsightsEventPageContext,
options?: InsightsEventOptions,
) => {
@@ -253,7 +252,7 @@ function sendEvents(args: {
*/
function transformEvents(input: {
url: string;
- events: TrackEventInput[];
+ events: TrackEventInput[];
context: InsightsEventContext;
pageContext: InsightsEventPageContext;
visitorId: string;
diff --git a/packages/gitbook/src/components/PageAside/PageAside.tsx b/packages/gitbook/src/components/PageAside/PageAside.tsx
index 64e686ad1..696ba4196 100644
--- a/packages/gitbook/src/components/PageAside/PageAside.tsx
+++ b/packages/gitbook/src/components/PageAside/PageAside.tsx
@@ -5,6 +5,7 @@ import {
Site,
SiteAdsStatus,
SiteCustomizationSettings,
+ SiteInsightsAdPlacement,
Space,
} from '@gitbook/api';
import { Icon } from '@gitbook/icons';
@@ -226,7 +227,7 @@ export async function PageAside(props: {
zoneId={
site?.ads && site.ads.status === SiteAdsStatus.Live ? site.ads.zoneId : null
}
- placement="page.aside"
+ placement={SiteInsightsAdPlacement.Aside}
spaceId={space.id}
siteAdsStatus={site?.ads && site.ads.status ? site.ads.status : undefined}
ignore={process.env.NODE_ENV !== 'production'}
diff --git a/packages/gitbook/src/components/PageBody/PageBodyBlankslate.tsx b/packages/gitbook/src/components/PageBody/PageBodyBlankslate.tsx
index 1e8455628..5bdf4fbc6 100644
--- a/packages/gitbook/src/components/PageBody/PageBodyBlankslate.tsx
+++ b/packages/gitbook/src/components/PageBody/PageBodyBlankslate.tsx
@@ -52,8 +52,11 @@ export async function PageBodyBlankslate(props: {
title={child.title}
href={resolved.href}
insights={{
- target: child.target,
- position: SiteInsightsLinkPosition.Content,
+ type: 'link_click',
+ link: {
+ target: child.target,
+ position: SiteInsightsLinkPosition.Content,
+ },
}}
/>
);
diff --git a/packages/gitbook/src/components/PageBody/PageFooterNavigation.tsx b/packages/gitbook/src/components/PageBody/PageFooterNavigation.tsx
index 32fc2b860..1163514a5 100644
--- a/packages/gitbook/src/components/PageBody/PageFooterNavigation.tsx
+++ b/packages/gitbook/src/components/PageBody/PageFooterNavigation.tsx
@@ -51,11 +51,14 @@ export async function PageFooterNavigation(props: {
title={previous.title}
href={previousHref}
insights={{
- target: {
- kind: 'page',
- page: previous.id,
+ type: 'link_click',
+ link: {
+ target: {
+ kind: 'page',
+ page: previous.id,
+ },
+ position: SiteInsightsLinkPosition.Content,
},
- position: SiteInsightsLinkPosition.Content,
}}
reversed
/>
@@ -67,11 +70,14 @@ export async function PageFooterNavigation(props: {
title={next.title}
href={nextHref}
insights={{
- target: {
- kind: 'page',
- page: next.id,
+ type: 'link_click',
+ link: {
+ target: {
+ kind: 'page',
+ page: next.id,
+ },
+ position: SiteInsightsLinkPosition.Content,
},
- position: SiteInsightsLinkPosition.Content,
}}
/>
) : null}
diff --git a/packages/gitbook/src/components/TableOfContents/PageDocumentItem.tsx b/packages/gitbook/src/components/TableOfContents/PageDocumentItem.tsx
index 1c7236c6e..1e89e7cb5 100644
--- a/packages/gitbook/src/components/TableOfContents/PageDocumentItem.tsx
+++ b/packages/gitbook/src/components/TableOfContents/PageDocumentItem.tsx
@@ -29,11 +29,14 @@ export async function PageDocumentItem(props: {
href={href}
pathname={getPagePath(rootPages, page)}
insights={{
- target: {
- kind: 'page',
- page: page.id,
+ type: 'link_click',
+ link: {
+ target: {
+ kind: 'page',
+ page: page.id,
+ },
+ position: SiteInsightsLinkPosition.Sidebar,
},
- position: SiteInsightsLinkPosition.Sidebar,
}}
descendants={
page.pages && page.pages.length ? (
diff --git a/packages/gitbook/src/components/TableOfContents/PageLinkItem.tsx b/packages/gitbook/src/components/TableOfContents/PageLinkItem.tsx
index 37957cbc0..9b11da895 100644
--- a/packages/gitbook/src/components/TableOfContents/PageLinkItem.tsx
+++ b/packages/gitbook/src/components/TableOfContents/PageLinkItem.tsx
@@ -36,8 +36,11 @@ export async function PageLinkItem(props: { page: RevisionPageLink; context: Con
'dark:hover:bg-light/2',
)}
insights={{
- target: page.target,
- position: SiteInsightsLinkPosition.Sidebar,
+ type: 'link_click',
+ link: {
+ target: page.target,
+ position: SiteInsightsLinkPosition.Sidebar,
+ },
}}
>
diff --git a/packages/gitbook/src/components/TableOfContents/TableOfContents.tsx b/packages/gitbook/src/components/TableOfContents/TableOfContents.tsx
index d549c3758..275ca7884 100644
--- a/packages/gitbook/src/components/TableOfContents/TableOfContents.tsx
+++ b/packages/gitbook/src/components/TableOfContents/TableOfContents.tsx
@@ -4,6 +4,7 @@ import {
RevisionPageDocument,
RevisionPageGroup,
SiteCustomizationSettings,
+ SiteInsightsTrademarkPlacement,
Space,
} from '@gitbook/api';
import React from 'react';
@@ -135,7 +136,11 @@ export function TableOfContents(props: {
)}
/>
{customization.trademark.enabled ? (
-
+
) : null}
diff --git a/packages/gitbook/src/components/TableOfContents/Trademark.tsx b/packages/gitbook/src/components/TableOfContents/Trademark.tsx
index 626826350..327f935aa 100644
--- a/packages/gitbook/src/components/TableOfContents/Trademark.tsx
+++ b/packages/gitbook/src/components/TableOfContents/Trademark.tsx
@@ -1,15 +1,23 @@
-import { CustomizationSettings, SiteCustomizationSettings, Space } from '@gitbook/api';
+import {
+ CustomizationSettings,
+ SiteCustomizationSettings,
+ Space,
+ SiteInsightsTrademarkPlacement,
+} from '@gitbook/api';
import { Icon } from '@gitbook/icons';
import { t, getSpaceLanguage } from '@/intl/server';
import { tcls } from '@/lib/tailwind';
+import { Link } from '../primitives';
+
/**
* Trademark link to the GitBook.
*/
export function Trademark(props: {
space: Space;
customization: CustomizationSettings | SiteCustomizationSettings;
+ placement: SiteInsightsTrademarkPlacement;
}) {
return (
{t(language, 'powered_by_gitbook')}
-
+
);
}
diff --git a/packages/gitbook/src/components/primitives/Link.tsx b/packages/gitbook/src/components/primitives/Link.tsx
index d39ffa09d..837894fcb 100644
--- a/packages/gitbook/src/components/primitives/Link.tsx
+++ b/packages/gitbook/src/components/primitives/Link.tsx
@@ -1,10 +1,9 @@
'use client';
-import * as api from '@gitbook/api';
import NextLink, { LinkProps as NextLinkProps } from 'next/link';
import React from 'react';
-import { useTrackEvent } from '../Insights';
+import { useTrackEvent, TrackEventInput } from '../Insights';
// Props from Next, which includes NextLinkProps and all the things anchor elements support.
type BaseLinkProps = Omit, keyof NextLinkProps> &
@@ -13,8 +12,11 @@ type BaseLinkProps = Omit, keyof N
} & React.RefAttributes;
export type LinkInsightsProps = {
- /** Target of the link, for insights. */
- insights?: api.SiteInsightsEventLinkClick['link'];
+ /** Event to track when the link is clicked. */
+ insights?:
+ | TrackEventInput<'ad_click'>
+ | TrackEventInput<'link_click'>
+ | TrackEventInput<'trademark_click'>;
};
export type LinkProps = Omit &
@@ -40,7 +42,7 @@ export const Link = React.forwardRef(function Link(
const onClick = (event: React.MouseEvent) => {
if (insights) {
- trackEvent({ type: 'link_click', link: insights }, undefined, {
+ trackEvent(insights, undefined, {
immediate: isExternal,
});
}
diff --git a/packages/react-contentkit/package.json b/packages/react-contentkit/package.json
index a4eb3c448..e47c9c241 100644
--- a/packages/react-contentkit/package.json
+++ b/packages/react-contentkit/package.json
@@ -10,7 +10,7 @@
},
"dependencies": {
"classnames": "^2.5.1",
- "@gitbook/api": "^0.85.0",
+ "@gitbook/api": "^0.89.0",
"assert-never": "^1.2.1"
},
"peerDependencies": {