feat(analytics): retire Rybbit and add SEO/GEO discovery tracking

Document Umami as the sole analytics platform, remove Rybbit proxy and
tracker code, and classify public page traffic with discovery_channel for
adm SEO/GEO dashboards.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
john
2026-08-12 01:34:05 +08:00
parent c58a23d155
commit c122bd5664
26 changed files with 466 additions and 449 deletions
+34 -18
View File
@@ -127,8 +127,8 @@ test('injects one local same-origin tracker with page dimensions', () => {
assert.match(out, /data-auto-track="false"/);
assert.doesNotMatch(out, /umami\.identify\(d\.owner_id/);
assert.match(out, /function identifyViewer\(\)/);
assert.match(out, /identifyViewer\(\);pageview\(\)/);
assert.match(out, /function pageview\(\).*window\.umami\.track\(\)/);
assert.match(out, /Object\.assign\(d,resolveDiscovery\(\)\);pageview\(\)/);
assert.match(out, /function pageview\(\).*window\.umami\.track\(function\(p\)/);
assert.doesNotMatch(out, /t\('page_view'\)/);
assert.match(out, /page_id/);
assert.match(out, /owner_segment/);
@@ -140,17 +140,20 @@ test('injects one local same-origin tracker with page dimensions', () => {
assert.match(out, /page_form_submit/);
assert.match(out, /page_scroll_/);
assert.match(out, /page_engaged_10s/);
assert.match(out, /discovery_channel/);
assert.match(out, /resolveDiscovery=/);
assert.match(out, /"owner_id":"user-123"/);
assert.match(out, /"generated_at":"2026-07-20T01:02:03.000Z"/);
assert.equal(injectMindSpaceAnalytics(out, { ownerId: 'user-123', config: { enabled: true, websiteId: 'local-website', idSecret: 'secret' } }), out);
});
test('public visitors skip creator identify and only send a standard page view', () => {
test('public visitors skip creator identify and attach discovery metadata to page views', () => {
const out = injectMindSpaceAnalytics('<!doctype html><html><head></head><body></body></html>', {
ownerId: 'user-123',
ownerSegment: 'plan:pro',
ownerLabel: '张三',
channel: 'h5',
referrerHint: 'https://www.google.com/search?q=demo',
config: {
enabled: true,
websiteId: 'local-website',
@@ -164,6 +167,8 @@ test('public visitors skip creator identify and only send a standard page view',
const calls = [];
vm.runInNewContext(inlineScript, {
URL,
URLSearchParams,
window: {
umami: {
identify: (...args) => calls.push(['identify', ...args]),
@@ -178,12 +183,23 @@ test('public visitors skip creator identify and only send a standard page view',
title: 'Demo',
documentElement: { scrollHeight: 1600 },
addEventListener: () => {},
referrer: 'https://www.google.com/search?q=demo',
},
location: {
href: 'https://m.tkmind.cn/MindSpace/demo/public/page.html',
pathname: '/MindSpace/demo/public/page.html',
hostname: 'm.tkmind.cn',
search: '',
},
location: { href: 'https://m.tkmind.cn/MindSpace/demo/public/page.html', pathname: '/MindSpace/demo/public/page.html' },
setTimeout: () => {},
});
assert.deepEqual(JSON.parse(JSON.stringify(calls)), [['track']]);
assert.equal(calls.length, 1);
assert.equal(calls[0][0], 'track');
const payload = calls[0][1]({});
assert.equal(payload.data.discovery_channel, 'seo');
assert.equal(payload.data.discovery_source, 'google');
assert.equal(payload.data.referrer_host, 'google.com');
});
test('logged-in public visitors identify themselves without using the page creator id', () => {
@@ -208,6 +224,8 @@ test('logged-in public visitors identify themselves without using the page creat
const calls = [];
vm.runInNewContext(inlineScript, {
URL,
URLSearchParams,
window: {
umami: {
identify: (...args) => calls.push(['identify', ...args]),
@@ -223,22 +241,20 @@ test('logged-in public visitors identify themselves without using the page creat
documentElement: { scrollHeight: 1600 },
addEventListener: () => {},
},
location: { href: 'https://m.tkmind.cn/MindSpace/demo/public/page.html', pathname: '/MindSpace/demo/public/page.html' },
location: {
href: 'https://m.tkmind.cn/MindSpace/demo/public/page.html',
pathname: '/MindSpace/demo/public/page.html',
hostname: 'm.tkmind.cn',
search: '',
},
setTimeout: () => {},
});
assert.deepEqual(JSON.parse(JSON.stringify(calls)), [
['identify', viewerId, {
username: '李四',
memind_page_url: 'https://m.tkmind.cn/MindSpace/demo/public/page.html',
owner_segment: 'plan:free',
plan_type: 'free',
channel: 'public',
surface: 'generated_page',
identity_mode: 'pseudonymous',
}],
['track'],
]);
assert.equal(calls.length, 2);
assert.equal(calls[0][0], 'identify');
assert.equal(calls[0][1], viewerId);
assert.equal(calls[1][0], 'track');
assert.equal(typeof calls[1][1], 'function');
assert.notEqual(viewerId, 'user-123');
});