Skip to content

Commit 1360f5a

Browse files
authoredMar 13, 2025··
Merge pull request #3495 from ClickHouse/kapa_user_id
user id for kapa
2 parents 0deea25 + 9425db1 commit 1360f5a

5 files changed

+59
-1
lines changed
 

‎docusaurus.config.en.js

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ function skipIndex(items) {
1414
/** @type {import('@docusaurus/types').Config} */
1515
const config = {
1616
scripts: [
17+
{
18+
src: "/docs/js/kapa_config.js",
19+
async: false,
20+
},
1721
{
1822
src: "https://widget.kapa.ai/kapa-widget.bundle.js",
1923
"data-website-id": "c0b5f156-1e92-49df-8252-adacc9feb21b",

‎docusaurus.config.jp.js

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ function skipIndex(items) {
1414
/** @type {import('@docusaurus/types').Config} */
1515
const config = {
1616
scripts: [
17+
{
18+
src: "/docs/jp/js/kapa_config.js",
19+
async: false,
20+
},
1721
{
1822
src: "https://widget.kapa.ai/kapa-widget.bundle.js",
1923
"data-website-id": "c0b5f156-1e92-49df-8252-adacc9feb21b",

‎docusaurus.config.ru.js

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ function skipIndex(items) {
1414
/** @type {import('@docusaurus/types').Config} */
1515
const config = {
1616
scripts: [
17+
{
18+
src: "/docs/ru/js/kapa_config.js",
19+
async: false,
20+
},
1721
{
1822
src: "https://widget.kapa.ai/kapa-widget.bundle.js",
1923
"data-website-id": "c0b5f156-1e92-49df-8252-adacc9feb21b",

‎docusaurus.config.zh.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ function skipIndex(items) {
1414
/** @type {import('@docusaurus/types').Config} */
1515
const config = {
1616
scripts: [
17+
{
18+
src: "/docs/zh/js/kapa_config.js",
19+
async: false,
20+
},
1721
{
1822
src: "https://widget.kapa.ai/kapa-widget.bundle.js",
1923
"data-website-id": "c0b5f156-1e92-49df-8252-adacc9feb21b",
@@ -43,7 +47,7 @@ const config = {
4347
},
4448
title: "ClickHouse Docs",
4549
tagline:
46-
"我们提供文档、快速入门指南、用户指南、技术参考、常见问题解答等多种信息。",
50+
"我们提供文档、快速入门指南、用户指南、技术参考、常见问题解答等多种信息。",
4751
url: "https://clickhouse.com",
4852
// url: process.env.VERCEL_URL ? `https://${process.env.VERCEL_URL}` : 'https://bookish-disco-5997zvo.pages.github.io',
4953
baseUrl: "/docs/zh/",

‎static/js/kapa_config.js

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* Extracts the user ID from the Google Analytics device ID.
3+
* @example `GA1.1.xxxxxxxxxx.xxxxxxxxxx => xxxxxxxxxx-xxxxxxxxxx`
4+
* @link https://support.google.com/analytics/answer/11397207
5+
*/
6+
function extractGoogleAnalyticsUserIdFromCookie(gaCookie) {
7+
if (gaCookie) {
8+
// Remove the Google Analytics tracker from the device ID.
9+
const userIdParts = gaCookie.split('.').slice(-2);
10+
if (userIdParts.length === 2) {
11+
return userIdParts.join('-');
12+
}
13+
}
14+
return undefined;
15+
};
16+
17+
function getBrowserCookie(cookieName) {
18+
// In React Native environments, `document.cookie` doesn't exist.
19+
if (typeof document !== 'object' || typeof document.cookie !== 'string') {
20+
return undefined;
21+
}
22+
const name = cookieName + '=';
23+
const decodedCookie = decodeURIComponent(document.cookie);
24+
const ca = decodedCookie.split(';');
25+
for (let i = 0; i < ca.length; i++) {
26+
let c = ca[i].trim();
27+
if (c.startsWith(name)) {
28+
return c.substring(name.length);
29+
}
30+
}
31+
return undefined;
32+
};
33+
34+
function getGoogleAnalyticsUserIdFromBrowserCookie(cookieName) {
35+
const browserCookie = getBrowserCookie(cookieName);
36+
return browserCookie ? extractGoogleAnalyticsUserIdFromCookie(browserCookie) : undefined;
37+
};
38+
39+
// make sure the cookie is available when the script first loads, i.e. when the user first visits the website
40+
const ga_cookie_id = getGoogleAnalyticsUserIdFromBrowserCookie('_ga');
41+
42+
window.kapaSettings = { user: { uniqueClientId: ga_cookie_id } };

0 commit comments

Comments
 (0)
Please sign in to comment.