Skip to content

Commit

Permalink
♻️ refactor: refactor the Vercel Aanlytics and support Google Aanlyti…
Browse files Browse the repository at this point in the history
…cs (lobehub#1688)

* ♻️ refactor: migrating to the latest Speed Insights package

* ✨ feat: support google analytics

* 📝 docs: update docs

* 📝 docs: update docs
  • Loading branch information
arvinxx authored Mar 22, 2024
1 parent 9f436ef commit e07e9cf
Show file tree
Hide file tree
Showing 15 changed files with 282 additions and 203 deletions.
2 changes: 1 addition & 1 deletion docs/self-hosting/advanced/analytics.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ To better help analyze the usage of LobeChat users, we have integrated several f

[Vercel Analytics](https://vercel.com/analytics) is a data analytics service launched by Vercel, which can help you collect website visit data, including traffic, sources, and devices used for access.

We have integrated Vercel Analytics into the code, and you can enable it by setting the environment variable `NEXT_PUBLIC_ANALYTICS_VERCEL=1`, and then open the Analytics tab in your Vercel deployment project to view your app's visit data.
We have integrated Vercel Analytics into the code, and you can enable it by setting the environment variable `ENABLE_VERCEL_ANALYTICS=1`, and then open the Analytics tab in your Vercel deployment project to view your app's visit data.

Vercel Analytics provides 2500 free Web Analytics Events per month (which can be understood as page views), which is generally sufficient for personal deployment and self-use products.

Expand Down
2 changes: 1 addition & 1 deletion docs/self-hosting/advanced/analytics.zh-CN.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

[Vercel Analytics](https://vercel.com/analytics) 是 Vercel 推出的一款数据分析服务,它可以帮助你收集网站的访问情况,包括访问量、访问来源、访问设备等等。

我们在代码中集成了 Vercel Analytics,你可以通过设置环境变量 `NEXT_PUBLIC_ANALYTICS_VERCEL=1` 来开启它,并打开 Vercel 部署项目中 Analytics tab 查看你的应用访问情况。
我们在代码中集成了 Vercel Analytics,你可以通过设置环境变量 `ENABLE_VERCEL_ANALYTICS=1` 来开启它,并打开 Vercel 部署项目中 Analytics tab 查看你的应用访问情况。

Vercel Analytics 提供了 2500 次 / 月的免费 Web Analytics Events (可以理解为 PV),对于个人部署自用的产品来说基本够用。

Expand Down
91 changes: 91 additions & 0 deletions docs/self-hosting/environment-variables/analytics.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Data Statistics

We have integrated several free/open-source data analytics services in LobeChat for collecting user usage data. Here are environment variables that you can use.

## Vercel Analytics

### `ENABLE_VERCEL_ANALYTICS`

- Type: Optional
- Description: Used to configure the environment variable for Vercel Analytics. Set to `1` to enable Vercel Analytics.
- Default: `-`
- Example: `1`

### `DEBUG_VERCEL_ANALYTICS`

- Type: Optional
- Description: Used to enable the debug mode for Vercel Analytics.
- Default: `-`
- Example: `1`

## Google Analytics

### `ENABLE_GOOGLE_ANALYTICS`

- Type: Optional
- Description: Used to configure the environment variable for Google Analytics. Set to `1` to enable Google Analytics.
- Default: `-`
- Example: `1`

### `GOOGLE_ANALYTICS_MEASUREMENT_ID`

- Type: Required
- Description: Google Analytics Measurement ID,you can get it from the Google Analytics dashboard.
- Default: `-`
- Example: `G-63LP2TV03T`

## Posthog Analytics

### `NEXT_PUBLIC_ANALYTICS_POSTHOG`

- Type: Optional
- Description: Used to enable the environment variable for [PostHog Analytics][posthog-analytics-url]. Set to `1` to enable PostHog Analytics.
- Default: `-`
- Example: `1`

### `NEXT_PUBLIC_POSTHOG_KEY`

- Type: Optional
- Description: Set the PostHog project Key.
- Default: `-`
- Example: `phc_xxxxxxxx`

### `NEXT_PUBLIC_POSTHOG_HOST`

- Type: Optional
- Description: Set the deployment address of the PostHog service, defaulting to the official SAAS address.
- Default: `https://app.posthog.com`
- Example: `https://example.com`

### `NEXT_PUBLIC_POSTHOG_DEBUG`

- Type: Optional
- Description: Enable the debug mode for PostHog.
- Default: `-`
- Example: `1`

## Umami Analytics

### `NEXT_PUBLIC_ANALYTICS_UMAMI`

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

### `NEXT_PUBLIC_UMAMI_SCRIPT_URL`

- Type: Optional
- Description: The URL of the Umami script, defaulting to the script URL provided by 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: Your Umami Website ID.
- Default: `-`
- Example: `E738D82A-EE9E-4806-A81F-0CA3CAE57F65`

[posthog-analytics-url]: https://posthog.com
[umami-analytics-url]: https://umami.is
91 changes: 91 additions & 0 deletions docs/self-hosting/environment-variables/analytics.zh-CN.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# 数据统计

我们在 LobeChat 中集成了若干免费 / 开源的数据统计服务,用于了解用户的使用情况,以下是相关环境变量。

## Vercel Analytics

### `ENABLE_VERCEL_ANALYTICS`

- 类型:可选
- 描述:用于配置 Vercel Analytics 的环境变量,当设为 `1` 时开启 Vercel Analytics
- 默认值: `-`
- 示例:`1`

### `DEBUG_VERCEL_ANALYTICS`

- 类型:可选
- 描述:用于开启 Vercel Analytics 的调试模式
- 默认值: `-`
- 示例:`1`

## Google Analytics

### `ENABLE_GOOGLE_ANALYTICS`

- 类型:必选
- 描述:用于配置 Google Analytics 的环境变量,当设为 `1` 时开启 Google Analytics
- 默认值: `-`
- 示例:`1`

### `GOOGLE_ANALYTICS_MEASUREMENT_ID`

- 类型:必选
- 描述:Google Analytics 的 Measurement ID,如果开启了 Google Analytics,此项必填
- 默认值: `-`
- 示例:`G-63LP2TV03T`

## Posthog Analytics

### `NEXT_PUBLIC_ANALYTICS_POSTHOG`

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

### `NEXT_PUBLIC_POSTHOG_KEY`

- 类型:可选
- 描述:设置 PostHog 项目 Key
- 默认值: `-`
- 示例:`phc_xxxxxxxx`

### `NEXT_PUBLIC_POSTHOG_HOST`

- 类型:可选
- 描述:设置 PostHog 服务的部署地址,默认为官方的 SAAS 地址
- 默认值:`https://app.posthog.com`
- 示例:`https://example.com`

### `NEXT_PUBLIC_POSTHOG_DEBUG`

- 类型:可选
- 描述:开启 PostHog 的调试模式
- 默认值: `-`
- 示例:`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`

[posthog-analytics-url]: https://posthog.com
[umami-analytics-url]: https://umami.is
105 changes: 16 additions & 89 deletions docs/self-hosting/environment-variables/basic.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@ LobeChat provides some additional configuration options during deployment, which

The `DEFAULT_AGENT_CONFIG` is used to configure the default settings for the LobeChat default agent. It supports various data types and structures, including key-value pairs, nested fields, array values, and more. The table below provides detailed information on the configuration options, examples, and corresponding explanations for the `DEFAULT_AGENT_CONFIG` environment variable:

| Configuration Type | Example | Explanation |
| ----------------------- | ------------------------------------------- | ------------------------------------------------------------------------------------------------------------------ |
| Basic Key-Value Pair | `model=gpt-4` | Set the model to `gpt-4`. |
| Nested Field | `tts.sttLocale=en-US` | Set the language locale for the text-to-speech service to `en-US`. |
| Array | `plugins=search-engine,lobe-image-designer` | Enable the `search-engine` and `lobe-image-designer` plugins. |
| Chinese Comma | `plugins=search-engine,lobe-image-designer` | Same as above, demonstrating support for Chinese comma separation. |
| Multiple Configurations | `model=glm-4;provider=zhipu` | Set the model to `glm-4` and the model provider to `zhipu`. |
| Numeric Value | `params.max_tokens=300` | Set the maximum tokens to `300`. |
| Boolean Value | `enableAutoCreateTopic=true` | Enable automatic topic creation. |
| Special Characters | `inputTemplate="Hello; I am a bot;"` | Set the input template to `Hello; I am a bot;`. |
| Error Handling | `model=gpt-4;maxToken` | Ignore invalid entry `maxToken` and only parse `model=gpt-4`. |
| Value Override | `model=gpt-4;model=gpt-4-1106-preview` | If a key is repeated, use the value that appears last; in this case, the value of `model` is `gpt-4-1106-preview`. |
| Configuration Type | Example | Explanation |
| --- | --- | --- |
| Basic Key-Value Pair | `model=gpt-4` | Set the model to `gpt-4`. |
| Nested Field | `tts.sttLocale=en-US` | Set the language locale for the text-to-speech service to `en-US`. |
| Array | `plugins=search-engine,lobe-image-designer` | Enable the `search-engine` and `lobe-image-designer` plugins. |
| Chinese Comma | `plugins=search-engine,lobe-image-designer` | Same as above, demonstrating support for Chinese comma separation. |
| Multiple Configurations | `model=glm-4;provider=zhipu` | Set the model to `glm-4` and the model provider to `zhipu`. |
| Numeric Value | `params.max_tokens=300` | Set the maximum tokens to `300`. |
| Boolean Value | `enableAutoCreateTopic=true` | Enable automatic topic creation. |
| Special Characters | `inputTemplate="Hello; I am a bot;"` | Set the input template to `Hello; I am a bot;`. |
| Error Handling | `model=gpt-4;maxToken` | Ignore invalid entry `maxToken` and only parse `model=gpt-4`. |
| Value Override | `model=gpt-4;model=gpt-4-1106-preview` | If a key is repeated, use the value that appears last; in this case, the value of `model` is `gpt-4-1106-preview`. |

Further reading:

Expand Down Expand Up @@ -86,8 +86,8 @@ Further reading:
### Auth0

<Callout>
Currently, we only support the Auth0, Microsoft Entra ID identity verification service providers. If you need to use
other identity verification service providers, you can submit a [feature
Currently, we only support the Auth0, Microsoft Entra ID identity verification service providers.
If you need to use other identity verification service providers, you can submit a [feature
request](https://github.com/lobehub/lobe-chat/issues/new/choose) or Pull Request.
</Callout>

Expand Down Expand Up @@ -115,8 +115,8 @@ Further reading:
### Microsoft Entra ID

<Callout>
Currently, we only support the Auth0, Microsoft Entra ID identity verification service providers. If you need to use
other identity verification service providers, you can submit a [feature
Currently, we only support the Auth0, Microsoft Entra ID identity verification service providers.
If you need to use other identity verification service providers, you can submit a [feature
request](https://github.com/lobehub/lobe-chat/issues/new/choose) or Pull Request.
</Callout>

Expand Down Expand Up @@ -178,77 +178,4 @@ The above example sets the `SERPAPI_API_KEY` of the `search-engine` plugin to `x
- Description: Index address of the LobeChat assistant market. If you have deployed the assistant market service on your own, you can use this variable to override the default market address.
- Default: `https://chat-agents.lobehub.com`

## Data Statistics

### Vercel Analytics

#### `NEXT_PUBLIC_ANALYTICS_VERCEL`

- Type: Optional
- Description: Used to configure the environment variable for Vercel Analytics. Set to `1` to enable Vercel Analytics.
- Default: `-`
- Example: `1`

#### `NEXT_PUBLIC_VERCEL_DEBUG`

- Type: Optional
- Description: Used to enable the debug mode for Vercel Analytics.
- Default: `-`
- Example: `1`

### Posthog Analytics

#### `NEXT_PUBLIC_ANALYTICS_POSTHOG`

- Type: Optional
- Description: Used to enable the environment variable for [PostHog Analytics][posthog-analytics-url]. Set to `1` to enable PostHog Analytics.
- Default: `-`
- Example: `1`

#### `NEXT_PUBLIC_POSTHOG_KEY`

- Type: Optional
- Description: Set the PostHog project Key.
- Default: `-`
- Example: `phc_xxxxxxxx`

#### `NEXT_PUBLIC_POSTHOG_HOST`

- Type: Optional
- Description: Set the deployment address of the PostHog service, defaulting to the official SAAS address.
- Default: `https://app.posthog.com`
- Example: `https://example.com`

#### `NEXT_PUBLIC_POSTHOG_DEBUG`

- Type: Optional
- Description: Enable the debug mode for PostHog.
- Default: `-`
- Example: `1`

### Umami Analytics

#### `NEXT_PUBLIC_ANALYTICS_UMAMI`

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

#### `NEXT_PUBLIC_UMAMI_SCRIPT_URL`

- Type: Optional
- Description: The URL of the Umami script, defaulting to the script URL provided by 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: Your Umami Website ID.
- Default: `-`
- Example: `E738D82A-EE9E-4806-A81F-0CA3CAE57F65`

[auth0-client-page]: https://manage.auth0.com/dashboard
[posthog-analytics-url]: https://posthog.com
[umami-analytics-url]: https://umami.is
Loading

0 comments on commit e07e9cf

Please sign in to comment.