diff --git a/src/__tests__/posthog-core.js b/src/__tests__/posthog-core.js index fbf60e299..f879a180a 100644 --- a/src/__tests__/posthog-core.js +++ b/src/__tests__/posthog-core.js @@ -32,6 +32,7 @@ describe('posthog core', () => { given('config', () => ({ api_host: 'https://app.posthog.com', + property_denylist: [], property_blacklist: [], _onCapture: jest.fn(), get_device_id: jest.fn().mockReturnValue('device-id'), @@ -95,6 +96,7 @@ describe('posthog core', () => { it('calls update_campaign_params and update_referrer_info on sessionPersistence', () => { given('config', () => ({ + property_denylist: [], property_blacklist: [], _onCapture: jest.fn(), store_google: true, @@ -151,6 +153,7 @@ describe('posthog core', () => { given('config', () => ({ opt_out_useragent_filter: true, + property_denylist: [], property_blacklist: [], _onCapture: jest.fn(), })) @@ -172,6 +175,7 @@ describe('posthog core', () => { it('truncates long properties', () => { given('config', () => ({ properties_string_max_length: 1000, + property_denylist: [], property_blacklist: [], _onCapture: jest.fn(), })) @@ -185,6 +189,7 @@ describe('posthog core', () => { it('keeps long properties if null', () => { given('config', () => ({ properties_string_max_length: null, + property_denylist: [], property_blacklist: [], _onCapture: jest.fn(), })) @@ -219,6 +224,7 @@ describe('posthog core', () => { it('updates persisted person properties for feature flags if $set is present', () => { given('config', () => ({ + property_denylist: [], property_blacklist: [], _onCapture: jest.fn(), })) @@ -361,9 +367,11 @@ describe('posthog core', () => { given('config', () => ({ token: 'testtoken', + property_denylist: given.property_denylist, property_blacklist: given.property_blacklist, sanitize_properties: given.sanitize_properties, })) + given('property_denylist', () => []) given('property_blacklist', () => []) beforeEach(() => { @@ -382,11 +390,11 @@ describe('posthog core', () => { }) }) - it('respects property_blacklist', () => { - given('property_blacklist', () => ['$lib', 'persistent']) + it('respects property_denylist and property_blacklist', () => { + given('property_denylist', () => ['$lib', 'persistent']) + given('property_blacklist', () => ['token']) expect(given.subject).toEqual({ - token: 'testtoken', event: 'prop', distinct_id: 'abc', $window_id: 'windowId', @@ -880,6 +888,7 @@ describe('posthog core', () => { given('config', () => ({ request_batching: true, persistence: 'memory', + property_denylist: [], property_blacklist: [], _onCapture: jest.fn(), })) diff --git a/src/posthog-core.ts b/src/posthog-core.ts index 0253f4e99..eba796d3b 100644 --- a/src/posthog-core.ts +++ b/src/posthog-core.ts @@ -144,7 +144,9 @@ export const defaultConfig = (): PostHogConfig => ({ opt_out_capturing_persistence_type: 'localStorage', opt_out_capturing_cookie_prefix: null, opt_in_site_apps: false, + // Deprecated, use property_denylist instead. property_blacklist: [], + property_denylist: [], respect_dnt: false, sanitize_properties: null, request_headers: {}, // { header: value, header2: value } @@ -1036,13 +1038,20 @@ export class PostHog { properties ) - const property_blacklist = this.config.property_blacklist - if (_isArray(property_blacklist)) { - _each(property_blacklist, function (blacklisted_prop) { - delete properties[blacklisted_prop] + if (_isArray(this.config.property_denylist) && _isArray(this.config.property_blacklist)) { + // since property_blacklist is deprecated in favor of property_denylist, we merge both of them here + // TODO: merge this only once, requires refactoring tests + const property_denylist = [...this.config.property_blacklist, ...this.config.property_denylist] + _each(property_denylist, function (denylisted_prop) { + delete properties[denylisted_prop] }) } else { - logger.error('Invalid value for property_blacklist config: ' + property_blacklist) + logger.error( + 'Invalid value for property_denylist config: ' + + this.config.property_denylist + + ' or property_blacklist config: ' + + this.config.property_blacklist + ) } const sanitize_properties = this.config.sanitize_properties @@ -1690,10 +1699,15 @@ export class PostHog { * // name for super properties persistent store * persistence_name: '' * + * // deprecated, use property_denylist instead. * // names of properties/superproperties which should never - * // be sent with capture() calls + * // be sent with capture() calls. * property_blacklist: [] * + * // names of properties/superproperties which should never + * // be sent with capture() calls. + * property_denylist: [] + * * // if this is true, posthog cookies will be marked as * // secure, meaning they will only be transmitted over https * secure_cookie: false diff --git a/src/types.ts b/src/types.ts index 1d5590095..058aafd37 100644 --- a/src/types.ts +++ b/src/types.ts @@ -104,7 +104,9 @@ export interface PostHogConfig { opt_out_capturing_cookie_prefix: string | null opt_in_site_apps: boolean respect_dnt: boolean + /** @deprecated - use `property_denylist` instead */ property_blacklist: string[] + property_denylist: string[] request_headers: { [header_name: string]: string } on_request_error: (error: MinimalHTTPResponse) => void /** @deprecated - use `request_headers` instead */