Skip to content

Commit 9ea3fa1

Browse files
committed
2 parents 8a11db1 + 187a0be commit 9ea3fa1

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

api/src/utils/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export const defaultConfig: OutputConfig = {
8181
experimentalCodehike: false,
8282
experimentalMath: false,
8383
automaticallyInferNextPrevious: true,
84+
plausibleAnalytics: false,
8485
};
8586

8687
// Merges any user config with default values.
@@ -121,6 +122,7 @@ export function mergeConfig(json: Record<string, unknown>): OutputConfig {
121122
'automaticallyInferNextPrevious',
122123
defaultConfig.automaticallyInferNextPrevious,
123124
),
125+
plausibleAnalytics: getBoolean(json, 'plausibleAnalytics', defaultConfig.plausibleAnalytics),
124126
};
125127
}
126128

docs/configuration.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,11 @@ Note; If using the `<Image />` component, the `zoom` property provided will over
216216
| Key | Type | Default |
217217
| ------------ | --------- | ------- |
218218
| `zoomImages` | `boolean` | `false` |
219+
220+
### `plausibleAnalytics`
221+
222+
If enabled, Plausible Analytics will be added to all of your documentation pages only if a custom domain has been enabled for this project.
223+
224+
| Key | Type | Default |
225+
| -------------------- | --------- | ------- |
226+
| `plausibleAnalytics` | `boolean` | `false` |

packages/server/src/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ export interface ConfigWithoutLocales {
4040
experimentalMath: boolean;
4141
// automatically infer next/previous
4242
automaticallyInferNextPrevious: boolean;
43+
// Adds Plausible Analytics to your documentation pages.
44+
plausibleAnalytics: string;
4345
}
4446

4547
export interface ConfigWithLocales {
@@ -85,6 +87,8 @@ export interface ConfigWithLocales {
8587
experimentalMath: boolean;
8688
// automatically infer next/previous
8789
automaticallyInferNextPrevious: boolean;
90+
// Adds Plausible Analytics to your documentation pages.
91+
plausibleAnalytics: string;
8892
}
8993
export type InputConfig = ConfigWithoutLocales | ConfigWithLocales;
9094

@@ -137,6 +141,8 @@ export interface OutputConfig {
137141
experimentalMath: boolean;
138142
// automatically infer next/previous
139143
automaticallyInferNextPrevious: boolean;
144+
// Adds Plausible Analytics to your documentation pages.
145+
plausibleAnalytics: boolean;
140146
}
141147

142148
export const defaultConfig: OutputConfig = {
@@ -158,6 +164,7 @@ export const defaultConfig: OutputConfig = {
158164
experimentalCodehike: false,
159165
experimentalMath: false,
160166
automaticallyInferNextPrevious: true,
167+
plausibleAnalytics: '',
161168
};
162169

163170
export type FetchBundleInput = {

website/app/components/Head.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import { Helmet } from 'react-helmet';
22
import { DocumentationLoader } from '~/loaders/documentation.server';
33
import codeHikeStyles from '@code-hike/mdx/dist/index.css';
4+
import domains from '../../../domains.json';
45

56
export const Head = ({ data }: { data: DocumentationLoader }) => {
67
const favicon = getFavicon({ data });
8+
const domain =
9+
domains.find(([, repository]) => repository === `${data.owner}/${data.repo}`)?.[0] || null;
710
data.repo;
811
return (
912
<Helmet>
@@ -35,6 +38,9 @@ export const Head = ({ data }: { data: DocumentationLoader }) => {
3538
`}
3639
</script>
3740
)}
41+
{data.config.plausibleAnalytics && domain && (
42+
<script defer data-domain={domain} src="https://plausible.io/js/plausible.js"></script>
43+
)}
3844
<link rel="icon" href={favicon} />
3945
{data.config.experimentalMath && (
4046
<link

0 commit comments

Comments
 (0)