FastComments.com

Add Comments to ThriveCart Learn+ Courses


透過 FastComments,我們可以輕鬆為任何 ThriveCart Learn+ 課程新增即時留言功能。

如果您在設定上遇到任何問題,FastComments 支援也可以提供協助。

請注意,本教學需要一個 FastComments 帳戶。建議您先註冊帳戶,然後再回來此處。您可以在此建立帳戶。


步驟 1:準備課程 Internal Link


由於 ThriveCart Learn+ 的設計,我們必須在每個想要顯示評論的課程頁面上加入 FastComments 代碼。

我們可以在每個頁面使用相同的程式碼片段,系統會自動將不同的留言串綁定到各自的頁面。

首先在編輯器中打開課程,並新增一個 HTML 區塊。

在左側會看到一個 HTML 區塊選項。將其拖放到你想顯示評論的頁面位置。

打開課程並新增 HTML 區塊
打開課程並新增 HTML 區塊

現在選取新的 HTML 元素。左側會出現一個區塊,我們可以在那裡貼上程式碼。

現在你已準備好進行步驟 2。

步驟 2:加入自訂程式碼 Internal Link

For Step 2 we have to copy our code snippet. Check that line 50 does not say "demo" - you'll want to ensure this has your tenant id. It should be populated for you.

現在讓我們複製專為 ThriveCart-Learn 設計的 FastComments 程式碼片段。

它相當龐大,因為與 ThriveCart 的整合有許多功能,所以只要點擊程式碼片段右上角的 Copy 按鈕:

ThriveCart Learn+ 評論程式碼
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 let attemptsRemaining = 10;
7
8 function tryLoad() {
9 const simpleSSO = {optedInNotifications: true, optedInSubscriptionNotifications: true};
10 let isAuthenticated = false;
11 let profileLink = document.querySelector('.thrivecart-courses-header-profile-link');
12 if (!profileLink) {
13 profileLink = document.querySelector('.thrivecart-courses-header-profile'); // 預覽模式時 class 不同。
14 }
15 // 廣泛的 email 輸入欄選擇器,以防 ThriveCart 更改 id.
16 const emailInputField = document.querySelector('input[type=email]');
17 if (emailInputField && emailInputField.value) {
18 isAuthenticated = true;
19 simpleSSO.email = emailInputField.value;
20 } else if (profileLink && !profileLink.innerText.includes('John Smith')) { // 允許預覽運作 - 沒有可用的電子郵件。
21 attemptsRemaining--;
22 if (!attemptsRemaining) {
23 return console.error('Could not load FastComments - could not determine user information (email). Please reach out to FastComments support.');
24 }
25 console.warn('FastComments: No user email found - waiting and trying again.');
26 return setTimeout(tryLoad, attemptsRemaining < 5 ? 3000 : 100); // 在嘗試 5 次後增加等待時間,以防網速較慢。
27 }
28 if (profileLink) {
29 // 使用原始 "img" 查詢,以防 ThriveCart 更改圖片 class 選擇器。
30 const avatarImg = profileLink.querySelector('img');
31 if (avatarImg && avatarImg.src) {
32 isAuthenticated = true;
33 simpleSSO.avatar = avatarImg.src;
34 }
35 // 使用 innerText,以防 ThriveCart 更改個人資料名稱的顯示方式。
36 if (profileLink.innerText) {
37 isAuthenticated = true;
38 simpleSSO.username = profileLink.innerText;
39 } else {
40 const bold = profileLink.querySelector('b');
41 if (bold && bold.innerText) {
42 isAuthenticated = true;
43 simpleSSO.username = bold.innerText;
44 }
45 }
46 } else {
47 if (!attemptsRemaining) {
48 return console.error('Could not load FastComments - could not determine user information (user name/avatar). Please reach out to FastComments support.');
49 }
50 console.warn('FastComments: No user profile info found - waiting and trying again.');
51 attemptsRemaining--;
52 return setTimeout(tryLoad, attemptsRemaining < 5 ? 3000 : 100); // 在嘗試 5 次後增加等待時間,以防網速較慢。
53 }
54
55 let url;
56 const selectedNavLink = document.querySelector('.tcc-browse-lesson.active a');
57
58 if (selectedNavLink) {
59 // 有時 TC 在同一頁使用多個連結,因此我們要去重複處理。
60 url = getPathnameFromUrl(selectedNavLink.href);
61 } else {
62 // 去除行銷參數與網域名稱
63 url = window.location.pathname;
64 }
65
66 if (url) {
67 url = url.replace('/starte-hier', '');
68 url = url.replace('/start-here', '');
69 }
70
71 FastCommentsUI(document.getElementById('fastcomments-widget'), {
72 tenantId: 'demo',
73 urlId: url,
74 simpleSSO: isAuthenticated ? simpleSSO : null
75 });
76 }
77
78 tryLoad();
79
80 function getPathnameFromUrl(url) {
81 try {
82 const parsedUrl = new URL(url);
83 // 去除行銷參數與網域名稱
84 return parsedUrl.pathname;
85 } catch (error) {
86 console.error("Invalid URL", url, error);
87 return window.location.pathname; // 預設為目前頁面,至少在某些情況下仍可運作
88 }
89 }
90
91 })();
92</script>
93

Now paste it into the code block on the left in the ThriveCart editor. It should look like this:

已新增程式碼
已新增程式碼

That's it! Now we just have to publish:

發佈
發佈

That's it! You should now see the comment box on your course when you preview, and real users will be able to leave comments without signing in or leaving their username/email a second time.

測試注意!

If you have anonymous commenting disabled, which it is by default, you won't be able to leave comments in Preview mode as the John Smith user. You will get an authentication error as the default John Smith user has no email. If you want to test, we suggest you use a coupon code and go through your site like an actual user.

完成 Internal Link


Success! You should now see the FastComments Comment Widget.

成功!
成功!

恭喜您已在 ThriveCart 中設定 FastComments!如果您遇到網域錯誤,或想了解如何自訂評論區,請繼續閱讀!


自訂 Internal Link


FastComments 的設計可讓您自訂以配合您的網站。

如果您想新增自訂樣式或微調設定,請參閱我們的自訂化文件以了解如何進行。參閱我們的自訂化文件