FastComments.com

Add Comments to GoHighLevel Sites

使用 FastComments,我们可以轻松地为任何使用 GoHighLevel 构建的网站添加实时评论功能。

请注意,本教程需要一个 FastComments 帐户。建议您先注册,然后再回来这里。您可以在此创建帐户。

先登录将确保生成的代码片段已与您的帐户关联。

GoHighLevel 会员网站与其他网站

本教程分为两类:会员网站和常规的 GoHighLevel 网站。

我们先从会员网站的说明开始。

步骤 1:编辑课程 Internal Link


首先,我们将编辑课程的设置。

为此,打开课程,然后点击 Edit Details

编辑课程详情
编辑课程详情

步骤 2:打开高级设置 Internal Link

接下来,我们需要打开 Advanced 设置:

打开高级设置
打开高级设置

我们将把代码添加到 Tracking Code 部分。转到该部分并点击 Footer Code

步骤 3:复制代码 Internal Link

现在我们将为你生成自定义的 FastComments 代码。使用下面的向导来配置 FastComments 在你的 GoHighLevel 网站上的工作方式:

FastComments Configuration Wizard

Choose the type of commenting experience you want
How should the widget be placed on your pages?
Comma-separated URL patterns (leave empty for all pages)
Your FastComments tenant ID (use "demo" for testing)

不同的评论框类型

你可以配置 TYPE = 'commenting' 这一行来切换使用的产品(例如你可以将其更改为 live 用于流式聊天,或 collab 用于协作聊天)。

将评论框放置在你想要的位置

假设你想在页面的特定部分放置评论框,而不是默认位置。 更改这行:

const TARGET_ELEMENT_ID = ''; // 设置为使用目标 div 模式

为:

const TARGET_ELEMENT_ID = 'fc_box'; // 设置为使用目标 div 模式

然后在 GHL 编辑器中,点击“code”按钮并添加你想放置评论的位置:

GoHighLevel FastComments Div 元素
Copy Copy
1
2<div
3 id="fc_box"
4 type="commenting"
5 urlid="custom-chat-id"
6></div>
7

每页不同的评论框类型

假设你希望用户高亮并讨论文本片段,或者改用流式聊天界面。

首先按照上面“将评论框放置在你想要的位置”中的步骤操作。

注意在上面的那段小片段中有 type="commenting"

例如,如果你想启用协作聊天,请将 type 改为 type="collab"

仅在特定页面显示

如果你不设置 不要设置 TARGET_ELEMENT_ID,你可以改为配置 VALID_PATTERNS 变量,以设置评论应该显示哪些 URL 路由。默认情况下,它会在 URL 中包含 /post 的页面上显示。

配置协作聊天

你可以告诉协作聊天只在特定区域内的 HTML 周围添加协作功能,例如,假设你在上面添加了页脚代码,然后在帖子/页面内容中添加此 div 来启用协作聊天:

具有指定内容的协作聊天
Copy Copy
1
2<div
3 id="fc_box"
4 type="collab"
5 urlid="custom-chat-id"
6><p>This content will have collab chat!</p></div>
7

然后 <div> 内的段落元素将启用协作聊天,页面上的其他部分则不会。如果你在 <div> 中不放任何内容,那么它将对整个帖子正文启用协作聊天。

步骤 4:粘贴代码 Internal Link


现在已复制代码片段,请将其按下图所示粘贴到 Footer Code 部分:

粘贴代码
粘贴代码

会员站点:安装成功 Internal Link

就这样!您现在应该已经在您的 GoHighLevel 课程中添加了实时评论。

成功
成功

如果您遇到“权限被拒绝”错误,或想自定义 FastComments,请继续阅读。

会员站点自定义 Internal Link

FastComments 旨在可根据您的站点进行定制。

如果您想添加自定义样式,或调整配置,查看我们的自定义和配置文档 以了解如何操作。


步骤 1:添加自定义代码元素 Internal Link

首先,我们将打开网站上要添加评论的页面的编辑器。

打开编辑器
打开编辑器

现在找到页面上想要添加评论的位置。将鼠标移到该区域的末端。会出现一个 + 图标:

添加部分
添加部分

如果我们点击它,会询问新部分应有多少列。我们将选择 1 COLUMN

添加一列
添加一列

现在,如果将鼠标移到新的单列行上,你将看到添加元素的选项。点击它:

添加元素
添加元素

向下滚动并选择 CUSTOM JS/HTML

选择 CUSTOM JS/HTML
选择 CUSTOM JS/HTML

现在选择我们的新元素,然后在左侧点击 Open Code Editor

打开代码编辑器
打开代码编辑器

步骤 2:复制并粘贴代码 Internal Link

现在是复制我们的代码。复制以下代码:

GoHighLevel 站点评论代码
Copy Copy
1
2<script src="https://cdn.fastcomments.com/js/embed-v2.min.js"></script>
3<div id="fastcomments-widget"></div>
4<script>
5 (function () {
6 const tenantId = 'demo';
7 const SCRIPT_ID = 'fastcomments-embed';
8 const WIDGET_ID = 'fastcomments-widget';
9
10 let lastInstance;
11 let currentUrlId;
12 let rendered = false;
13
14 // 为 SPA 支持修改 History API
15 const oldPushState = history.pushState;
16 history.pushState = function pushState() {
17 const ret = oldPushState.apply(this, arguments);
18 window.dispatchEvent(new Event('pushstate'));
19 window.dispatchEvent(new Event('locationchange'));
20 return ret;
21 };
22
23 const oldReplaceState = history.replaceState;
24 history.replaceState = function replaceState() {
25 const ret = oldReplaceState.apply(this, arguments);
26 window.dispatchEvent(new Event('replacestate'));
27 window.dispatchEvent(new Event('locationchange'));
28 return ret;
29 };
30
31 window.addEventListener('popstate', () => {
32 window.dispatchEvent(new Event('locationchange'));
33 });
34
35 function getContainer() {
36 return document.getElementById(WIDGET_ID);
37 }
38
39 // 确保脚本已加载的函数
40 function ensureScriptLoaded() {
41 return new Promise((resolve) => {
42 // 检查脚本标签是否已存在
43 let scriptTag = document.getElementById(SCRIPT_ID);
44
45 if (!scriptTag) {
46 console.log('FastComments: Script tag not found, adding dynamically...');
47 scriptTag = document.createElement('script');
48 scriptTag.id = SCRIPT_ID;
49 scriptTag.src = 'https://cdn.fastcomments.com/js/embed-v2.min.js';
50 scriptTag.async = true;
51
52 scriptTag.onload = () => {
53 console.log('FastComments: Script loaded successfully');
54 resolve();
55 };
56
57 scriptTag.onerror = () => {
58 console.error('FastComments: Failed to load script');
59 resolve(); // Resolve anyway to prevent hanging
60 };
61
62 document.head.appendChild(scriptTag);
63 } else if (window.FastCommentsUI) {
64 // 脚本标签存在且已加载
65 console.log('FastComments: Script already loaded');
66 resolve();
67 } else {
68 // 脚本标签存在但尚未就绪
69 console.log('FastComments: Waiting for script to initialize...');
70 scriptTag.addEventListener('load', () => {
71 resolve();
72 });
73
74 // 在脚本可能正在加载时的后备检查
75 const checkInterval = setInterval(() => {
76 if (window.FastCommentsUI) {
77 clearInterval(checkInterval);
78 resolve();
79 }
80 }, 100);
81
82 // 10 秒后超时
83 setTimeout(() => {
84 clearInterval(checkInterval);
85 console.warn('FastComments: Script load timeout');
86 resolve();
87 }, 10000);
88 }
89 });
90 }
91
92 // 主渲染函数
93 async function render() {
94 rendered = false;
95
96 // 在继续之前确保脚本已加载
97 await ensureScriptLoaded();
98
99 function tryNext() {
100 if (rendered) {
101 return;
102 }
103
104 const container = getContainer();
105
106 if (container) {
107 // 再次检查 FastCommentsUI 是否可用
108 if (!window.FastCommentsUI) {
109 console.log('FastComments: not ready, waiting...');
110 setTimeout(tryNext, 300);
111 return;
112 }
113
114 console.log('FastComments: Target element found, initializing...');
115
116 // 将当前 URL 作为 urlId
117 const newUrlId = window.location.pathname;
118
119 // 检查是否需要重新渲染(urlId 改变或首次渲染)
120 if (currentUrlId !== newUrlId || !lastInstance) {
121 currentUrlId = newUrlId;
122
123 // 销毁之前的实例(如果存在)
124 if (lastInstance) {
125 lastInstance.destroy();
126 // 清空容器内容
127 container.innerHTML = '';
128 }
129
130 // 准备配置
131 const config = {
132 tenantId: tenantId,
133 urlId: newUrlId
134 };
135
136 console.log('FastComments: Using urlId:', newUrlId);
137
138 // 初始化 FastComments
139 lastInstance = window.FastCommentsUI(container, config);
140 rendered = true;
141 } else {
142 console.log('FastComments: Already rendered with same urlId');
143 rendered = true;
144 }
145
146 // 监测容器是否被移除或 URL 是否更改
147 const interval = setInterval(function () {
148 const currentContainer = getContainer();
149 if (!currentContainer) {
150 console.log('FastComments: Container removed, will retry...');
151 rendered = false;
152 currentUrlId = null;
153 tryNext();
154 clearInterval(interval);
155 } else {
156 const newUrlId = window.location.pathname;
157 if (newUrlId !== currentUrlId) {
158 console.log('FastComments: URL changed, re-rendering...');
159 rendered = false;
160 tryNext();
161 clearInterval(interval);
162 }
163 }
164 }, 1000);
165 } else {
166 console.log('FastComments: Target element not found, waiting...');
167 setTimeout(tryNext, 300);
168 }
169 }
170
171 tryNext();
172 }
173
174 // DOM 就绪时的首次渲染
175 if (document.readyState === 'loading') {
176 document.addEventListener('DOMContentLoaded', render);
177 } else {
178 render();
179 }
180
181 // 在位置变更时重新渲染(用于 SPA)
182 window.addEventListener('locationchange', function () {
183 console.log('FastComments: Location changed, updating...');
184 render();
185 });
186 })();
187</script>
188

将其粘贴到我们打开的编辑器窗口中:

粘贴代码
粘贴代码

现在我们可以点击该窗口右下角的 Yes, Save

在页面顶部点击 Save,然后点击 Preview

站点:安装成功 Internal Link

就是这样!您现在应该已经在您的 GoHighLevel 网站上添加了实时评论功能。

成功
成功

如果您遇到“权限被拒绝”错误,或想要自定义 FastComments,请继续阅读。


站点自定义 Internal Link

FastComments 设计为可自定义,以匹配您的网站。

如果您想添加自定义样式或调整配置,请查看我们的自定义与配置文档以了解如何操作。

结论

如果所提供的步骤或代码因任何原因无法正常工作,请让我们知道