Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docusaurus.config.en.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ function skipIndex(items) {
/** @type {import('@docusaurus/types').Config} */
const config = {
scripts: [
{
src: "/docs/js/kapa_config.js",
async: false,
},
{
src: "https://widget.kapa.ai/kapa-widget.bundle.js",
"data-website-id": "c0b5f156-1e92-49df-8252-adacc9feb21b",
Expand Down
4 changes: 4 additions & 0 deletions docusaurus.config.jp.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ function skipIndex(items) {
/** @type {import('@docusaurus/types').Config} */
const config = {
scripts: [
{
src: "/docs/jp/js/kapa_config.js",
async: false,
},
{
src: "https://widget.kapa.ai/kapa-widget.bundle.js",
"data-website-id": "c0b5f156-1e92-49df-8252-adacc9feb21b",
Expand Down
4 changes: 4 additions & 0 deletions docusaurus.config.ru.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ function skipIndex(items) {
/** @type {import('@docusaurus/types').Config} */
const config = {
scripts: [
{
src: "/docs/ru/js/kapa_config.js",
async: false,
},
{
src: "https://widget.kapa.ai/kapa-widget.bundle.js",
"data-website-id": "c0b5f156-1e92-49df-8252-adacc9feb21b",
Expand Down
6 changes: 5 additions & 1 deletion docusaurus.config.zh.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ function skipIndex(items) {
/** @type {import('@docusaurus/types').Config} */
const config = {
scripts: [
{
src: "/docs/zh/js/kapa_config.js",
async: false,
},
{
src: "https://widget.kapa.ai/kapa-widget.bundle.js",
"data-website-id": "c0b5f156-1e92-49df-8252-adacc9feb21b",
Expand Down Expand Up @@ -43,7 +47,7 @@ const config = {
},
title: "ClickHouse Docs",
tagline:
"我们提供文档、快速入门指南、用户指南、技术参考、常见问题解答等多种信息。",
"我们提供文档、快速入门指南、用户指南、技术参考、常见问题解答等多种信息。",
url: "https://clickhouse.com",
// url: process.env.VERCEL_URL ? `https://${process.env.VERCEL_URL}` : 'https://bookish-disco-5997zvo.pages.github.io',
baseUrl: "/docs/zh/",
Expand Down
42 changes: 42 additions & 0 deletions static/js/kapa_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Extracts the user ID from the Google Analytics device ID.
* @example `GA1.1.xxxxxxxxxx.xxxxxxxxxx => xxxxxxxxxx-xxxxxxxxxx`
* @link https://support.google.com/analytics/answer/11397207
*/
function extractGoogleAnalyticsUserIdFromCookie(gaCookie) {
if (gaCookie) {
// Remove the Google Analytics tracker from the device ID.
const userIdParts = gaCookie.split('.').slice(-2);
if (userIdParts.length === 2) {
return userIdParts.join('-');
}
}
return undefined;
};

function getBrowserCookie(cookieName) {
// In React Native environments, `document.cookie` doesn't exist.
if (typeof document !== 'object' || typeof document.cookie !== 'string') {
return undefined;
}
const name = cookieName + '=';
const decodedCookie = decodeURIComponent(document.cookie);
const ca = decodedCookie.split(';');
for (let i = 0; i < ca.length; i++) {
let c = ca[i].trim();
if (c.startsWith(name)) {
return c.substring(name.length);
}
}
return undefined;
};

function getGoogleAnalyticsUserIdFromBrowserCookie(cookieName) {
const browserCookie = getBrowserCookie(cookieName);
return browserCookie ? extractGoogleAnalyticsUserIdFromCookie(browserCookie) : undefined;
};

// make sure the cookie is available when the script first loads, i.e. when the user first visits the website
const ga_cookie_id = getGoogleAnalyticsUserIdFromBrowserCookie('_ga');

window.kapaSettings = { user: { uniqueClientId: ga_cookie_id } };