posthog-js 1.310.2 → 1.312.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.es5.js +1 -1
- package/dist/array.full.es5.js.map +1 -1
- package/dist/array.full.js +1 -1
- package/dist/array.full.js.map +1 -1
- package/dist/array.full.no-external.js +1 -1
- package/dist/array.full.no-external.js.map +1 -1
- package/dist/array.js +1 -1
- package/dist/array.js.map +1 -1
- package/dist/array.no-external.js +1 -1
- package/dist/array.no-external.js.map +1 -1
- package/dist/customizations.full.js +1 -1
- package/dist/lazy-recorder.js +1 -1
- package/dist/main.js +1 -1
- package/dist/main.js.map +1 -1
- package/dist/module.d.ts +43 -0
- package/dist/module.full.d.ts +43 -0
- package/dist/module.full.js +1 -1
- package/dist/module.full.js.map +1 -1
- package/dist/module.full.no-external.d.ts +43 -0
- package/dist/module.full.no-external.js +1 -1
- package/dist/module.full.no-external.js.map +1 -1
- package/dist/module.js +1 -1
- package/dist/module.js.map +1 -1
- package/dist/module.no-external.d.ts +43 -0
- package/dist/module.no-external.js +1 -1
- package/dist/module.no-external.js.map +1 -1
- package/dist/posthog-recorder.js +1 -1
- package/dist/src/page-view.d.ts +4 -0
- package/dist/src/posthog-core.d.ts +39 -0
- package/dist/surveys-preview.d.ts +43 -0
- package/lib/package.json +1 -1
- package/lib/src/page-view.d.ts +4 -0
- package/lib/src/page-view.js +29 -0
- package/lib/src/page-view.js.map +1 -1
- package/lib/src/posthog-core.d.ts +39 -0
- package/lib/src/posthog-core.js +83 -8
- package/lib/src/posthog-core.js.map +1 -1
- package/package.json +1 -1
package/dist/src/page-view.d.ts
CHANGED
|
@@ -20,7 +20,11 @@ export declare class PageViewManager {
|
|
|
20
20
|
pathname: string | undefined;
|
|
21
21
|
};
|
|
22
22
|
_instance: PostHog;
|
|
23
|
+
private _unsubscribeSessionId?;
|
|
23
24
|
constructor(instance: PostHog);
|
|
25
|
+
private _setupSessionRotationHandler;
|
|
26
|
+
private _onSessionIdChange;
|
|
27
|
+
destroy(): void;
|
|
24
28
|
doPageView(timestamp: Date, pageViewId?: string): PageViewEventProperties;
|
|
25
29
|
doPageLeave(timestamp: Date): PageViewEventProperties;
|
|
26
30
|
doEvent(): PageViewEventProperties;
|
|
@@ -470,6 +470,45 @@ export declare class PostHog {
|
|
|
470
470
|
* @public
|
|
471
471
|
*/
|
|
472
472
|
reloadFeatureFlags(): void;
|
|
473
|
+
/**
|
|
474
|
+
* Manually update feature flag values without making a network request.
|
|
475
|
+
*
|
|
476
|
+
* This is useful when you have feature flag values from an external source
|
|
477
|
+
* (e.g., server-side evaluation, edge middleware) and want to inject them
|
|
478
|
+
* into the client SDK.
|
|
479
|
+
*
|
|
480
|
+
* {@label Feature flags}
|
|
481
|
+
*
|
|
482
|
+
* @example
|
|
483
|
+
* ```js
|
|
484
|
+
* // Replace all flags with server-evaluated values
|
|
485
|
+
* posthog.updateFlags({
|
|
486
|
+
* 'my-flag': true,
|
|
487
|
+
* 'my-experiment': 'variant-a'
|
|
488
|
+
* })
|
|
489
|
+
*
|
|
490
|
+
* // Merge with existing flags (update only specified flags)
|
|
491
|
+
* posthog.updateFlags(
|
|
492
|
+
* { 'my-flag': true },
|
|
493
|
+
* undefined,
|
|
494
|
+
* { merge: true }
|
|
495
|
+
* )
|
|
496
|
+
*
|
|
497
|
+
* // With payloads
|
|
498
|
+
* posthog.updateFlags(
|
|
499
|
+
* { 'my-flag': true },
|
|
500
|
+
* { 'my-flag': { some: 'data' } }
|
|
501
|
+
* )
|
|
502
|
+
* ```
|
|
503
|
+
*
|
|
504
|
+
* @param flags - An object mapping flag keys to their values (boolean or string variant)
|
|
505
|
+
* @param payloads - Optional object mapping flag keys to their JSON payloads
|
|
506
|
+
* @param options - Optional settings. Use `{ merge: true }` to merge with existing flags instead of replacing.
|
|
507
|
+
* @public
|
|
508
|
+
*/
|
|
509
|
+
updateFlags(flags: Record<string, boolean | string>, payloads?: Record<string, JsonType>, options?: {
|
|
510
|
+
merge?: boolean;
|
|
511
|
+
}): void;
|
|
473
512
|
/**
|
|
474
513
|
* Opt the user in or out of an early access feature. [Learn more in the docs](/docs/feature-flags/early-access-feature-management#option-2-custom-implementation)
|
|
475
514
|
*
|
|
@@ -2757,7 +2757,11 @@ declare class PageViewManager {
|
|
|
2757
2757
|
pathname: string | undefined;
|
|
2758
2758
|
};
|
|
2759
2759
|
_instance: PostHog;
|
|
2760
|
+
private _unsubscribeSessionId?;
|
|
2760
2761
|
constructor(instance: PostHog);
|
|
2762
|
+
private _setupSessionRotationHandler;
|
|
2763
|
+
private _onSessionIdChange;
|
|
2764
|
+
destroy(): void;
|
|
2761
2765
|
doPageView(timestamp: Date, pageViewId?: string): PageViewEventProperties;
|
|
2762
2766
|
doPageLeave(timestamp: Date): PageViewEventProperties;
|
|
2763
2767
|
doEvent(): PageViewEventProperties;
|
|
@@ -3970,6 +3974,45 @@ declare class PostHog {
|
|
|
3970
3974
|
* @public
|
|
3971
3975
|
*/
|
|
3972
3976
|
reloadFeatureFlags(): void;
|
|
3977
|
+
/**
|
|
3978
|
+
* Manually update feature flag values without making a network request.
|
|
3979
|
+
*
|
|
3980
|
+
* This is useful when you have feature flag values from an external source
|
|
3981
|
+
* (e.g., server-side evaluation, edge middleware) and want to inject them
|
|
3982
|
+
* into the client SDK.
|
|
3983
|
+
*
|
|
3984
|
+
* {@label Feature flags}
|
|
3985
|
+
*
|
|
3986
|
+
* @example
|
|
3987
|
+
* ```js
|
|
3988
|
+
* // Replace all flags with server-evaluated values
|
|
3989
|
+
* posthog.updateFlags({
|
|
3990
|
+
* 'my-flag': true,
|
|
3991
|
+
* 'my-experiment': 'variant-a'
|
|
3992
|
+
* })
|
|
3993
|
+
*
|
|
3994
|
+
* // Merge with existing flags (update only specified flags)
|
|
3995
|
+
* posthog.updateFlags(
|
|
3996
|
+
* { 'my-flag': true },
|
|
3997
|
+
* undefined,
|
|
3998
|
+
* { merge: true }
|
|
3999
|
+
* )
|
|
4000
|
+
*
|
|
4001
|
+
* // With payloads
|
|
4002
|
+
* posthog.updateFlags(
|
|
4003
|
+
* { 'my-flag': true },
|
|
4004
|
+
* { 'my-flag': { some: 'data' } }
|
|
4005
|
+
* )
|
|
4006
|
+
* ```
|
|
4007
|
+
*
|
|
4008
|
+
* @param flags - An object mapping flag keys to their values (boolean or string variant)
|
|
4009
|
+
* @param payloads - Optional object mapping flag keys to their JSON payloads
|
|
4010
|
+
* @param options - Optional settings. Use `{ merge: true }` to merge with existing flags instead of replacing.
|
|
4011
|
+
* @public
|
|
4012
|
+
*/
|
|
4013
|
+
updateFlags(flags: Record<string, boolean | string>, payloads?: Record<string, JsonType>, options?: {
|
|
4014
|
+
merge?: boolean;
|
|
4015
|
+
}): void;
|
|
3973
4016
|
/**
|
|
3974
4017
|
* Opt the user in or out of an early access feature. [Learn more in the docs](/docs/feature-flags/early-access-feature-management#option-2-custom-implementation)
|
|
3975
4018
|
*
|
package/lib/package.json
CHANGED
package/lib/src/page-view.d.ts
CHANGED
|
@@ -20,7 +20,11 @@ export declare class PageViewManager {
|
|
|
20
20
|
pathname: string | undefined;
|
|
21
21
|
};
|
|
22
22
|
_instance: PostHog;
|
|
23
|
+
private _unsubscribeSessionId?;
|
|
23
24
|
constructor(instance: PostHog);
|
|
25
|
+
private _setupSessionRotationHandler;
|
|
26
|
+
private _onSessionIdChange;
|
|
27
|
+
destroy(): void;
|
|
24
28
|
doPageView(timestamp: Date, pageViewId?: string): PageViewEventProperties;
|
|
25
29
|
doPageLeave(timestamp: Date): PageViewEventProperties;
|
|
26
30
|
doEvent(): PageViewEventProperties;
|
package/lib/src/page-view.js
CHANGED
|
@@ -14,8 +14,37 @@ var logger_1 = require("./utils/logger");
|
|
|
14
14
|
// event name is $pageview or $pageleave and where $prev_pageview_id matches the original pageview event's id.
|
|
15
15
|
var PageViewManager = /** @class */ (function () {
|
|
16
16
|
function PageViewManager(instance) {
|
|
17
|
+
var _this = this;
|
|
18
|
+
this._onSessionIdChange = function (sessionId, _windowId, changeReason) {
|
|
19
|
+
// Only act on actual session rotations, not initial session creation
|
|
20
|
+
if (!changeReason) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
// Clear state when session changes for any of these reasons:
|
|
24
|
+
// - noSessionId: after posthog.reset() or forced idle reset
|
|
25
|
+
// - activityTimeout: 30 min idle (default, configurable up to 10 hours)
|
|
26
|
+
// - sessionPastMaximumLength: 24 hour max session
|
|
27
|
+
if (changeReason.noSessionId || changeReason.activityTimeout || changeReason.sessionPastMaximumLength) {
|
|
28
|
+
logger_1.logger.info('[PageViewManager] Session rotated, clearing pageview state', {
|
|
29
|
+
sessionId: sessionId,
|
|
30
|
+
changeReason: changeReason,
|
|
31
|
+
});
|
|
32
|
+
_this._currentPageview = undefined;
|
|
33
|
+
_this._instance.scrollManager.resetContext();
|
|
34
|
+
}
|
|
35
|
+
};
|
|
17
36
|
this._instance = instance;
|
|
37
|
+
this._setupSessionRotationHandler();
|
|
18
38
|
}
|
|
39
|
+
PageViewManager.prototype._setupSessionRotationHandler = function () {
|
|
40
|
+
var _a;
|
|
41
|
+
this._unsubscribeSessionId = (_a = this._instance.sessionManager) === null || _a === void 0 ? void 0 : _a.onSessionId(this._onSessionIdChange);
|
|
42
|
+
};
|
|
43
|
+
PageViewManager.prototype.destroy = function () {
|
|
44
|
+
var _a;
|
|
45
|
+
(_a = this._unsubscribeSessionId) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
46
|
+
this._unsubscribeSessionId = undefined;
|
|
47
|
+
};
|
|
19
48
|
PageViewManager.prototype.doPageView = function (timestamp, pageViewId) {
|
|
20
49
|
var _a;
|
|
21
50
|
var response = this._previousPageViewProperties(timestamp, pageViewId);
|
package/lib/src/page-view.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"page-view.js","sourceRoot":"","sources":["../../src/page-view.ts"],"names":[],"mappings":";;;AAAA,2CAAwC;AAExC,sCAAyD;AACzD,iCAAgC;AAChC,yCAAuC;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} from './utils/globals'\nimport { PostHog } from './posthog-core'\nimport { clampToRange, isUndefined } from '@posthog/core'\nimport { extend } from './utils'\nimport { logger } from './utils/logger'\n\ninterface PageViewEventProperties {\n $pageview_id?: string\n $prev_pageview_id?: string\n $prev_pageview_pathname?: string\n $prev_pageview_duration?: number // seconds\n $prev_pageview_last_scroll?: number\n $prev_pageview_last_scroll_percentage?: number\n $prev_pageview_max_scroll?: number\n $prev_pageview_max_scroll_percentage?: number\n $prev_pageview_last_content?: number\n $prev_pageview_last_content_percentage?: number\n $prev_pageview_max_content?: number\n $prev_pageview_max_content_percentage?: number\n}\n\n// This keeps track of the PageView state (such as the previous PageView's path, timestamp, id, and scroll properties).\n// We store the state in memory, which means that for non-SPA sites, the state will be lost on page reload. This means\n// that non-SPA sites should always send a $pageleave event on any navigation, before the page unloads. For SPA sites,\n// they only need to send a $pageleave event when the user navigates away from the site, as the information is not lost\n// on an internal navigation, and is included as the $prev_pageview_ properties in the next $pageview event.\n\n// Practically, this means that to find the scroll properties for a given pageview, you need to find the event where\n// event name is $pageview or $pageleave and where $prev_pageview_id matches the original pageview event's id.\n\nexport class PageViewManager {\n _currentPageview?: { timestamp: Date; pageViewId: string | undefined; pathname: string | undefined }\n _instance: PostHog\n\n constructor(instance: PostHog) {\n this._instance = instance\n }\n\n doPageView(timestamp: Date, pageViewId?: string): PageViewEventProperties {\n const response = this._previousPageViewProperties(timestamp, pageViewId)\n\n // On a pageview we reset the contexts\n this._currentPageview = { pathname: window?.location.pathname ?? '', pageViewId, timestamp }\n this._instance.scrollManager.resetContext()\n\n return response\n }\n\n doPageLeave(timestamp: Date): PageViewEventProperties {\n return this._previousPageViewProperties(timestamp, this._currentPageview?.pageViewId)\n }\n\n doEvent(): PageViewEventProperties {\n return { $pageview_id: this._currentPageview?.pageViewId }\n }\n\n private _previousPageViewProperties(timestamp: Date, pageviewId: string | undefined): PageViewEventProperties {\n const previousPageView = this._currentPageview\n\n if (!previousPageView) {\n return { $pageview_id: pageviewId }\n }\n\n let properties: PageViewEventProperties = {\n $pageview_id: pageviewId,\n $prev_pageview_id: previousPageView.pageViewId,\n }\n\n const scrollContext = this._instance.scrollManager.getContext()\n\n if (scrollContext && !this._instance.config.disable_scroll_properties) {\n let { maxScrollHeight, lastScrollY, maxScrollY, maxContentHeight, lastContentY, maxContentY } =\n scrollContext\n\n if (\n !isUndefined(maxScrollHeight) &&\n !isUndefined(lastScrollY) &&\n !isUndefined(maxScrollY) &&\n !isUndefined(maxContentHeight) &&\n !isUndefined(lastContentY) &&\n !isUndefined(maxContentY)\n ) {\n // Use ceil, so that e.g. scrolling 999.5px of a 1000px page is considered 100% scrolled\n maxScrollHeight = Math.ceil(maxScrollHeight)\n lastScrollY = Math.ceil(lastScrollY)\n maxScrollY = Math.ceil(maxScrollY)\n maxContentHeight = Math.ceil(maxContentHeight)\n lastContentY = Math.ceil(lastContentY)\n maxContentY = Math.ceil(maxContentY)\n\n // if the maximum scroll height is near 0, then the percentage is 1\n const lastScrollPercentage =\n maxScrollHeight <= 1 ? 1 : clampToRange(lastScrollY / maxScrollHeight, 0, 1, logger)\n const maxScrollPercentage =\n maxScrollHeight <= 1 ? 1 : clampToRange(maxScrollY / maxScrollHeight, 0, 1, logger)\n const lastContentPercentage =\n maxContentHeight <= 1 ? 1 : clampToRange(lastContentY / maxContentHeight, 0, 1, logger)\n const maxContentPercentage =\n maxContentHeight <= 1 ? 1 : clampToRange(maxContentY / maxContentHeight, 0, 1, logger)\n\n properties = extend(properties, {\n $prev_pageview_last_scroll: lastScrollY,\n $prev_pageview_last_scroll_percentage: lastScrollPercentage,\n $prev_pageview_max_scroll: maxScrollY,\n $prev_pageview_max_scroll_percentage: maxScrollPercentage,\n $prev_pageview_last_content: lastContentY,\n $prev_pageview_last_content_percentage: lastContentPercentage,\n $prev_pageview_max_content: maxContentY,\n $prev_pageview_max_content_percentage: maxContentPercentage,\n })\n }\n }\n\n if (previousPageView.pathname) {\n properties.$prev_pageview_pathname = previousPageView.pathname\n }\n if (previousPageView.timestamp) {\n // Use seconds, for consistency with our other duration-related properties like $duration\n properties.$prev_pageview_duration = (timestamp.getTime() - previousPageView.timestamp.getTime()) / 1000\n }\n\n return properties\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"page-view.js","sourceRoot":"","sources":["../../src/page-view.ts"],"names":[],"mappings":";;;AAAA,2CAAwC;AAExC,sCAAyD;AACzD,iCAAgC;AAChC,yCAAuC;AAkBvC,uHAAuH;AACvH,sHAAsH;AACtH,sHAAsH;AACtH,uHAAuH;AACvH,4GAA4G;AAE5G,oHAAoH;AACpH,8GAA8G;AAE9G;IAKI,yBAAY,QAAiB;QAA7B,iBAGC;QAMO,uBAAkB,GAA6B,UAAC,SAAS,EAAE,SAAS,EAAE,YAAY;YACtF,qEAAqE;YACrE,IAAI,CAAC,YAAY,EAAE,CAAC;gBAChB,OAAM;YACV,CAAC;YAED,6DAA6D;YAC7D,4DAA4D;YAC5D,wEAAwE;YACxE,kDAAkD;YAClD,IAAI,YAAY,CAAC,WAAW,IAAI,YAAY,CAAC,eAAe,IAAI,YAAY,CAAC,wBAAwB,EAAE,CAAC;gBACpG,eAAM,CAAC,IAAI,CAAC,4DAA4D,EAAE;oBACtE,SAAS,WAAA;oBACT,YAAY,cAAA;iBACf,CAAC,CAAA;gBACF,KAAI,CAAC,gBAAgB,GAAG,SAAS,CAAA;gBACjC,KAAI,CAAC,SAAS,CAAC,aAAa,CAAC,YAAY,EAAE,CAAA;YAC/C,CAAC;QACL,CAAC,CAAA;QA1BG,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAA;QACzB,IAAI,CAAC,4BAA4B,EAAE,CAAA;IACvC,CAAC;IAEO,sDAA4B,GAApC;;QACI,IAAI,CAAC,qBAAqB,GAAG,MAAA,IAAI,CAAC,SAAS,CAAC,cAAc,0CAAE,WAAW,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAA;IACpG,CAAC;IAsBD,iCAAO,GAAP;;QACI,MAAA,IAAI,CAAC,qBAA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,CAAC,CAAA;gBACvF,IAAM,qBAAqB,GACvB,gBAAgB,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAA,mBAAY,EAAC,YAAY,GAAG,gBAAgB,EAAE,CAAC,EAAE,CAAC,EAAE,eAAM,CAAC,CAAA;gBAC3F,IAAM,oBAAoB,GACtB,gBAAgB,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAA,mBAAY,EAAC,WAAW,GAAG,gBAAgB,EAAE,CAAC,EAAE,CAAC,EAAE,eAAM,CAAC,CAAA;gBAE1F,UAAU,GAAG,IAAA,cAAM,EAAC,UAAU,EAAE;oBAC5B,0BAA0B,EAAE,WAAW;oBACvC,qCAAqC,EAAE,oBAAoB;oBAC3D,yBAAyB,EAAE,UAAU;oBACrC,oCAAoC,EAAE,mBAAmB;oBACzD,2BAA2B,EAAE,YAAY;oBACzC,sCAAsC,EAAE,qBAAqB;oBAC7D,0BAA0B,EAAE,WAAW;oBACvC,qCAAqC,EAAE,oBAAoB;iBAC9D,CAAC,CAAA;YACN,CAAC;QACL,CAAC;QAED,IAAI,gBAAgB,CAAC,QAAQ,EAAE,CAAC;YAC5B,UAAU,CAAC,uBAAuB,GAAG,gBAAgB,CAAC,QAAQ,CAAA;QAClE,CAAC;QACD,IAAI,gBAAgB,CAAC,SAAS,EAAE,CAAC;YAC7B,yFAAyF;YACzF,UAAU,CAAC,uBAAuB,GAAG,CAAC,SAAS,CAAC,OAAO,EAAE,GAAG,gBAAgB,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,GAAG,IAAI,CAAA;QAC5G,CAAC;QAED,OAAO,UAAU,CAAA;IACrB,CAAC;IACL,sBAAC;AAAD,CAAC,AA5HD,IA4HC;AA5HY,0CAAe","sourcesContent":["import { window } from './utils/globals'\nimport { PostHog } from './posthog-core'\nimport { clampToRange, isUndefined } from '@posthog/core'\nimport { extend } from './utils'\nimport { logger } from './utils/logger'\nimport { SessionIdChangedCallback } from './types'\n\ninterface PageViewEventProperties {\n $pageview_id?: string\n $prev_pageview_id?: string\n $prev_pageview_pathname?: string\n $prev_pageview_duration?: number // seconds\n $prev_pageview_last_scroll?: number\n $prev_pageview_last_scroll_percentage?: number\n $prev_pageview_max_scroll?: number\n $prev_pageview_max_scroll_percentage?: number\n $prev_pageview_last_content?: number\n $prev_pageview_last_content_percentage?: number\n $prev_pageview_max_content?: number\n $prev_pageview_max_content_percentage?: number\n}\n\n// This keeps track of the PageView state (such as the previous PageView's path, timestamp, id, and scroll properties).\n// We store the state in memory, which means that for non-SPA sites, the state will be lost on page reload. This means\n// that non-SPA sites should always send a $pageleave event on any navigation, before the page unloads. For SPA sites,\n// they only need to send a $pageleave event when the user navigates away from the site, as the information is not lost\n// on an internal navigation, and is included as the $prev_pageview_ properties in the next $pageview event.\n\n// Practically, this means that to find the scroll properties for a given pageview, you need to find the event where\n// event name is $pageview or $pageleave and where $prev_pageview_id matches the original pageview event's id.\n\nexport class PageViewManager {\n _currentPageview?: { timestamp: Date; pageViewId: string | undefined; pathname: string | undefined }\n _instance: PostHog\n private _unsubscribeSessionId?: () => void\n\n constructor(instance: PostHog) {\n this._instance = instance\n this._setupSessionRotationHandler()\n }\n\n private _setupSessionRotationHandler(): void {\n this._unsubscribeSessionId = this._instance.sessionManager?.onSessionId(this._onSessionIdChange)\n }\n\n private _onSessionIdChange: SessionIdChangedCallback = (sessionId, _windowId, changeReason) => {\n // Only act on actual session rotations, not initial session creation\n if (!changeReason) {\n return\n }\n\n // Clear state when session changes for any of these reasons:\n // - noSessionId: after posthog.reset() or forced idle reset\n // - activityTimeout: 30 min idle (default, configurable up to 10 hours)\n // - sessionPastMaximumLength: 24 hour max session\n if (changeReason.noSessionId || changeReason.activityTimeout || changeReason.sessionPastMaximumLength) {\n logger.info('[PageViewManager] Session rotated, clearing pageview state', {\n sessionId,\n changeReason,\n })\n this._currentPageview = undefined\n this._instance.scrollManager.resetContext()\n }\n }\n\n destroy(): void {\n this._unsubscribeSessionId?.()\n this._unsubscribeSessionId = undefined\n }\n\n doPageView(timestamp: Date, pageViewId?: string): PageViewEventProperties {\n const response = this._previousPageViewProperties(timestamp, pageViewId)\n\n // On a pageview we reset the contexts\n this._currentPageview = { pathname: window?.location.pathname ?? '', pageViewId, timestamp }\n this._instance.scrollManager.resetContext()\n\n return response\n }\n\n doPageLeave(timestamp: Date): PageViewEventProperties {\n return this._previousPageViewProperties(timestamp, this._currentPageview?.pageViewId)\n }\n\n doEvent(): PageViewEventProperties {\n return { $pageview_id: this._currentPageview?.pageViewId }\n }\n\n private _previousPageViewProperties(timestamp: Date, pageviewId: string | undefined): PageViewEventProperties {\n const previousPageView = this._currentPageview\n\n if (!previousPageView) {\n return { $pageview_id: pageviewId }\n }\n\n let properties: PageViewEventProperties = {\n $pageview_id: pageviewId,\n $prev_pageview_id: previousPageView.pageViewId,\n }\n\n const scrollContext = this._instance.scrollManager.getContext()\n\n if (scrollContext && !this._instance.config.disable_scroll_properties) {\n let { maxScrollHeight, lastScrollY, maxScrollY, maxContentHeight, lastContentY, maxContentY } =\n scrollContext\n\n if (\n !isUndefined(maxScrollHeight) &&\n !isUndefined(lastScrollY) &&\n !isUndefined(maxScrollY) &&\n !isUndefined(maxContentHeight) &&\n !isUndefined(lastContentY) &&\n !isUndefined(maxContentY)\n ) {\n // Use ceil, so that e.g. scrolling 999.5px of a 1000px page is considered 100% scrolled\n maxScrollHeight = Math.ceil(maxScrollHeight)\n lastScrollY = Math.ceil(lastScrollY)\n maxScrollY = Math.ceil(maxScrollY)\n maxContentHeight = Math.ceil(maxContentHeight)\n lastContentY = Math.ceil(lastContentY)\n maxContentY = Math.ceil(maxContentY)\n\n // if the maximum scroll height is near 0, then the percentage is 1\n const lastScrollPercentage =\n maxScrollHeight <= 1 ? 1 : clampToRange(lastScrollY / maxScrollHeight, 0, 1, logger)\n const maxScrollPercentage =\n maxScrollHeight <= 1 ? 1 : clampToRange(maxScrollY / maxScrollHeight, 0, 1, logger)\n const lastContentPercentage =\n maxContentHeight <= 1 ? 1 : clampToRange(lastContentY / maxContentHeight, 0, 1, logger)\n const maxContentPercentage =\n maxContentHeight <= 1 ? 1 : clampToRange(maxContentY / maxContentHeight, 0, 1, logger)\n\n properties = extend(properties, {\n $prev_pageview_last_scroll: lastScrollY,\n $prev_pageview_last_scroll_percentage: lastScrollPercentage,\n $prev_pageview_max_scroll: maxScrollY,\n $prev_pageview_max_scroll_percentage: maxScrollPercentage,\n $prev_pageview_last_content: lastContentY,\n $prev_pageview_last_content_percentage: lastContentPercentage,\n $prev_pageview_max_content: maxContentY,\n $prev_pageview_max_content_percentage: maxContentPercentage,\n })\n }\n }\n\n if (previousPageView.pathname) {\n properties.$prev_pageview_pathname = previousPageView.pathname\n }\n if (previousPageView.timestamp) {\n // Use seconds, for consistency with our other duration-related properties like $duration\n properties.$prev_pageview_duration = (timestamp.getTime() - previousPageView.timestamp.getTime()) / 1000\n }\n\n return properties\n }\n}\n"]}
|
|
@@ -470,6 +470,45 @@ export declare class PostHog {
|
|
|
470
470
|
* @public
|
|
471
471
|
*/
|
|
472
472
|
reloadFeatureFlags(): void;
|
|
473
|
+
/**
|
|
474
|
+
* Manually update feature flag values without making a network request.
|
|
475
|
+
*
|
|
476
|
+
* This is useful when you have feature flag values from an external source
|
|
477
|
+
* (e.g., server-side evaluation, edge middleware) and want to inject them
|
|
478
|
+
* into the client SDK.
|
|
479
|
+
*
|
|
480
|
+
* {@label Feature flags}
|
|
481
|
+
*
|
|
482
|
+
* @example
|
|
483
|
+
* ```js
|
|
484
|
+
* // Replace all flags with server-evaluated values
|
|
485
|
+
* posthog.updateFlags({
|
|
486
|
+
* 'my-flag': true,
|
|
487
|
+
* 'my-experiment': 'variant-a'
|
|
488
|
+
* })
|
|
489
|
+
*
|
|
490
|
+
* // Merge with existing flags (update only specified flags)
|
|
491
|
+
* posthog.updateFlags(
|
|
492
|
+
* { 'my-flag': true },
|
|
493
|
+
* undefined,
|
|
494
|
+
* { merge: true }
|
|
495
|
+
* )
|
|
496
|
+
*
|
|
497
|
+
* // With payloads
|
|
498
|
+
* posthog.updateFlags(
|
|
499
|
+
* { 'my-flag': true },
|
|
500
|
+
* { 'my-flag': { some: 'data' } }
|
|
501
|
+
* )
|
|
502
|
+
* ```
|
|
503
|
+
*
|
|
504
|
+
* @param flags - An object mapping flag keys to their values (boolean or string variant)
|
|
505
|
+
* @param payloads - Optional object mapping flag keys to their JSON payloads
|
|
506
|
+
* @param options - Optional settings. Use `{ merge: true }` to merge with existing flags instead of replacing.
|
|
507
|
+
* @public
|
|
508
|
+
*/
|
|
509
|
+
updateFlags(flags: Record<string, boolean | string>, payloads?: Record<string, JsonType>, options?: {
|
|
510
|
+
merge?: boolean;
|
|
511
|
+
}): void;
|
|
473
512
|
/**
|
|
474
513
|
* Opt the user in or out of an early access feature. [Learn more in the docs](/docs/feature-flags/early-access-feature-management#option-2-custom-implementation)
|
|
475
514
|
*
|
package/lib/src/posthog-core.js
CHANGED
|
@@ -1375,6 +1375,78 @@ var PostHog = /** @class */ (function () {
|
|
|
1375
1375
|
PostHog.prototype.reloadFeatureFlags = function () {
|
|
1376
1376
|
this.featureFlags.reloadFeatureFlags();
|
|
1377
1377
|
};
|
|
1378
|
+
/**
|
|
1379
|
+
* Manually update feature flag values without making a network request.
|
|
1380
|
+
*
|
|
1381
|
+
* This is useful when you have feature flag values from an external source
|
|
1382
|
+
* (e.g., server-side evaluation, edge middleware) and want to inject them
|
|
1383
|
+
* into the client SDK.
|
|
1384
|
+
*
|
|
1385
|
+
* {@label Feature flags}
|
|
1386
|
+
*
|
|
1387
|
+
* @example
|
|
1388
|
+
* ```js
|
|
1389
|
+
* // Replace all flags with server-evaluated values
|
|
1390
|
+
* posthog.updateFlags({
|
|
1391
|
+
* 'my-flag': true,
|
|
1392
|
+
* 'my-experiment': 'variant-a'
|
|
1393
|
+
* })
|
|
1394
|
+
*
|
|
1395
|
+
* // Merge with existing flags (update only specified flags)
|
|
1396
|
+
* posthog.updateFlags(
|
|
1397
|
+
* { 'my-flag': true },
|
|
1398
|
+
* undefined,
|
|
1399
|
+
* { merge: true }
|
|
1400
|
+
* )
|
|
1401
|
+
*
|
|
1402
|
+
* // With payloads
|
|
1403
|
+
* posthog.updateFlags(
|
|
1404
|
+
* { 'my-flag': true },
|
|
1405
|
+
* { 'my-flag': { some: 'data' } }
|
|
1406
|
+
* )
|
|
1407
|
+
* ```
|
|
1408
|
+
*
|
|
1409
|
+
* @param flags - An object mapping flag keys to their values (boolean or string variant)
|
|
1410
|
+
* @param payloads - Optional object mapping flag keys to their JSON payloads
|
|
1411
|
+
* @param options - Optional settings. Use `{ merge: true }` to merge with existing flags instead of replacing.
|
|
1412
|
+
* @public
|
|
1413
|
+
*/
|
|
1414
|
+
PostHog.prototype.updateFlags = function (flags, payloads, options) {
|
|
1415
|
+
var e_1, _a;
|
|
1416
|
+
// If merging, combine with existing flags
|
|
1417
|
+
var existingFlags = (options === null || options === void 0 ? void 0 : options.merge) ? this.featureFlags.getFlagVariants() : {};
|
|
1418
|
+
var existingPayloads = (options === null || options === void 0 ? void 0 : options.merge) ? this.featureFlags.getFlagPayloads() : {};
|
|
1419
|
+
var finalFlags = __assign(__assign({}, existingFlags), flags);
|
|
1420
|
+
var finalPayloads = __assign(__assign({}, existingPayloads), payloads);
|
|
1421
|
+
// Convert simple flags to v4 format to avoid deprecation warning
|
|
1422
|
+
var flagDetails = {};
|
|
1423
|
+
try {
|
|
1424
|
+
for (var _b = __values(Object.entries(finalFlags)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1425
|
+
var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
|
|
1426
|
+
var isVariant = typeof value === 'string';
|
|
1427
|
+
flagDetails[key] = {
|
|
1428
|
+
key: key,
|
|
1429
|
+
enabled: isVariant ? true : Boolean(value),
|
|
1430
|
+
variant: isVariant ? value : undefined,
|
|
1431
|
+
reason: undefined,
|
|
1432
|
+
// id: 0 indicates manually injected flags (not from server evaluation)
|
|
1433
|
+
metadata: !(0, core_1.isUndefined)(finalPayloads === null || finalPayloads === void 0 ? void 0 : finalPayloads[key])
|
|
1434
|
+
? { id: 0, version: undefined, description: undefined, payload: finalPayloads[key] }
|
|
1435
|
+
: undefined,
|
|
1436
|
+
};
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
1439
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1440
|
+
finally {
|
|
1441
|
+
try {
|
|
1442
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1443
|
+
}
|
|
1444
|
+
finally { if (e_1) throw e_1.error; }
|
|
1445
|
+
}
|
|
1446
|
+
this.featureFlags.receivedFeatureFlags({
|
|
1447
|
+
flags: flagDetails,
|
|
1448
|
+
});
|
|
1449
|
+
};
|
|
1378
1450
|
/**
|
|
1379
1451
|
* Opt the user in or out of an early access feature. [Learn more in the docs](/docs/feature-flags/early-access-feature-management#option-2-custom-implementation)
|
|
1380
1452
|
*
|
|
@@ -2696,7 +2768,7 @@ var PostHog = /** @class */ (function () {
|
|
|
2696
2768
|
* @param {Object} [config.capture_properties] Set of properties to be captured along with the opt-in action
|
|
2697
2769
|
*/
|
|
2698
2770
|
PostHog.prototype.opt_in_capturing = function (options) {
|
|
2699
|
-
var _a, _b, _c;
|
|
2771
|
+
var _a, _b, _c, _d;
|
|
2700
2772
|
if (this.config.cookieless_mode === 'always') {
|
|
2701
2773
|
logger_1.logger.warn('Consent opt in/out is not valid with cookieless_mode="always" and will be ignored');
|
|
2702
2774
|
return;
|
|
@@ -2706,7 +2778,9 @@ var PostHog = /** @class */ (function () {
|
|
|
2706
2778
|
// we need to reset the instance to ensure that there is no leaking of state or data between the cookieless and regular events
|
|
2707
2779
|
this.reset(true);
|
|
2708
2780
|
(_a = this.sessionManager) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
2781
|
+
(_b = this.pageViewManager) === null || _b === void 0 ? void 0 : _b.destroy();
|
|
2709
2782
|
this.sessionManager = new sessionid_1.SessionIdManager(this);
|
|
2783
|
+
this.pageViewManager = new page_view_1.PageViewManager(this);
|
|
2710
2784
|
if (this.persistence) {
|
|
2711
2785
|
this.sessionPropsManager = new session_props_1.SessionPropsManager(this, this.sessionManager, this.persistence);
|
|
2712
2786
|
}
|
|
@@ -2719,14 +2793,14 @@ var PostHog = /** @class */ (function () {
|
|
|
2719
2793
|
this._start_queue_if_opted_in();
|
|
2720
2794
|
// Restart session recording if it should now be enabled
|
|
2721
2795
|
// (this handles the case where opt_out_capturing_by_default or cookieless_mode prevented it from starting)
|
|
2722
|
-
(
|
|
2796
|
+
(_c = this.sessionRecording) === null || _c === void 0 ? void 0 : _c.startIfEnabledOrStop();
|
|
2723
2797
|
// Reinitialize surveys if we're in cookieless mode and just opted in
|
|
2724
2798
|
if (this.config.cookieless_mode == 'on_reject') {
|
|
2725
2799
|
this.surveys.loadIfEnabled();
|
|
2726
2800
|
}
|
|
2727
2801
|
// Don't capture if captureEventName is null or false
|
|
2728
2802
|
if ((0, core_1.isUndefined)(options === null || options === void 0 ? void 0 : options.captureEventName) || (options === null || options === void 0 ? void 0 : options.captureEventName)) {
|
|
2729
|
-
this.capture((
|
|
2803
|
+
this.capture((_d = options === null || options === void 0 ? void 0 : options.captureEventName) !== null && _d !== void 0 ? _d : '$opt_in', options === null || options === void 0 ? void 0 : options.captureProperties, { send_instantly: true });
|
|
2730
2804
|
}
|
|
2731
2805
|
if (this.config.capture_pageview) {
|
|
2732
2806
|
this._captureInitialPageview();
|
|
@@ -2750,7 +2824,7 @@ var PostHog = /** @class */ (function () {
|
|
|
2750
2824
|
* @public
|
|
2751
2825
|
*/
|
|
2752
2826
|
PostHog.prototype.opt_out_capturing = function () {
|
|
2753
|
-
var _a, _b;
|
|
2827
|
+
var _a, _b, _c;
|
|
2754
2828
|
if (this.config.cookieless_mode === 'always') {
|
|
2755
2829
|
logger_1.logger.warn('Consent opt in/out is not valid with cookieless_mode="always" and will be ignored');
|
|
2756
2830
|
return;
|
|
@@ -2768,9 +2842,10 @@ var PostHog = /** @class */ (function () {
|
|
|
2768
2842
|
$device_id: null,
|
|
2769
2843
|
});
|
|
2770
2844
|
(_a = this.sessionManager) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
2845
|
+
(_b = this.pageViewManager) === null || _b === void 0 ? void 0 : _b.destroy();
|
|
2771
2846
|
this.sessionManager = undefined;
|
|
2772
2847
|
this.sessionPropsManager = undefined;
|
|
2773
|
-
(
|
|
2848
|
+
(_c = this.sessionRecording) === null || _c === void 0 ? void 0 : _c.stopRecording();
|
|
2774
2849
|
this.sessionRecording = undefined;
|
|
2775
2850
|
this._captureInitialPageview();
|
|
2776
2851
|
}
|
|
@@ -2980,7 +3055,7 @@ var PostHog = /** @class */ (function () {
|
|
|
2980
3055
|
return (0, utils_1.migrateConfigField)(originalConfig, 'advanced_disable_flags', 'advanced_disable_decide', false, logger_1.logger);
|
|
2981
3056
|
};
|
|
2982
3057
|
PostHog.prototype._runBeforeSend = function (data) {
|
|
2983
|
-
var
|
|
3058
|
+
var e_2, _a;
|
|
2984
3059
|
if ((0, core_1.isNullish)(this.config.before_send)) {
|
|
2985
3060
|
return data;
|
|
2986
3061
|
}
|
|
@@ -3005,12 +3080,12 @@ var PostHog = /** @class */ (function () {
|
|
|
3005
3080
|
}
|
|
3006
3081
|
}
|
|
3007
3082
|
}
|
|
3008
|
-
catch (
|
|
3083
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
3009
3084
|
finally {
|
|
3010
3085
|
try {
|
|
3011
3086
|
if (fns_1_1 && !fns_1_1.done && (_a = fns_1.return)) _a.call(fns_1);
|
|
3012
3087
|
}
|
|
3013
|
-
finally { if (
|
|
3088
|
+
finally { if (e_2) throw e_2.error; }
|
|
3014
3089
|
}
|
|
3015
3090
|
return beforeSendResult;
|
|
3016
3091
|
};
|