posthog-js
Advanced tools
Comparing version 1.163.1 to 1.164.0
@@ -1,1 +0,2 @@ | ||
export {}; | ||
import './external-scripts-loader'; | ||
import './array.no-external'; |
@@ -1,5 +0,2 @@ | ||
import './recorder'; | ||
import './surveys'; | ||
import './exception-autocapture'; | ||
import './tracing-headers'; | ||
import './web-vitals'; | ||
import './all-external-dependencies'; | ||
import './array'; |
@@ -0,1 +1,2 @@ | ||
import './external-scripts-loader'; | ||
export { PostHog } from '../posthog-core'; | ||
@@ -2,0 +3,0 @@ export * from '../types'; |
@@ -1,5 +0,4 @@ | ||
export { PostHog } from '../posthog-core'; | ||
export * from '../types'; | ||
export * from '../posthog-surveys-types'; | ||
export declare const posthog: import("../posthog-core").PostHog; | ||
import './external-scripts-loader'; | ||
import posthog from './module.no-external.es'; | ||
export * from './module.no-external.es'; | ||
export default posthog; |
@@ -0,4 +1,4 @@ | ||
import type { PostHog } from '../posthog-core'; | ||
import { SessionIdManager } from '../sessionid'; | ||
import { ErrorEventArgs, ErrorProperties, Properties } from '../types'; | ||
import { PostHog } from '../posthog-core'; | ||
declare const win: (Window & typeof globalThis) | undefined; | ||
@@ -9,3 +9,6 @@ /** | ||
*/ | ||
interface PosthogExtensions { | ||
export type PostHogExtensionKind = 'toolbar' | 'exception-autocapture' | 'web-vitals' | 'recorder' | 'tracing-headers' | 'surveys'; | ||
interface PostHogExtensions { | ||
loadExternalDependency?: (posthog: PostHog, kind: PostHogExtensionKind, callback: (error?: string | Event, event?: Event) => void) => void; | ||
loadSiteApp?: (posthog: PostHog, appUrl: string, callback: (error?: string | Event, event?: Event) => void) => void; | ||
parseErrorAsProperties?: ([event, source, lineno, colno, error]: ErrorEventArgs) => ErrorProperties; | ||
@@ -60,4 +63,4 @@ errorWrappingFunctions?: { | ||
export declare const assignableWindow: Window & typeof globalThis & Record<string, any> & { | ||
__PosthogExtensions__?: PosthogExtensions; | ||
__PosthogExtensions__?: PostHogExtensions; | ||
}; | ||
export { win as window }; |
@@ -21,3 +21,2 @@ import { PostHog } from '../posthog-core'; | ||
endpointFor(target: RequestRouterTarget, path?: string): string; | ||
loadScript(scriptUrlToLoad: string, callback: (error?: string | Event, event?: Event) => void): void; | ||
} |
{ | ||
"name": "posthog-js", | ||
"version": "1.163.1", | ||
"version": "1.164.0", | ||
"description": "Posthog-js allows you to automatically capture usage and send events to PostHog.", | ||
@@ -14,4 +14,5 @@ "repository": "https://github.com/PostHog/posthog-js", | ||
"lint": "eslint src && eslint cypress", | ||
"lint:fix": "eslint src --fix && eslint cypress --fix", | ||
"prettier": "prettier --write src/ functional_tests/", | ||
"prepublishOnly": "pnpm lint && pnpm test && pnpm build && pnpm test:react", | ||
"prepublishOnly": "pnpm lint && pnpm build && pnpm test && pnpm test:react", | ||
"test": "pnpm test:unit && pnpm test:custom-eslint-rules && pnpm test:functional", | ||
@@ -104,2 +105,3 @@ "test:unit": "jest src", | ||
"rollup-plugin-dts": "^6.1.0", | ||
"rollup-plugin-ts": "^3.4.5", | ||
"rollup-plugin-visualizer": "^5.12.0", | ||
@@ -111,4 +113,4 @@ "rrweb": "2.0.0-alpha.13", | ||
"testcafe-browser-provider-browserstack": "1.14.0", | ||
"ts-node": "^10.9.2", | ||
"tslib": "^2.5.0", | ||
"ts-node": "^10.9.2", | ||
"typescript": "^5.5.4", | ||
@@ -115,0 +117,0 @@ "yargs": "^17.7.2" |
@@ -49,2 +49,3 @@ var __values = (this && this.__values) || function(o) { | ||
var _this = this; | ||
var _b, _c; | ||
this.instance.featureFlags.setReloadingPaused(false); | ||
@@ -73,5 +74,4 @@ // :TRICKY: Reload - start another request if queued! | ||
var _loop_1 = function (id, url) { | ||
var scriptUrl = this_1.instance.requestRouter.endpointFor('api', url); | ||
assignableWindow["__$$ph_site_app_".concat(id)] = this_1.instance; | ||
this_1.instance.requestRouter.loadScript(scriptUrl, function (err) { | ||
(_c = (_b = assignableWindow.__PosthogExtensions__) === null || _b === void 0 ? void 0 : _b.loadSiteApp) === null || _c === void 0 ? void 0 : _c.call(_b, this_1.instance, url, function (err) { | ||
if (err) { | ||
@@ -84,4 +84,4 @@ return logger.error("Error while initializing PostHog app with config id ".concat(id), err); | ||
try { | ||
for (var _b = __values(response['siteApps']), _c = _b.next(); !_c.done; _c = _b.next()) { | ||
var _d = _c.value, id = _d.id, url = _d.url; | ||
for (var _d = __values(response['siteApps']), _e = _d.next(); !_e.done; _e = _d.next()) { | ||
var _f = _e.value, id = _f.id, url = _f.url; | ||
_loop_1(id, url); | ||
@@ -93,3 +93,3 @@ } | ||
try { | ||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); | ||
if (_e && !_e.done && (_a = _d.return)) _a.call(_d); | ||
} | ||
@@ -96,0 +96,0 @@ finally { if (e_1) throw e_1.error; } |
@@ -1,1 +0,2 @@ | ||
export {}; | ||
import './external-scripts-loader'; | ||
import './array.no-external'; |
@@ -1,5 +0,2 @@ | ||
import './recorder'; | ||
import './surveys'; | ||
import './exception-autocapture'; | ||
import './tracing-headers'; | ||
import './web-vitals'; | ||
import './all-external-dependencies'; | ||
import './array'; |
// Same as loader-globals.ts except includes all additional extension loaders | ||
import './recorder'; | ||
import './surveys'; | ||
import './exception-autocapture'; | ||
import './tracing-headers'; | ||
import './web-vitals'; | ||
import { init_from_snippet } from '../posthog-core'; | ||
init_from_snippet(); | ||
import './all-external-dependencies'; | ||
import './array'; | ||
//# sourceMappingURL=array.full.js.map |
@@ -1,3 +0,3 @@ | ||
import { init_from_snippet } from '../posthog-core'; | ||
init_from_snippet(); | ||
import './external-scripts-loader'; | ||
import './array.no-external'; | ||
//# sourceMappingURL=array.js.map |
@@ -0,1 +1,2 @@ | ||
import './external-scripts-loader'; | ||
export { PostHog } from '../posthog-core'; | ||
@@ -2,0 +3,0 @@ export * from '../types'; |
@@ -0,1 +1,2 @@ | ||
import './external-scripts-loader'; | ||
import { init_as_module } from '../posthog-core'; | ||
@@ -2,0 +3,0 @@ export { PostHog } from '../posthog-core'; |
@@ -1,5 +0,4 @@ | ||
export { PostHog } from '../posthog-core'; | ||
export * from '../types'; | ||
export * from '../posthog-surveys-types'; | ||
export declare const posthog: import("../posthog-core").PostHog; | ||
import './external-scripts-loader'; | ||
import posthog from './module.no-external.es'; | ||
export * from './module.no-external.es'; | ||
export default posthog; |
@@ -1,7 +0,5 @@ | ||
import { init_as_module } from '../posthog-core'; | ||
export { PostHog } from '../posthog-core'; | ||
export * from '../types'; | ||
export * from '../posthog-surveys-types'; | ||
export var posthog = init_as_module(); | ||
import './external-scripts-loader'; | ||
import posthog from './module.no-external.es'; | ||
export * from './module.no-external.es'; | ||
export default posthog; | ||
//# sourceMappingURL=module.es.js.map |
import { assignableWindow, window } from '../../utils/globals'; | ||
import { logger } from '../../utils/logger'; | ||
import { EXCEPTION_CAPTURE_ENABLED_SERVER_SIDE } from '../../constants'; | ||
import Config from '../../config'; | ||
var LOGGER_PREFIX = '[Exception Autocapture]'; | ||
@@ -65,2 +64,3 @@ var ExceptionObserver = /** @class */ (function () { | ||
ExceptionObserver.prototype.loadScript = function (cb) { | ||
var _a, _b; | ||
if (this.hasHandlers) { | ||
@@ -70,3 +70,3 @@ // already loaded | ||
} | ||
this.instance.requestRouter.loadScript("/static/exception-autocapture.js?v=".concat(Config.LIB_VERSION), function (err) { | ||
(_b = (_a = assignableWindow.__PosthogExtensions__) === null || _a === void 0 ? void 0 : _a.loadExternalDependency) === null || _b === void 0 ? void 0 : _b.call(_a, this.instance, 'exception-autocapture', function (err) { | ||
if (err) { | ||
@@ -73,0 +73,0 @@ return logger.error(LOGGER_PREFIX + ' failed to load script', err); |
@@ -51,3 +51,2 @@ var __assign = (this && this.__assign) || function () { | ||
import { EventType, IncrementalSource } from '@rrweb/types'; | ||
import Config from '../../config'; | ||
import { timestamp } from '../../utils'; | ||
@@ -480,2 +479,3 @@ import { isBoolean, isFunction, isNullish, isNumber, isObject, isString, isUndefined } from '../../utils/type-utils'; | ||
var _this = this; | ||
var _a, _b; | ||
if (isUndefined(Object.assign)) { | ||
@@ -504,5 +504,5 @@ // According to the rrweb docs, rrweb is not supported on IE11 and below: | ||
if (!this.rrwebRecord) { | ||
this.instance.requestRouter.loadScript("/static/recorder.js?v=".concat(Config.LIB_VERSION), function (err) { | ||
(_b = (_a = assignableWindow.__PosthogExtensions__) === null || _a === void 0 ? void 0 : _a.loadExternalDependency) === null || _b === void 0 ? void 0 : _b.call(_a, this.instance, 'recorder', function (err) { | ||
if (err) { | ||
return logger.error(LOGGER_PREFIX + " could not load recorder.js", err); | ||
return logger.error(LOGGER_PREFIX + " could not load recorder", err); | ||
} | ||
@@ -509,0 +509,0 @@ _this._onScriptLoaded(); |
@@ -126,2 +126,3 @@ var __assign = (this && this.__assign) || function () { | ||
var _this = this; | ||
var _a, _b; | ||
var toolbarRunning = !!(document === null || document === void 0 ? void 0 : document.getElementById(TOOLBAR_ID)); | ||
@@ -141,8 +142,3 @@ if (!window || toolbarRunning) { | ||
this.setToolbarState(ToolbarState.LOADING); | ||
// toolbar.js is served from the PostHog CDN, this has a TTL of 24 hours. | ||
// the toolbar asset includes a rotating "token" that is valid for 5 minutes. | ||
var fiveMinutesInMillis = 5 * 60 * 1000; | ||
// this ensures that we bust the cache periodically | ||
var timestampToNearestFiveMinutes = Math.floor(Date.now() / fiveMinutesInMillis) * fiveMinutesInMillis; | ||
this.instance.requestRouter.loadScript("/static/toolbar.js?t=".concat(timestampToNearestFiveMinutes), function (err) { | ||
(_b = (_a = assignableWindow.__PosthogExtensions__) === null || _a === void 0 ? void 0 : _a.loadExternalDependency) === null || _b === void 0 ? void 0 : _b.call(_a, this.instance, 'toolbar', function (err) { | ||
if (err) { | ||
@@ -149,0 +145,0 @@ logger.error('Failed to load toolbar', err); |
import { assignableWindow } from '../utils/globals'; | ||
import { logger } from '../utils/logger'; | ||
import Config from '../config'; | ||
import { isUndefined } from '../utils/type-utils'; | ||
@@ -24,3 +23,3 @@ var LOGGER_PREFIX = '[TRACING-HEADERS]'; | ||
TracingHeaders.prototype._loadScript = function (cb) { | ||
var _a; | ||
var _a, _b, _c; | ||
if ((_a = assignableWindow.__PosthogExtensions__) === null || _a === void 0 ? void 0 : _a.tracingHeadersPatchFns) { | ||
@@ -30,3 +29,3 @@ // already loaded | ||
} | ||
this.instance.requestRouter.loadScript("/static/tracing-headers.js?v=".concat(Config.LIB_VERSION), function (err) { | ||
(_c = (_b = assignableWindow.__PosthogExtensions__) === null || _b === void 0 ? void 0 : _b.loadExternalDependency) === null || _c === void 0 ? void 0 : _c.call(_b, this.instance, 'tracing-headers', function (err) { | ||
if (err) { | ||
@@ -33,0 +32,0 @@ return logger.error(LOGGER_PREFIX + ' failed to load script', err); |
@@ -16,3 +16,2 @@ var __assign = (this && this.__assign) || function () { | ||
import { assignableWindow, window } from '../../utils/globals'; | ||
import Config from '../../config'; | ||
export var FLUSH_TO_CAPTURE_TIMEOUT_MILLISECONDS = 8000; | ||
@@ -178,3 +177,3 @@ var ONE_MINUTE_IN_MILLIS = 60 * 1000; | ||
WebVitalsAutocapture.prototype.loadScript = function (cb) { | ||
var _a; | ||
var _a, _b, _c; | ||
if ((_a = assignableWindow.__PosthogExtensions__) === null || _a === void 0 ? void 0 : _a.postHogWebVitalsCallbacks) { | ||
@@ -184,3 +183,3 @@ // already loaded | ||
} | ||
this.instance.requestRouter.loadScript("/static/web-vitals.js?v=".concat(Config.LIB_VERSION), function (err) { | ||
(_c = (_b = assignableWindow.__PosthogExtensions__) === null || _b === void 0 ? void 0 : _b.loadExternalDependency) === null || _c === void 0 ? void 0 : _c.call(_b, this.instance, 'web-vitals', function (err) { | ||
if (err) { | ||
@@ -187,0 +186,0 @@ logger.error(LOGGER_PREFIX + ' failed to load script', err); |
@@ -61,3 +61,3 @@ import { SURVEYS } from './constants'; | ||
var _this = this; | ||
var _a; | ||
var _a, _b, _c; | ||
var surveysGenerator = (_a = assignableWindow === null || assignableWindow === void 0 ? void 0 : assignableWindow.__PosthogExtensions__) === null || _a === void 0 ? void 0 : _a.generateSurveys; | ||
@@ -68,3 +68,3 @@ if (!this.instance.config.disable_surveys && this._decideServerResponse && !surveysGenerator) { | ||
} | ||
this.instance.requestRouter.loadScript('/static/surveys.js', function (err) { | ||
(_c = (_b = assignableWindow.__PosthogExtensions__) === null || _b === void 0 ? void 0 : _b.loadExternalDependency) === null || _c === void 0 ? void 0 : _c.call(_b, this.instance, 'surveys', function (err) { | ||
var _a, _b; | ||
@@ -71,0 +71,0 @@ if (err) { |
@@ -0,4 +1,4 @@ | ||
import type { PostHog } from '../posthog-core'; | ||
import { SessionIdManager } from '../sessionid'; | ||
import { ErrorEventArgs, ErrorProperties, Properties } from '../types'; | ||
import { PostHog } from '../posthog-core'; | ||
declare const win: (Window & typeof globalThis) | undefined; | ||
@@ -9,3 +9,6 @@ /** | ||
*/ | ||
interface PosthogExtensions { | ||
export type PostHogExtensionKind = 'toolbar' | 'exception-autocapture' | 'web-vitals' | 'recorder' | 'tracing-headers' | 'surveys'; | ||
interface PostHogExtensions { | ||
loadExternalDependency?: (posthog: PostHog, kind: PostHogExtensionKind, callback: (error?: string | Event, event?: Event) => void) => void; | ||
loadSiteApp?: (posthog: PostHog, appUrl: string, callback: (error?: string | Event, event?: Event) => void) => void; | ||
parseErrorAsProperties?: ([event, source, lineno, colno, error]: ErrorEventArgs) => ErrorProperties; | ||
@@ -60,4 +63,4 @@ errorWrappingFunctions?: { | ||
export declare const assignableWindow: Window & typeof globalThis & Record<string, any> & { | ||
__PosthogExtensions__?: PosthogExtensions; | ||
__PosthogExtensions__?: PostHogExtensions; | ||
}; | ||
export { win as window }; |
@@ -21,3 +21,2 @@ import { PostHog } from '../posthog-core'; | ||
endpointFor(target: RequestRouterTarget, path?: string): string; | ||
loadScript(scriptUrlToLoad: string, callback: (error?: string | Event, event?: Event) => void): void; | ||
} |
@@ -1,3 +0,1 @@ | ||
import { document } from '../utils/globals'; | ||
import { logger } from './logger'; | ||
/** | ||
@@ -86,34 +84,2 @@ * The request router helps simplify the logic to determine which endpoints should be called for which things | ||
}; | ||
RequestRouter.prototype.loadScript = function (scriptUrlToLoad, callback) { | ||
if (this.instance.config.disable_external_dependency_loading) { | ||
logger.warn("".concat(scriptUrlToLoad, " was requested but loading of external scripts is disabled.")); | ||
return callback('Loading of external scripts is disabled'); | ||
} | ||
var url = scriptUrlToLoad[0] === '/' ? this.endpointFor('assets', scriptUrlToLoad) : scriptUrlToLoad; | ||
var addScript = function () { | ||
var _a; | ||
if (!document) { | ||
return callback('document not found'); | ||
} | ||
var scriptTag = document.createElement('script'); | ||
scriptTag.type = 'text/javascript'; | ||
scriptTag.src = url; | ||
scriptTag.onload = function (event) { return callback(undefined, event); }; | ||
scriptTag.onerror = function (error) { return callback(error); }; | ||
var scripts = document.querySelectorAll('body > script'); | ||
if (scripts.length > 0) { | ||
(_a = scripts[0].parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(scriptTag, scripts[0]); | ||
} | ||
else { | ||
// In exceptional situations this call might load before the DOM is fully ready. | ||
document.body.appendChild(scriptTag); | ||
} | ||
}; | ||
if (document === null || document === void 0 ? void 0 : document.body) { | ||
addScript(); | ||
} | ||
else { | ||
document === null || document === void 0 ? void 0 : document.addEventListener('DOMContentLoaded', addScript); | ||
} | ||
}; | ||
return RequestRouter; | ||
@@ -120,0 +86,0 @@ }()); |
{ | ||
"name": "posthog-js", | ||
"version": "1.163.1", | ||
"version": "1.164.0", | ||
"description": "Posthog-js allows you to automatically capture usage and send events to PostHog.", | ||
@@ -14,4 +14,5 @@ "repository": "https://github.com/PostHog/posthog-js", | ||
"lint": "eslint src && eslint cypress", | ||
"lint:fix": "eslint src --fix && eslint cypress --fix", | ||
"prettier": "prettier --write src/ functional_tests/", | ||
"prepublishOnly": "pnpm lint && pnpm test && pnpm build && pnpm test:react", | ||
"prepublishOnly": "pnpm lint && pnpm build && pnpm test && pnpm test:react", | ||
"test": "pnpm test:unit && pnpm test:custom-eslint-rules && pnpm test:functional", | ||
@@ -104,2 +105,3 @@ "test:unit": "jest src", | ||
"rollup-plugin-dts": "^6.1.0", | ||
"rollup-plugin-ts": "^3.4.5", | ||
"rollup-plugin-visualizer": "^5.12.0", | ||
@@ -111,4 +113,4 @@ "rrweb": "2.0.0-alpha.13", | ||
"testcafe-browser-provider-browserstack": "1.14.0", | ||
"ts-node": "^10.9.2", | ||
"tslib": "^2.5.0", | ||
"ts-node": "^10.9.2", | ||
"typescript": "^5.5.4", | ||
@@ -115,0 +117,0 @@ "yargs": "^17.7.2" |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16383228
400
38487
69