Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(web-analytics): Add site_name in config and $site_name property #916

Closed
wants to merge 2 commits into from
Closed
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
1 change: 1 addition & 0 deletions playground/nextjs/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
20 changes: 20 additions & 0 deletions src/__tests__/posthog-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
4 changes: 4 additions & 0 deletions src/posthog-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export interface PostHogConfig {
featureFlagPayloads?: Record<string, JsonType>
}
segment?: any
site_name?: string
__preview_measure_pageview_stats?: boolean
__preview_send_client_session_params?: boolean
}
Expand Down
Loading