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
2 changes: 1 addition & 1 deletion assets/js/welcome.js

Large diffs are not rendered by default.

20 changes: 15 additions & 5 deletions src/shared/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,21 @@ export function initAnalytics(): typeof posthog {
: {}),
before_send: (event) => {
if (event?.properties) {
delete event.properties.$current_url;
delete event.properties.$host;
delete event.properties.$pathname;
delete event.properties.$referrer;
delete event.properties.$referring_domain;
const p = event.properties;
delete p.$current_url;
delete p.$host;
delete p.$pathname;
delete p.$referrer;
delete p.$referring_domain;
// Newer posthog-js also records the entry URL/referrer/host on a
// `$session_entry_*` family (e.g. $session_entry_url =
// https://shop.example/wp-admin/admin.php?page=woocommerce-pos). Strip
// the whole family so the site's admin URL never reaches PostHog
// (privacy / wp.org guideline 7) — there is no useful campaign data on
// an admin-screen entry.
for (const key of Object.keys(p)) {
if (key.startsWith('$session_entry_')) delete p[key];
}
}
return event;
},
Expand Down
3 changes: 2 additions & 1 deletion tests/analytics-config.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ test('person profiles always + session recording stays off', () => {
});

test('before_send strips admin URLs', () => {
for (const key of ['\\$current_url', '\\$host', '\\$pathname', '\\$referrer']) {
assert.match(source, /key\.startsWith\('\$session_entry_'\)/, 'before_send must strip the $session_entry_* URL family');
for (const key of ['\\$current_url', '\\$host', '\\$pathname', '\\$referrer', '\\$referring_domain']) {
assert.match(source, new RegExp(key), `before_send must strip ${key}`);
}
});
Expand Down
Loading