posthog-js 1.135.2 → 1.136.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/array.full.js +2 -2
- package/dist/array.full.js.map +1 -1
- package/dist/array.js +1 -1
- package/dist/array.js.map +1 -1
- package/dist/es.js +1 -1
- package/dist/es.js.map +1 -1
- package/dist/lib/src/consent.d.ts +24 -0
- package/dist/lib/src/posthog-core.d.ts +27 -65
- package/dist/lib/src/types.d.ts +4 -15
- package/dist/module.d.ts +54 -80
- package/dist/module.js +1 -1
- package/dist/module.js.map +1 -1
- package/lib/package.json +1 -1
- package/lib/src/consent.d.ts +24 -0
- package/lib/src/consent.js +98 -0
- package/lib/src/consent.js.map +1 -0
- package/lib/src/extensions/replay/sessionrecording.js +3 -2
- package/lib/src/extensions/replay/sessionrecording.js.map +1 -1
- package/lib/src/posthog-core.d.ts +27 -65
- package/lib/src/posthog-core.js +46 -152
- package/lib/src/posthog-core.js.map +1 -1
- package/lib/src/types.d.ts +4 -15
- package/lib/src/types.js.map +1 -1
- package/package.json +1 -1
- package/dist/lib/src/gdpr-utils.d.ts +0 -70
- package/lib/src/gdpr-utils.d.ts +0 -70
- package/lib/src/gdpr-utils.js +0 -209
- package/lib/src/gdpr-utils.js.map +0 -1
|
@@ -6,7 +6,7 @@ import { RequestQueue } from './request-queue';
|
|
|
6
6
|
import { RetryQueue } from './retry-queue';
|
|
7
7
|
import { SessionIdManager } from './sessionid';
|
|
8
8
|
import { RequestRouter } from './utils/request-router';
|
|
9
|
-
import { CaptureOptions, CaptureResult, Compression, DecideResponse, EarlyAccessFeatureCallback,
|
|
9
|
+
import { CaptureOptions, CaptureResult, Compression, DecideResponse, EarlyAccessFeatureCallback, IsFeatureEnabledOptions, JsonType, PostHogConfig, Properties, Property, QueuedRequestOptions, RequestCallback, SessionIdChangedCallback, SnippetArrayItem, ToolbarParams } from './types';
|
|
10
10
|
import { SentryIntegration } from './extensions/sentry-integration';
|
|
11
11
|
import { PageViewManager } from './page-view';
|
|
12
12
|
import { PostHogSurveys } from './posthog-surveys';
|
|
@@ -16,6 +16,7 @@ import { SessionPropsManager } from './session-props';
|
|
|
16
16
|
import { Heatmaps } from './heatmaps';
|
|
17
17
|
import { ScrollManager } from './scroll-manager';
|
|
18
18
|
import { Autocapture } from './autocapture';
|
|
19
|
+
import { ConsentManager } from './consent';
|
|
19
20
|
type OnlyValidKeys<T, Shape> = T extends Shape ? (Exclude<keyof T, keyof Shape> extends never ? T : never) : never;
|
|
20
21
|
export declare const defaultConfig: () => PostHogConfig;
|
|
21
22
|
export declare const configRenames: (origConfig: Partial<PostHogConfig>) => Partial<PostHogConfig>;
|
|
@@ -37,6 +38,7 @@ export declare class PostHog {
|
|
|
37
38
|
featureFlags: PostHogFeatureFlags;
|
|
38
39
|
surveys: PostHogSurveys;
|
|
39
40
|
toolbar: Toolbar;
|
|
41
|
+
consent: ConsentManager;
|
|
40
42
|
persistence?: PostHogPersistence;
|
|
41
43
|
sessionPersistence?: PostHogPersistence;
|
|
42
44
|
sessionManager?: SessionIdManager;
|
|
@@ -127,9 +129,9 @@ export declare class PostHog {
|
|
|
127
129
|
*
|
|
128
130
|
* @param {String} event_name The name of the event. This can be anything the user does - 'Button Click', 'Sign Up', 'Item Purchased', etc.
|
|
129
131
|
* @param {Object} [properties] A set of properties to include with the event you're sending. These describe the user who did the event or details about the event itself.
|
|
130
|
-
* @param {Object} [
|
|
131
|
-
* @param {String} [
|
|
132
|
-
* @param {Date} [
|
|
132
|
+
* @param {Object} [config] Optional configuration for this capture request.
|
|
133
|
+
* @param {String} [config.transport] Transport method for network request ('XHR' or 'sendBeacon').
|
|
134
|
+
* @param {Date} [config.timestamp] Timestamp is a Date object. If not set, it'll automatically be set to the current time.
|
|
133
135
|
*/
|
|
134
136
|
capture(event_name: string, properties?: Properties | null, options?: CaptureOptions): CaptureResult | void;
|
|
135
137
|
_addCaptureHook(callback: (eventName: string) => void): void;
|
|
@@ -610,17 +612,15 @@ export declare class PostHog {
|
|
|
610
612
|
* @param function_name
|
|
611
613
|
*/
|
|
612
614
|
_requirePersonProcessing(function_name: string): boolean;
|
|
613
|
-
_gdpr_init(): void;
|
|
614
615
|
/**
|
|
615
616
|
* Enable or disable persistence based on options
|
|
616
617
|
* only enable/disable if persistence is not already in this state
|
|
617
|
-
* @param {boolean} [
|
|
618
|
-
* @param {boolean} [options.enable_persistence] If true, will re-enable sdk persistence
|
|
618
|
+
* @param {boolean} [disabled] If true, will re-enable sdk persistence
|
|
619
619
|
*/
|
|
620
|
-
|
|
621
|
-
_gdpr_call_func<R = any>(func: (token: string, options: GDPROptions) => R, options?: Partial<OptInOutCapturingOptions>): R;
|
|
620
|
+
private _sync_opt_out_with_persistence;
|
|
622
621
|
/**
|
|
623
622
|
* Opt the user in to data capturing and cookies/localstorage for this PostHog instance
|
|
623
|
+
* If the config.opt_out_persistence_by_default is set to false, the SDK persistence will be enabled.
|
|
624
624
|
*
|
|
625
625
|
* ### Usage
|
|
626
626
|
*
|
|
@@ -631,47 +631,28 @@ export declare class PostHog {
|
|
|
631
631
|
* posthog.opt_in_capturing({
|
|
632
632
|
* capture_event_name: 'User opted in',
|
|
633
633
|
* capture_event_properties: {
|
|
634
|
-
* '
|
|
635
|
-
* }
|
|
636
|
-
* cookie_expiration: 30,
|
|
637
|
-
* secure_cookie: true
|
|
634
|
+
* 'email': 'jdoe@example.com'
|
|
635
|
+
* }
|
|
638
636
|
* });
|
|
639
637
|
*
|
|
640
|
-
* @param {Object} [
|
|
641
|
-
* @param {
|
|
642
|
-
* @param {
|
|
643
|
-
* @param {Object} [options.capture_properties] Set of properties to be captured along with the opt-in action
|
|
644
|
-
* @param {boolean} [options.enable_persistence=true] If true, will re-enable sdk persistence
|
|
645
|
-
* @param {string} [options.persistence_type=localStorage] Persistence mechanism used - cookie or localStorage - falls back to cookie if localStorage is unavailable
|
|
646
|
-
* @param {string} [options.cookie_prefix=__ph_opt_in_out] Custom prefix to be used in the cookie/localstorage name
|
|
647
|
-
* @param {Number} [options.cookie_expiration] Number of days until the opt-in cookie expires (overrides value specified in this PostHog instance's config)
|
|
648
|
-
* @param {boolean} [options.cross_subdomain_cookie] Whether the opt-in cookie is set as cross-subdomain or not (overrides value specified in this PostHog instance's config)
|
|
649
|
-
* @param {boolean} [options.secure_cookie] Whether the opt-in cookie is set as secure or not (overrides value specified in this PostHog instance's config)
|
|
638
|
+
* @param {Object} [config] A dictionary of config options to override
|
|
639
|
+
* @param {string} [config.capture_event_name=$opt_in] Event name to be used for capturing the opt-in action
|
|
640
|
+
* @param {Object} [config.capture_properties] Set of properties to be captured along with the opt-in action
|
|
650
641
|
*/
|
|
651
|
-
opt_in_capturing(options?:
|
|
642
|
+
opt_in_capturing(options?: {
|
|
643
|
+
captureEventName?: string; /** event name to be used for capturing the opt-in action */
|
|
644
|
+
captureProperties?: Properties; /** set of properties to be captured along with the opt-in action */
|
|
645
|
+
}): void;
|
|
652
646
|
/**
|
|
653
|
-
* Opt the user out of data capturing and cookies/localstorage for this PostHog instance
|
|
647
|
+
* Opt the user out of data capturing and cookies/localstorage for this PostHog instance.
|
|
648
|
+
* If the config.opt_out_persistence_by_default is set to true, the SDK persistence will be disabled.
|
|
654
649
|
*
|
|
655
650
|
* ### Usage
|
|
656
651
|
*
|
|
657
652
|
* // opt user out
|
|
658
|
-
* posthog.opt_out_capturing()
|
|
659
|
-
*
|
|
660
|
-
* // opt user out with different cookie configuration from PostHog instance
|
|
661
|
-
* posthog.opt_out_capturing({
|
|
662
|
-
* cookie_expiration: 30,
|
|
663
|
-
* secure_cookie: true
|
|
664
|
-
* });
|
|
665
|
-
*
|
|
666
|
-
* @param {Object} [options] A dictionary of config options to override
|
|
667
|
-
* @param {boolean} [options.clear_persistence=true] If true, will delete all data stored by the sdk in persistence
|
|
668
|
-
* @param {string} [options.persistence_type=localStorage] Persistence mechanism used - cookie or localStorage - falls back to cookie if localStorage is unavailable
|
|
669
|
-
* @param {string} [options.cookie_prefix=__ph_opt_in_out] Custom prefix to be used in the cookie/localstorage name
|
|
670
|
-
* @param {Number} [options.cookie_expiration] Number of days until the opt-in cookie expires (overrides value specified in this PostHog instance's config)
|
|
671
|
-
* @param {boolean} [options.cross_subdomain_cookie] Whether the opt-in cookie is set as cross-subdomain or not (overrides value specified in this PostHog instance's config)
|
|
672
|
-
* @param {boolean} [options.secure_cookie] Whether the opt-in cookie is set as secure or not (overrides value specified in this PostHog instance's config)
|
|
653
|
+
* posthog.opt_out_capturing()
|
|
673
654
|
*/
|
|
674
|
-
opt_out_capturing(
|
|
655
|
+
opt_out_capturing(): void;
|
|
675
656
|
/**
|
|
676
657
|
* Check whether the user has opted in to data capturing and cookies/localstorage for this PostHog instance
|
|
677
658
|
*
|
|
@@ -680,12 +661,9 @@ export declare class PostHog {
|
|
|
680
661
|
* const has_opted_in = posthog.has_opted_in_capturing();
|
|
681
662
|
* // use has_opted_in value
|
|
682
663
|
*
|
|
683
|
-
* @param {Object} [options] A dictionary of config options to override
|
|
684
|
-
* @param {string} [options.persistence_type=localStorage] Persistence mechanism used - cookie or localStorage - falls back to cookie if localStorage is unavailable
|
|
685
|
-
* @param {string} [options.cookie_prefix=__ph_opt_in_out] Custom prefix to be used in the cookie/localstorage name
|
|
686
664
|
* @returns {boolean} current opt-in status
|
|
687
665
|
*/
|
|
688
|
-
has_opted_in_capturing(
|
|
666
|
+
has_opted_in_capturing(): boolean;
|
|
689
667
|
/**
|
|
690
668
|
* Check whether the user has opted out of data capturing and cookies/localstorage for this PostHog instance
|
|
691
669
|
*
|
|
@@ -694,12 +672,9 @@ export declare class PostHog {
|
|
|
694
672
|
* const has_opted_out = posthog.has_opted_out_capturing();
|
|
695
673
|
* // use has_opted_out value
|
|
696
674
|
*
|
|
697
|
-
* @param {Object} [options] A dictionary of config options to override
|
|
698
|
-
* @param {string} [options.persistence_type=localStorage] Persistence mechanism used - cookie or localStorage - falls back to cookie if localStorage is unavailable
|
|
699
|
-
* @param {string} [options.cookie_prefix=__ph_opt_in_out] Custom prefix to be used in the cookie/localstorage name
|
|
700
675
|
* @returns {boolean} current opt-out status
|
|
701
676
|
*/
|
|
702
|
-
has_opted_out_capturing(
|
|
677
|
+
has_opted_out_capturing(): boolean;
|
|
703
678
|
/**
|
|
704
679
|
* Clear the user's opt in/out status of data capturing and cookies/localstorage for this PostHog instance
|
|
705
680
|
*
|
|
@@ -707,23 +682,10 @@ export declare class PostHog {
|
|
|
707
682
|
*
|
|
708
683
|
* // clear user's opt-in/out status
|
|
709
684
|
* posthog.clear_opt_in_out_capturing();
|
|
710
|
-
*
|
|
711
|
-
*
|
|
712
|
-
* // configuration used when opt_in_capturing/opt_out_capturing methods were called.
|
|
713
|
-
* posthog.clear_opt_in_out_capturing({
|
|
714
|
-
* cookie_expiration: 30,
|
|
715
|
-
* secure_cookie: true
|
|
716
|
-
* });
|
|
717
|
-
*
|
|
718
|
-
* @param {Object} [options] A dictionary of config options to override
|
|
719
|
-
* @param {boolean} [options.enable_persistence=true] If true, will re-enable sdk persistence
|
|
720
|
-
* @param {string} [options.persistence_type=localStorage] Persistence mechanism used - cookie or localStorage - falls back to cookie if localStorage is unavailable
|
|
721
|
-
* @param {string} [options.cookie_prefix=__ph_opt_in_out] Custom prefix to be used in the cookie/localstorage name
|
|
722
|
-
* @param {Number} [options.cookie_expiration] Number of days until the opt-in cookie expires (overrides value specified in this PostHog instance's config)
|
|
723
|
-
* @param {boolean} [options.cross_subdomain_cookie] Whether the opt-in cookie is set as cross-subdomain or not (overrides value specified in this PostHog instance's config)
|
|
724
|
-
* @param {boolean} [options.secure_cookie] Whether the opt-in cookie is set as secure or not (overrides value specified in this PostHog instance's config)
|
|
685
|
+
* *
|
|
686
|
+
* @param {Object} [config] A dictionary of config options to override
|
|
725
687
|
*/
|
|
726
|
-
clear_opt_in_out_capturing(
|
|
688
|
+
clear_opt_in_out_capturing(): void;
|
|
727
689
|
debug(debug?: boolean): void;
|
|
728
690
|
}
|
|
729
691
|
export declare function init_from_snippet(): void;
|
package/lib/src/posthog-core.js
CHANGED
|
@@ -43,8 +43,7 @@ import { ALIAS_ID_KEY, FLAG_CALL_REPORTED, PEOPLE_DISTINCT_ID_KEY, SESSION_RECOR
|
|
|
43
43
|
import { SessionRecording } from './extensions/replay/sessionrecording';
|
|
44
44
|
import { Decide } from './decide';
|
|
45
45
|
import { Toolbar } from './extensions/toolbar';
|
|
46
|
-
import {
|
|
47
|
-
import { cookieStore, localStore } from './storage';
|
|
46
|
+
import { localStore } from './storage';
|
|
48
47
|
import { RequestQueue } from './request-queue';
|
|
49
48
|
import { RetryQueue } from './retry-queue';
|
|
50
49
|
import { SessionIdManager } from './sessionid';
|
|
@@ -66,6 +65,7 @@ import { Heatmaps } from './heatmaps';
|
|
|
66
65
|
import { ScrollManager } from './scroll-manager';
|
|
67
66
|
import { SimpleEventEmitter } from './utils/simple-event-emitter';
|
|
68
67
|
import { Autocapture } from './autocapture';
|
|
68
|
+
import { ConsentManager } from './consent';
|
|
69
69
|
var instances = {};
|
|
70
70
|
// some globals for comparisons
|
|
71
71
|
var __NOOP = function () { };
|
|
@@ -214,6 +214,7 @@ var PostHog = /** @class */ (function () {
|
|
|
214
214
|
this.surveys = new PostHogSurveys(this);
|
|
215
215
|
this.rateLimiter = new RateLimiter(this);
|
|
216
216
|
this.requestRouter = new RequestRouter(this);
|
|
217
|
+
this.consent = new ConsentManager(this);
|
|
217
218
|
// NOTE: See the property definition for deprecation notice
|
|
218
219
|
this.people = {
|
|
219
220
|
set: function (prop, to, callback) {
|
|
@@ -318,7 +319,7 @@ var PostHog = /** @class */ (function () {
|
|
|
318
319
|
// if any instance on the page has debug = true, we set the
|
|
319
320
|
// global debug to be true
|
|
320
321
|
Config.DEBUG = Config.DEBUG || this.config.debug;
|
|
321
|
-
this.
|
|
322
|
+
this._sync_opt_out_with_persistence();
|
|
322
323
|
// isUndefined doesn't provide typehint here so wouldn't reduce bundle as we'd need to assign
|
|
323
324
|
// eslint-disable-next-line posthog-js/no-direct-undefined-check
|
|
324
325
|
if (((_a = config.bootstrap) === null || _a === void 0 ? void 0 : _a.distinctID) !== undefined) {
|
|
@@ -590,9 +591,9 @@ var PostHog = /** @class */ (function () {
|
|
|
590
591
|
*
|
|
591
592
|
* @param {String} event_name The name of the event. This can be anything the user does - 'Button Click', 'Sign Up', 'Item Purchased', etc.
|
|
592
593
|
* @param {Object} [properties] A set of properties to include with the event you're sending. These describe the user who did the event or details about the event itself.
|
|
593
|
-
* @param {Object} [
|
|
594
|
-
* @param {String} [
|
|
595
|
-
* @param {Date} [
|
|
594
|
+
* @param {Object} [config] Optional configuration for this capture request.
|
|
595
|
+
* @param {String} [config.transport] Transport method for network request ('XHR' or 'sendBeacon').
|
|
596
|
+
* @param {Date} [config.timestamp] Timestamp is a Date object. If not set, it'll automatically be set to the current time.
|
|
596
597
|
*/
|
|
597
598
|
PostHog.prototype.capture = function (event_name, properties, options) {
|
|
598
599
|
var _a, _b;
|
|
@@ -601,7 +602,7 @@ var PostHog = /** @class */ (function () {
|
|
|
601
602
|
if (!this.__loaded || !this.persistence || !this.sessionPersistence || !this._requestQueue) {
|
|
602
603
|
return logger.uninitializedWarning('posthog.capture');
|
|
603
604
|
}
|
|
604
|
-
if (
|
|
605
|
+
if (this.consent.isOptedOut()) {
|
|
605
606
|
return;
|
|
606
607
|
}
|
|
607
608
|
// typing doesn't prevent interesting data
|
|
@@ -1206,6 +1207,7 @@ var PostHog = /** @class */ (function () {
|
|
|
1206
1207
|
return logger.uninitializedWarning('posthog.reset');
|
|
1207
1208
|
}
|
|
1208
1209
|
var device_id = this.get_property('$device_id');
|
|
1210
|
+
this.consent.reset();
|
|
1209
1211
|
(_a = this.persistence) === null || _a === void 0 ? void 0 : _a.clear();
|
|
1210
1212
|
(_b = this.sessionPersistence) === null || _b === void 0 ? void 0 : _b.clear();
|
|
1211
1213
|
(_c = this.persistence) === null || _c === void 0 ? void 0 : _c.set_property(USER_STATE, 'anonymous');
|
|
@@ -1474,6 +1476,7 @@ var PostHog = /** @class */ (function () {
|
|
|
1474
1476
|
(_c = this.autocapture) === null || _c === void 0 ? void 0 : _c.startIfEnabled();
|
|
1475
1477
|
(_d = this.heatmaps) === null || _d === void 0 ? void 0 : _d.startIfEnabled();
|
|
1476
1478
|
this.surveys.loadIfEnabled();
|
|
1479
|
+
this._sync_opt_out_with_persistence();
|
|
1477
1480
|
}
|
|
1478
1481
|
};
|
|
1479
1482
|
/**
|
|
@@ -1617,89 +1620,27 @@ var PostHog = /** @class */ (function () {
|
|
|
1617
1620
|
this._register_single(ENABLE_PERSON_PROCESSING, true);
|
|
1618
1621
|
return true;
|
|
1619
1622
|
};
|
|
1620
|
-
// perform some housekeeping around GDPR opt-in/out state
|
|
1621
|
-
PostHog.prototype._gdpr_init = function () {
|
|
1622
|
-
var is_localStorage_requested = this.config.opt_out_capturing_persistence_type === 'localStorage';
|
|
1623
|
-
// try to convert opt-in/out cookies to localStorage if possible
|
|
1624
|
-
if (is_localStorage_requested && localStore.is_supported()) {
|
|
1625
|
-
if (!this.has_opted_in_capturing() && this.has_opted_in_capturing({ persistence_type: 'cookie' })) {
|
|
1626
|
-
this.opt_in_capturing({ enable_persistence: false });
|
|
1627
|
-
}
|
|
1628
|
-
if (!this.has_opted_out_capturing() && this.has_opted_out_capturing({ persistence_type: 'cookie' })) {
|
|
1629
|
-
this.opt_out_capturing({ clear_persistence: false });
|
|
1630
|
-
}
|
|
1631
|
-
this.clear_opt_in_out_capturing({
|
|
1632
|
-
persistence_type: 'cookie',
|
|
1633
|
-
enable_persistence: false,
|
|
1634
|
-
});
|
|
1635
|
-
}
|
|
1636
|
-
// check whether the user has already opted out - if so, clear & disable persistence
|
|
1637
|
-
if (this.has_opted_out_capturing()) {
|
|
1638
|
-
this._gdpr_update_persistence({ clear_persistence: true });
|
|
1639
|
-
// check whether we should opt out by default
|
|
1640
|
-
// note: we don't clear persistence here by default since opt-out default state is often
|
|
1641
|
-
// used as an initial state while GDPR information is being collected
|
|
1642
|
-
}
|
|
1643
|
-
else if (!this.has_opted_in_capturing() &&
|
|
1644
|
-
(this.config.opt_out_capturing_by_default || cookieStore.get('ph_optout'))) {
|
|
1645
|
-
cookieStore.remove('ph_optout');
|
|
1646
|
-
this.opt_out_capturing({
|
|
1647
|
-
clear_persistence: this.config.opt_out_persistence_by_default,
|
|
1648
|
-
});
|
|
1649
|
-
}
|
|
1650
|
-
};
|
|
1651
1623
|
/**
|
|
1652
1624
|
* Enable or disable persistence based on options
|
|
1653
1625
|
* only enable/disable if persistence is not already in this state
|
|
1654
|
-
* @param {boolean} [
|
|
1655
|
-
* @param {boolean} [options.enable_persistence] If true, will re-enable sdk persistence
|
|
1626
|
+
* @param {boolean} [disabled] If true, will re-enable sdk persistence
|
|
1656
1627
|
*/
|
|
1657
|
-
PostHog.prototype.
|
|
1628
|
+
PostHog.prototype._sync_opt_out_with_persistence = function () {
|
|
1658
1629
|
var _a, _b, _c, _d;
|
|
1659
|
-
var
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1630
|
+
var isOptedOut = this.consent.isOptedOut();
|
|
1631
|
+
var defaultPersistenceDisabled = this.config.opt_out_persistence_by_default;
|
|
1632
|
+
// TRICKY: We want a deterministic state for persistence so that a new pageload has the same persistence
|
|
1633
|
+
var persistenceDisabled = this.config.disable_persistence || (isOptedOut && !!defaultPersistenceDisabled);
|
|
1634
|
+
if (((_a = this.persistence) === null || _a === void 0 ? void 0 : _a.disabled) !== persistenceDisabled) {
|
|
1635
|
+
(_b = this.persistence) === null || _b === void 0 ? void 0 : _b.set_disabled(persistenceDisabled);
|
|
1665
1636
|
}
|
|
1666
|
-
|
|
1667
|
-
|
|
1637
|
+
if (((_c = this.sessionPersistence) === null || _c === void 0 ? void 0 : _c.disabled) !== persistenceDisabled) {
|
|
1638
|
+
(_d = this.sessionPersistence) === null || _d === void 0 ? void 0 : _d.set_disabled(persistenceDisabled);
|
|
1668
1639
|
}
|
|
1669
|
-
if (!this.config.disable_persistence && ((_a = this.persistence) === null || _a === void 0 ? void 0 : _a.disabled) !== disabled) {
|
|
1670
|
-
(_b = this.persistence) === null || _b === void 0 ? void 0 : _b.set_disabled(disabled);
|
|
1671
|
-
}
|
|
1672
|
-
if (!this.config.disable_persistence && ((_c = this.sessionPersistence) === null || _c === void 0 ? void 0 : _c.disabled) !== disabled) {
|
|
1673
|
-
(_d = this.sessionPersistence) === null || _d === void 0 ? void 0 : _d.set_disabled(disabled);
|
|
1674
|
-
}
|
|
1675
|
-
};
|
|
1676
|
-
// call a base gdpr function after constructing the appropriate token and options args
|
|
1677
|
-
PostHog.prototype._gdpr_call_func = function (func, options) {
|
|
1678
|
-
options = extend({
|
|
1679
|
-
capture: this.capture.bind(this),
|
|
1680
|
-
persistence_type: this.config.opt_out_capturing_persistence_type,
|
|
1681
|
-
cookie_prefix: this.config.opt_out_capturing_cookie_prefix,
|
|
1682
|
-
cookie_expiration: this.config.cookie_expiration,
|
|
1683
|
-
cross_subdomain_cookie: this.config.cross_subdomain_cookie,
|
|
1684
|
-
secure_cookie: this.config.secure_cookie,
|
|
1685
|
-
}, options || {});
|
|
1686
|
-
// check if localStorage can be used for recording opt out status, fall back to cookie if not
|
|
1687
|
-
if (!localStore.is_supported() && options['persistence_type'] === 'localStorage') {
|
|
1688
|
-
options['persistence_type'] = 'cookie';
|
|
1689
|
-
}
|
|
1690
|
-
return func(this.config.token, {
|
|
1691
|
-
capture: options['capture'],
|
|
1692
|
-
captureEventName: options['capture_event_name'],
|
|
1693
|
-
captureProperties: options['capture_properties'],
|
|
1694
|
-
persistenceType: options['persistence_type'],
|
|
1695
|
-
persistencePrefix: options['cookie_prefix'],
|
|
1696
|
-
cookieExpiration: options['cookie_expiration'],
|
|
1697
|
-
crossSubdomainCookie: options['cross_subdomain_cookie'],
|
|
1698
|
-
secureCookie: options['secure_cookie'],
|
|
1699
|
-
});
|
|
1700
1640
|
};
|
|
1701
1641
|
/**
|
|
1702
1642
|
* Opt the user in to data capturing and cookies/localstorage for this PostHog instance
|
|
1643
|
+
* If the config.opt_out_persistence_by_default is set to false, the SDK persistence will be enabled.
|
|
1703
1644
|
*
|
|
1704
1645
|
* ### Usage
|
|
1705
1646
|
*
|
|
@@ -1710,58 +1651,33 @@ var PostHog = /** @class */ (function () {
|
|
|
1710
1651
|
* posthog.opt_in_capturing({
|
|
1711
1652
|
* capture_event_name: 'User opted in',
|
|
1712
1653
|
* capture_event_properties: {
|
|
1713
|
-
* '
|
|
1714
|
-
* }
|
|
1715
|
-
* cookie_expiration: 30,
|
|
1716
|
-
* secure_cookie: true
|
|
1654
|
+
* 'email': 'jdoe@example.com'
|
|
1655
|
+
* }
|
|
1717
1656
|
* });
|
|
1718
1657
|
*
|
|
1719
|
-
* @param {Object} [
|
|
1720
|
-
* @param {
|
|
1721
|
-
* @param {
|
|
1722
|
-
* @param {Object} [options.capture_properties] Set of properties to be captured along with the opt-in action
|
|
1723
|
-
* @param {boolean} [options.enable_persistence=true] If true, will re-enable sdk persistence
|
|
1724
|
-
* @param {string} [options.persistence_type=localStorage] Persistence mechanism used - cookie or localStorage - falls back to cookie if localStorage is unavailable
|
|
1725
|
-
* @param {string} [options.cookie_prefix=__ph_opt_in_out] Custom prefix to be used in the cookie/localstorage name
|
|
1726
|
-
* @param {Number} [options.cookie_expiration] Number of days until the opt-in cookie expires (overrides value specified in this PostHog instance's config)
|
|
1727
|
-
* @param {boolean} [options.cross_subdomain_cookie] Whether the opt-in cookie is set as cross-subdomain or not (overrides value specified in this PostHog instance's config)
|
|
1728
|
-
* @param {boolean} [options.secure_cookie] Whether the opt-in cookie is set as secure or not (overrides value specified in this PostHog instance's config)
|
|
1658
|
+
* @param {Object} [config] A dictionary of config options to override
|
|
1659
|
+
* @param {string} [config.capture_event_name=$opt_in] Event name to be used for capturing the opt-in action
|
|
1660
|
+
* @param {Object} [config.capture_properties] Set of properties to be captured along with the opt-in action
|
|
1729
1661
|
*/
|
|
1730
1662
|
PostHog.prototype.opt_in_capturing = function (options) {
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
this.
|
|
1663
|
+
var _a;
|
|
1664
|
+
this.consent.optInOut(true);
|
|
1665
|
+
this._sync_opt_out_with_persistence();
|
|
1666
|
+
// TODO: Do we need it to be sent instantly?
|
|
1667
|
+
this.capture((_a = options === null || options === void 0 ? void 0 : options.captureEventName) !== null && _a !== void 0 ? _a : '$opt_in', options === null || options === void 0 ? void 0 : options.captureProperties, { send_instantly: true });
|
|
1736
1668
|
};
|
|
1737
1669
|
/**
|
|
1738
|
-
* Opt the user out of data capturing and cookies/localstorage for this PostHog instance
|
|
1670
|
+
* Opt the user out of data capturing and cookies/localstorage for this PostHog instance.
|
|
1671
|
+
* If the config.opt_out_persistence_by_default is set to true, the SDK persistence will be disabled.
|
|
1739
1672
|
*
|
|
1740
1673
|
* ### Usage
|
|
1741
1674
|
*
|
|
1742
1675
|
* // opt user out
|
|
1743
|
-
* posthog.opt_out_capturing()
|
|
1744
|
-
*
|
|
1745
|
-
* // opt user out with different cookie configuration from PostHog instance
|
|
1746
|
-
* posthog.opt_out_capturing({
|
|
1747
|
-
* cookie_expiration: 30,
|
|
1748
|
-
* secure_cookie: true
|
|
1749
|
-
* });
|
|
1750
|
-
*
|
|
1751
|
-
* @param {Object} [options] A dictionary of config options to override
|
|
1752
|
-
* @param {boolean} [options.clear_persistence=true] If true, will delete all data stored by the sdk in persistence
|
|
1753
|
-
* @param {string} [options.persistence_type=localStorage] Persistence mechanism used - cookie or localStorage - falls back to cookie if localStorage is unavailable
|
|
1754
|
-
* @param {string} [options.cookie_prefix=__ph_opt_in_out] Custom prefix to be used in the cookie/localstorage name
|
|
1755
|
-
* @param {Number} [options.cookie_expiration] Number of days until the opt-in cookie expires (overrides value specified in this PostHog instance's config)
|
|
1756
|
-
* @param {boolean} [options.cross_subdomain_cookie] Whether the opt-in cookie is set as cross-subdomain or not (overrides value specified in this PostHog instance's config)
|
|
1757
|
-
* @param {boolean} [options.secure_cookie] Whether the opt-in cookie is set as secure or not (overrides value specified in this PostHog instance's config)
|
|
1676
|
+
* posthog.opt_out_capturing()
|
|
1758
1677
|
*/
|
|
1759
|
-
PostHog.prototype.opt_out_capturing = function (
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
}, options || {});
|
|
1763
|
-
this._gdpr_call_func(optOut, _options);
|
|
1764
|
-
this._gdpr_update_persistence(_options);
|
|
1678
|
+
PostHog.prototype.opt_out_capturing = function () {
|
|
1679
|
+
this.consent.optInOut(false);
|
|
1680
|
+
this._sync_opt_out_with_persistence();
|
|
1765
1681
|
};
|
|
1766
1682
|
/**
|
|
1767
1683
|
* Check whether the user has opted in to data capturing and cookies/localstorage for this PostHog instance
|
|
@@ -1771,13 +1687,10 @@ var PostHog = /** @class */ (function () {
|
|
|
1771
1687
|
* const has_opted_in = posthog.has_opted_in_capturing();
|
|
1772
1688
|
* // use has_opted_in value
|
|
1773
1689
|
*
|
|
1774
|
-
* @param {Object} [options] A dictionary of config options to override
|
|
1775
|
-
* @param {string} [options.persistence_type=localStorage] Persistence mechanism used - cookie or localStorage - falls back to cookie if localStorage is unavailable
|
|
1776
|
-
* @param {string} [options.cookie_prefix=__ph_opt_in_out] Custom prefix to be used in the cookie/localstorage name
|
|
1777
1690
|
* @returns {boolean} current opt-in status
|
|
1778
1691
|
*/
|
|
1779
|
-
PostHog.prototype.has_opted_in_capturing = function (
|
|
1780
|
-
return this.
|
|
1692
|
+
PostHog.prototype.has_opted_in_capturing = function () {
|
|
1693
|
+
return this.consent.isOptedIn();
|
|
1781
1694
|
};
|
|
1782
1695
|
/**
|
|
1783
1696
|
* Check whether the user has opted out of data capturing and cookies/localstorage for this PostHog instance
|
|
@@ -1787,13 +1700,10 @@ var PostHog = /** @class */ (function () {
|
|
|
1787
1700
|
* const has_opted_out = posthog.has_opted_out_capturing();
|
|
1788
1701
|
* // use has_opted_out value
|
|
1789
1702
|
*
|
|
1790
|
-
* @param {Object} [options] A dictionary of config options to override
|
|
1791
|
-
* @param {string} [options.persistence_type=localStorage] Persistence mechanism used - cookie or localStorage - falls back to cookie if localStorage is unavailable
|
|
1792
|
-
* @param {string} [options.cookie_prefix=__ph_opt_in_out] Custom prefix to be used in the cookie/localstorage name
|
|
1793
1703
|
* @returns {boolean} current opt-out status
|
|
1794
1704
|
*/
|
|
1795
|
-
PostHog.prototype.has_opted_out_capturing = function (
|
|
1796
|
-
return this.
|
|
1705
|
+
PostHog.prototype.has_opted_out_capturing = function () {
|
|
1706
|
+
return this.consent.isOptedOut();
|
|
1797
1707
|
};
|
|
1798
1708
|
/**
|
|
1799
1709
|
* Clear the user's opt in/out status of data capturing and cookies/localstorage for this PostHog instance
|
|
@@ -1802,28 +1712,12 @@ var PostHog = /** @class */ (function () {
|
|
|
1802
1712
|
*
|
|
1803
1713
|
* // clear user's opt-in/out status
|
|
1804
1714
|
* posthog.clear_opt_in_out_capturing();
|
|
1805
|
-
*
|
|
1806
|
-
*
|
|
1807
|
-
* // configuration used when opt_in_capturing/opt_out_capturing methods were called.
|
|
1808
|
-
* posthog.clear_opt_in_out_capturing({
|
|
1809
|
-
* cookie_expiration: 30,
|
|
1810
|
-
* secure_cookie: true
|
|
1811
|
-
* });
|
|
1812
|
-
*
|
|
1813
|
-
* @param {Object} [options] A dictionary of config options to override
|
|
1814
|
-
* @param {boolean} [options.enable_persistence=true] If true, will re-enable sdk persistence
|
|
1815
|
-
* @param {string} [options.persistence_type=localStorage] Persistence mechanism used - cookie or localStorage - falls back to cookie if localStorage is unavailable
|
|
1816
|
-
* @param {string} [options.cookie_prefix=__ph_opt_in_out] Custom prefix to be used in the cookie/localstorage name
|
|
1817
|
-
* @param {Number} [options.cookie_expiration] Number of days until the opt-in cookie expires (overrides value specified in this PostHog instance's config)
|
|
1818
|
-
* @param {boolean} [options.cross_subdomain_cookie] Whether the opt-in cookie is set as cross-subdomain or not (overrides value specified in this PostHog instance's config)
|
|
1819
|
-
* @param {boolean} [options.secure_cookie] Whether the opt-in cookie is set as secure or not (overrides value specified in this PostHog instance's config)
|
|
1715
|
+
* *
|
|
1716
|
+
* @param {Object} [config] A dictionary of config options to override
|
|
1820
1717
|
*/
|
|
1821
|
-
PostHog.prototype.clear_opt_in_out_capturing = function (
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
}, options !== null && options !== void 0 ? options : {});
|
|
1825
|
-
this._gdpr_call_func(clearOptInOut, _options);
|
|
1826
|
-
this._gdpr_update_persistence(_options);
|
|
1718
|
+
PostHog.prototype.clear_opt_in_out_capturing = function () {
|
|
1719
|
+
this.consent.reset();
|
|
1720
|
+
this._sync_opt_out_with_persistence();
|
|
1827
1721
|
};
|
|
1828
1722
|
PostHog.prototype.debug = function (debug) {
|
|
1829
1723
|
if (debug === false) {
|