Skip to content

Commit

Permalink
feat: integration for umami analytics
Browse files Browse the repository at this point in the history
Signed-off-by: ZTL-UwU <[email protected]>
  • Loading branch information
ZTL-UwU committed Nov 12, 2024
1 parent 5e7972d commit f9a418d
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 10 deletions.
5 changes: 5 additions & 0 deletions app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ export default defineAppConfig({
description: 'Beautifully designed Nuxt Content template built with shadcn-vue. Customizable. Compatible. Open Source.',
ogImage: '/hero.png',
ogImageComponent: 'ShadcnDocs',
umami: {
enable: true,
src: 'https://cloud.umami.is/script.js',
dataWebsiteId: 'd793fbf3-461e-4e26-9ec9-4e9141df96ee',
},
},
theme: {
customizable: true,
Expand Down
5 changes: 5 additions & 0 deletions composables/useConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ const defaultConfig: DefaultConfig = {
description: 'Beautifully designed Nuxt Content template built with shadcn-vue. Customizable. Compatible. Open Source.',
ogImage: '/hero.png',
ogImageComponent: 'ShadcnDocs',
umami: {
enable: false,
src: 'https://cloud.umami.is/script.js',
dataWebsiteId: '',
},
},
theme: {
customizable: true,
Expand Down
15 changes: 15 additions & 0 deletions content/3.api/1.configuration/1.shadcn-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,21 @@ All configurable icons can be set to iconify icons, emojis and urls, using [smar
::field{name="ogImageComponent" type="string" default-value="ShadcnDocs"}
The component to use for the dynamic ogImage. Possible values: `ShadcnDocs`, `Nuxt`, `NuxtSeo` or your custom component name.
::
::field{name="umami" type="object"}
::collapsible{title="Details"}
::field-group
::field{name="enable" type="boolean" default-value="false"}
Whether to turn on the umami integration.
::
::field{name="src" type="string" default-value="https://cloud.umami.is/script.js"}
The link src in the tracking code.
::
::field{name="dataWebsiteId" type="string"}
The _Website ID_ from umami dashboard.
::
::
::
::
::

## `theme`
Expand Down
41 changes: 41 additions & 0 deletions content/3.api/1.configuration/6.umami.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
title: Umami
icon: lucide:cloud
description: Integration for Umami analytics.
---

**shadcn-docs-nuxt** has built-in support for [Umami Analytics](https://umami.is/). Add your Umami `data-website-id` to `app.config.ts`.

```ts [app.config.ts]
export default defineAppConfig({
shadcnDocs: {
site: {
umami: {
enable: true,
src: 'https://cloud.umami.is/script.js',
dataWebsiteId: 'your-data-website-id',
},
},
},
});
```

These values are used to add the Umami script to `<head>`{lang="html"} as shown below.

```html
<script defer src="https://cloud.umami.is/script.js" data-website-id="your-data-website-id"></script>
```

## Parameters

::field-group
::field{name="enable" type="boolean" default-value="false"}
Whether to turn on the umami integration.
::
::field{name="src" type="string" default-value="https://cloud.umami.is/script.js"}
The link src in the tracking code.
::
::field{name="dataWebsiteId" type="string"}
The _Website ID_ from umami dashboard.
::
::
10 changes: 0 additions & 10 deletions plugins/analytics.client.ts

This file was deleted.

15 changes: 15 additions & 0 deletions plugins/umami.client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export default defineNuxtPlugin(() => {
const { enable, dataWebsiteId, src } = useConfig().value.site.umami;

if (enable && !import.meta.dev) {
useHead({
script: [
{
src,
'defer': true,
'data-website-id': dataWebsiteId,
},
],
});
}
});
5 changes: 5 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ interface DefaultConfig {
description: string;
ogImage: string;
ogImageComponent: string;
umami: {
enable: boolean;
src: string;
dataWebsiteId: string;
};
};
theme: {
customizable: boolean;
Expand Down

0 comments on commit f9a418d

Please sign in to comment.