Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
bentwnghk committed Feb 9, 2024
2 parents 03acb99 + 105e1a8 commit 2fbe1e1
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 2 deletions.
25 changes: 25 additions & 0 deletions docs/Deployment/Environment-Variable.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ LobeChat provides additional configuration options during deployment, which can
- [Data Analytics](#data-analytics)
- [Vercel Analytics](#vercel-analytics)
- [Posthog Analytics](#posthog-analytics)
- [Umami Analytics](#umami-analytics)

## General Variables

Expand Down Expand Up @@ -286,8 +287,32 @@ The above example adds `search-engine` plugin settings, and sets the `SERPAPI_AP
- Default: -
- Example: `1`

### Umami Analytics

#### `NEXT_PUBLIC_ANALYTICS_UMAMI`

- Type: Optional
- Description: Environment variable to enable [Umami Analytics][umami-analytics-url]. Set to `1` to enable Umami Analytics.
- Default: `-`
- Example: `1`

#### `NEXT_PUBLIC_UMAMI_SCRIPT_URL`

- Type: Optional
- Description: Set the url of the umami script. Default is the script address of Umami Cloud.
- Default: `https://analytics.umami.is/script.js`
- Example: `https://umami.your-site.com/script.js`

#### `NEXT_PUBLIC_UMAMI_WEBSITE_ID`

- Type: Required
- Description: The website ID in umami
- Default: `-`
- Example: `E738D82A-EE9E-4806-A81F-0CA3CAE57F65`

[auth0-client-page]: https://manage.auth0.com/dashboard
[azure-api-verion-url]: https://docs.microsoft.com/zh-cn/azure/developer/javascript/api-reference/es-modules/azure-sdk/ai-translation/translationconfiguration?view=azure-node-latest#api-version
[openai-api-page]: https://platform.openai.com/account/api-keys
[posthog-analytics-url]: https://posthog.com
[umami-analytics-url]: https://umami.is
[vercel-analytics-url]: https://vercel.com/analytics
26 changes: 26 additions & 0 deletions docs/Deployment/Environment-Variable.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ LobeChat 在部署时提供了一些额外的配置项,使用环境变量进
- [数据统计](#数据统计)
- [Vercel Analytics](#vercel-analytics)
- [Posthog Analytics](#posthog-analytics)
- [Umami Analytics](#umami-analytics)

## 通用变量

Expand Down Expand Up @@ -282,7 +283,32 @@ LobeChat 在部署时提供了一些额外的配置项,使用环境变量进
- 默认值: `-`
- 示例:`1`

### Umami Analytics

#### `NEXT_PUBLIC_ANALYTICS_UMAMI`

- 类型:可选
- 描述:用于开启 [Umami Analytics][umami-analytics-url] 的环境变量,设为 `1`
时开启 Umami Analytics
- 默认值: `-`
- 示例:`1`

#### `NEXT_PUBLIC_UMAMI_SCRIPT_URL`

- 类型:可选
- 描述:Umami 脚本的网址,默认为 Umami Cloud 提供的脚本网址
- 默认值:`https://analytics.umami.is/script.js`
- 示例:`https://umami.your-site.com/script.js`

#### `NEXT_PUBLIC_UMAMI_WEBSITE_ID`

- 类型:必选
- 描述:你的 Umami 的 Website ID
- 默认值:`-`
- 示例:`E738D82A-EE9E-4806-A81F-0CA3CAE57F65`

[auth0-client-page]: https://manage.auth0.com/dashboard
[azure-api-verion-url]: https://docs.microsoft.com/zh-cn/azure/developer/javascript/api-reference/es-modules/azure-sdk/ai-translation/translationconfiguration?view=azure-node-latest#api-version
[openai-api-page]: https://platform.openai.com/account/api-keys
[posthog-analytics-url]: https://posthog.com
[umami-analytics-url]: https://umami.is
2 changes: 1 addition & 1 deletion src/app/chat/settings/(desktop)/features/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const Header = memo(() => {
return (
<ChatHeader
left={<ChatHeaderTitle title={t('header.session')} />}
onBackClick={() => router.push(pathString('/chat', { hash: location.hash }))}
onBackClick={() => router.push(pathString('/chat', { search: location.search }))}
right={<HeaderContent />}
showBackButton
/>
Expand Down
15 changes: 15 additions & 0 deletions src/components/Analytics/Umami.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use client';

import Script from 'next/script';
import { memo } from 'react';

import { getClientConfig } from '@/config/client';

const { UMAMI_SCRIPT_URL, UMAMI_WEBSITE_ID } = getClientConfig();

const UmamiAnalytics = memo(
() =>
UMAMI_WEBSITE_ID && <Script data-website-id={UMAMI_WEBSITE_ID} defer src={UMAMI_SCRIPT_URL} />,
);

export default UmamiAnalytics;
5 changes: 4 additions & 1 deletion src/components/Analytics/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ import { getClientConfig } from '@/config/client';
const Vercel = dynamic(() => import('./Vercel'), { ssr: false });
const Plausible = dynamic(() => import('./Plausible'), { ssr: false });
const Posthog = dynamic(() => import('./Posthog'), { ssr: false });
const Umami = dynamic(() => import('./Umami'), { ssr: false });

const { ANALYTICS_VERCEL, ANALYTICS_POSTHOG, ANALYTICS_PLAUSIBLE } = getClientConfig();
const { ANALYTICS_VERCEL, ANALYTICS_POSTHOG, ANALYTICS_PLAUSIBLE, ANALYTICS_UMAMI } =
getClientConfig();

const Analytics = () => {
return (
<>
{ANALYTICS_VERCEL && <Vercel />}
{ANALYTICS_PLAUSIBLE && <Plausible />}
{ANALYTICS_POSTHOG && <Posthog />}
{ANALYTICS_UMAMI && <Umami />}
</>
);
};
Expand Down
10 changes: 10 additions & 0 deletions src/config/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ declare global {
NEXT_PUBLIC_POSTHOG_HOST: string;
NEXT_PUBLIC_POSTHOG_DEBUG: string;

NEXT_PUBLIC_ANALYTICS_UMAMI?: string;
NEXT_PUBLIC_UMAMI_SCRIPT_URL?: string;
NEXT_PUBLIC_UMAMI_WEBSITE_ID?: string;

NEXT_PUBLIC_I18N_DEBUG: string;
NEXT_PUBLIC_I18N_DEBUG_BROWSER: string;
NEXT_PUBLIC_I18N_DEBUG_SERVER: string;
Expand All @@ -50,6 +54,12 @@ export const getClientConfig = () => ({
POSTHOG_HOST: process.env.NEXT_PUBLIC_POSTHOG_HOST,
POSTHOG_DEBUG: process.env.NEXT_PUBLIC_POSTHOG_DEBUG === '1',

// Umami Analytics
ANALYTICS_UMAMI: process.env.NEXT_PUBLIC_ANALYTICS_UMAMI === '1',
UMAMI_SCRIPT_URL:
process.env.NEXT_PUBLIC_UMAMI_SCRIPT_URL || 'https://analytics.umami.is/script.js',
UMAMI_WEBSITE_ID: process.env.NEXT_PUBLIC_UMAMI_WEBSITE_ID,

// i18n debug mode
I18N_DEBUG: process.env.NEXT_PUBLIC_I18N_DEBUG === '1',
I18N_DEBUG_BROWSER: process.env.NEXT_PUBLIC_I18N_DEBUG_BROWSER === '1',
Expand Down

0 comments on commit 2fbe1e1

Please sign in to comment.