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: add property so we can check if a client is using a proxy #1084

Merged
merged 7 commits into from
Mar 18, 2024
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
21 changes: 21 additions & 0 deletions src/__tests__/posthog-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ describe('posthog core', () => {
}))

given('config', () => ({
api_host: 'https://app.posthog.com',
token: 'testtoken',
property_denylist: given.property_denylist,
property_blacklist: given.property_blacklist,
Expand All @@ -408,6 +409,26 @@ describe('posthog core', () => {
})
})

it('sets $lib_custom_api_host if api_host is not the default', () => {
given('config', () => ({
api_host: 'https://custom.posthog.com',
token: 'testtoken',
property_denylist: given.property_denylist,
property_blacklist: given.property_blacklist,
sanitize_properties: given.sanitize_properties,
}))
expect(given.subject).toEqual({
token: 'testtoken',
event: 'prop',
$lib: 'web',
distinct_id: 'abc',
persistent: 'prop',
$window_id: 'windowId',
$session_id: 'sessionId',
$lib_custom_api_host: 'https://custom.posthog.com',
})
})

it('respects property_denylist and property_blacklist', () => {
given('property_denylist', () => ['$lib', 'persistent'])
given('property_blacklist', () => ['token'])
Expand Down
6 changes: 5 additions & 1 deletion src/posthog-core.ts
benjackwhite marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { cookieStore, localStore } from './storage'
import { RequestQueue } from './request-queue'
import { RetryQueue } from './retry-queue'
import { SessionIdManager } from './sessionid'
import { RequestRouter } from './utils/request-router'
import { RequestRouter, RequestRouterRegion } from './utils/request-router'
import {
AutocaptureConfig,
CaptureOptions,
Expand Down Expand Up @@ -813,6 +813,10 @@ export class PostHog {
properties['$window_id'] = windowId
}

if (this.requestRouter.region === RequestRouterRegion.CUSTOM) {
properties['$lib_custom_api_host'] = this.config.api_host
}

if (
this.sessionPropsManager &&
this.config.__preview_send_client_session_params &&
Expand Down
Loading