diff --git a/playground/nextjs/pages/_app.tsx b/playground/nextjs/pages/_app.tsx index 7f0601849..222625689 100644 --- a/playground/nextjs/pages/_app.tsx +++ b/playground/nextjs/pages/_app.tsx @@ -15,6 +15,7 @@ if (typeof window !== 'undefined') { }, debug: true, __preview_send_client_session_params: true, + site_name: 'playground-nextjs', }) ;(window as any).posthog = posthog } diff --git a/src/__tests__/posthog-core.js b/src/__tests__/posthog-core.js index f9262e0ab..5a9b4c2fc 100644 --- a/src/__tests__/posthog-core.js +++ b/src/__tests__/posthog-core.js @@ -234,6 +234,26 @@ describe('posthog core', () => { undefined ) }) + + it('includes $site_name from config', () => { + given('config', () => ({ + site_name: 'test site name', + property_blacklist: [], + _onCapture: jest.fn(), + })) + const event = given.subject() + expect(event.properties['$site_name']).toBe('test site name') + }) + + it('doesnt include $site_name if not set', () => { + given('config', () => ({ + site_name: undefined, + property_blacklist: [], + _onCapture: jest.fn(), + })) + const event = given.subject() + expect(event.properties).not.toHaveProperty('$site_name') + }) }) describe('_afterDecideResponse', () => { diff --git a/src/posthog-core.ts b/src/posthog-core.ts index 0de7d319a..c6de3ecfe 100644 --- a/src/posthog-core.ts +++ b/src/posthog-core.ts @@ -988,6 +988,10 @@ export class PostHog { properties['$duration'] = parseFloat((duration_in_ms / 1000).toFixed(3)) } + if (this.config.site_name) { + properties['$site_name'] = this.config.site_name + } + // note: extend writes to the first object, so lets make sure we // don't write to the persistence properties object and info // properties object by passing in a new object diff --git a/src/types.ts b/src/types.ts index 0339727a1..013b2c7ff 100644 --- a/src/types.ts +++ b/src/types.ts @@ -124,6 +124,7 @@ export interface PostHogConfig { featureFlagPayloads?: Record } segment?: any + site_name?: string __preview_measure_pageview_stats?: boolean __preview_send_client_session_params?: boolean }