posthog-js 1.24.0 → 1.25.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/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## 1.25.0 - 2022-06-28
2
+
3
+ - feat(feature-flags): Enable experience continuity (#404)
4
+ - chore: Update changelog for 1.24.0 (#411)
5
+
6
+ ## 1.24.0 - 2022-06-01
7
+
8
+ - feat: Limit session recordings to 24 hours (#405)
9
+ - a new recording is immediately started and no data is lost
10
+
1
11
  ## 1.23.0 - 2022-06-01
2
12
 
3
13
  - feat: Allow overriding device id generation (#401)
package/dist/array.js CHANGED
@@ -1,7 +1,7 @@
1
1
  parcelRequire=function(e,r,t,n){var i,o="function"==typeof parcelRequire&&parcelRequire,u="function"==typeof require&&require;function f(t,n){if(!r[t]){if(!e[t]){var i="function"==typeof parcelRequire&&parcelRequire;if(!n&&i)return i(t,!0);if(o)return o(t,!0);if(u&&"string"==typeof t)return u(t);var c=new Error("Cannot find module '"+t+"'");throw c.code="MODULE_NOT_FOUND",c}p.resolve=function(r){return e[t][1][r]||r},p.cache={};var l=r[t]=new f.Module(t);e[t][0].call(l.exports,p,l,l.exports,this)}return r[t].exports;function p(e){return f(p.resolve(e))}}f.isParcelRequire=!0,f.Module=function(e){this.id=e,this.bundle=f,this.exports={}},f.modules=e,f.cache=r,f.parent=o,f.register=function(r,t){e[r]=[function(e,r){r.exports=t},{}]};for(var c=0;c<t.length;c++)try{f(t[c])}catch(e){i||(i=e)}if(t.length){var l=f(t[t.length-1]);"object"==typeof exports&&"undefined"!=typeof module?module.exports=l:"function"==typeof define&&define.amd?define(function(){return l}):n&&(this[n]=l)}if(parcelRequire=f,i)throw i;return f}({"zdbk":[function(require,module,exports) {
2
2
  "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LZString=void 0;var o=String.fromCharCode,r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$",n={};function t(o,r){if(!n[o]){n[o]={};for(var e=0;e<o.length;e++)n[o][o.charAt(e)]=e}return n[o][r]}var s={compressToBase64:function(o){if(null==o)return"";var e=s._compress(o,6,function(o){return r.charAt(o)});switch(e.length%4){default:case 0:return e;case 1:return e+"===";case 2:return e+"==";case 3:return e+"="}},decompressFromBase64:function(o){return null==o?"":""==o?null:s._decompress(o.length,32,function(e){return t(r,o.charAt(e))})},compressToUTF16:function(r){return null==r?"":s._compress(r,15,function(r){return o(r+32)})+" "},decompressFromUTF16:function(o){return null==o?"":""==o?null:s._decompress(o.length,16384,function(r){return o.charCodeAt(r)-32})},compressToUint8Array:function(o){for(var r=s.compress(o),e=new Uint8Array(2*r.length),n=0,t=r.length;n<t;n++){var i=r.charCodeAt(n);e[2*n]=i>>>8,e[2*n+1]=i%256}return e},decompressFromUint8Array:function(r){if(null==r)return s.decompress(r);for(var e=new Array(r.length/2),n=0,t=e.length;n<t;n++)e[n]=256*r[2*n]+r[2*n+1];var i=[];return e.forEach(function(r){i.push(o(r))}),s.decompress(i.join(""))},compressToEncodedURIComponent:function(o){return null==o?"":s._compress(o,6,function(o){return e.charAt(o)})},decompressFromEncodedURIComponent:function(o){return null==o?"":""==o?null:(o=o.replace(/ /g,"+"),s._decompress(o.length,32,function(r){return t(e,o.charAt(r))}))},compress:function(r){return s._compress(r,16,function(r){return o(r)})},_compress:function(o,r,e){if(null==o)return"";var n,t,s,i={},p={},c="",a="",u="",l=2,f=3,h=2,d=[],m=0,v=0;for(s=0;s<o.length;s+=1)if(c=o.charAt(s),Object.prototype.hasOwnProperty.call(i,c)||(i[c]=f++,p[c]=!0),a=u+c,Object.prototype.hasOwnProperty.call(i,a))u=a;else{if(Object.prototype.hasOwnProperty.call(p,u)){if(u.charCodeAt(0)<256){for(n=0;n<h;n++)m<<=1,v==r-1?(v=0,d.push(e(m)),m=0):v++;for(t=u.charCodeAt(0),n=0;n<8;n++)m=m<<1|1&t,v==r-1?(v=0,d.push(e(m)),m=0):v++,t>>=1}else{for(t=1,n=0;n<h;n++)m=m<<1|t,v==r-1?(v=0,d.push(e(m)),m=0):v++,t=0;for(t=u.charCodeAt(0),n=0;n<16;n++)m=m<<1|1&t,v==r-1?(v=0,d.push(e(m)),m=0):v++,t>>=1}0==--l&&(l=Math.pow(2,h),h++),delete p[u]}else for(t=i[u],n=0;n<h;n++)m=m<<1|1&t,v==r-1?(v=0,d.push(e(m)),m=0):v++,t>>=1;0==--l&&(l=Math.pow(2,h),h++),i[a]=f++,u=String(c)}if(""!==u){if(Object.prototype.hasOwnProperty.call(p,u)){if(u.charCodeAt(0)<256){for(n=0;n<h;n++)m<<=1,v==r-1?(v=0,d.push(e(m)),m=0):v++;for(t=u.charCodeAt(0),n=0;n<8;n++)m=m<<1|1&t,v==r-1?(v=0,d.push(e(m)),m=0):v++,t>>=1}else{for(t=1,n=0;n<h;n++)m=m<<1|t,v==r-1?(v=0,d.push(e(m)),m=0):v++,t=0;for(t=u.charCodeAt(0),n=0;n<16;n++)m=m<<1|1&t,v==r-1?(v=0,d.push(e(m)),m=0):v++,t>>=1}0==--l&&(l=Math.pow(2,h),h++),delete p[u]}else for(t=i[u],n=0;n<h;n++)m=m<<1|1&t,v==r-1?(v=0,d.push(e(m)),m=0):v++,t>>=1;0==--l&&(l=Math.pow(2,h),h++)}for(t=2,n=0;n<h;n++)m=m<<1|1&t,v==r-1?(v=0,d.push(e(m)),m=0):v++,t>>=1;for(;;){if(m<<=1,v==r-1){d.push(e(m));break}v++}return d.join("")},decompress:function(o){return null==o?"":""==o?null:s._decompress(o.length,32768,function(r){return o.charCodeAt(r)})},_decompress:function(r,e,n){var t,s,i,p,c,a,u,l=[],f=4,h=4,d=3,m="",v=[],w={val:n(0),position:e,index:1};for(t=0;t<3;t+=1)l[t]=t;for(i=0,c=Math.pow(2,2),a=1;a!=c;)p=w.val&w.position,w.position>>=1,0==w.position&&(w.position=e,w.val=n(w.index++)),i|=(p>0?1:0)*a,a<<=1;switch(i){case 0:for(i=0,c=Math.pow(2,8),a=1;a!=c;)p=w.val&w.position,w.position>>=1,0==w.position&&(w.position=e,w.val=n(w.index++)),i|=(p>0?1:0)*a,a<<=1;u=o(i);break;case 1:for(i=0,c=Math.pow(2,16),a=1;a!=c;)p=w.val&w.position,w.position>>=1,0==w.position&&(w.position=e,w.val=n(w.index++)),i|=(p>0?1:0)*a,a<<=1;u=o(i);break;case 2:return""}for(l[3]=u,s=u,v.push(u);;){if(w.index>r)return"";for(i=0,c=Math.pow(2,d),a=1;a!=c;)p=w.val&w.position,w.position>>=1,0==w.position&&(w.position=e,w.val=n(w.index++)),i|=(p>0?1:0)*a,a<<=1;switch(u=i){case 0:for(i=0,c=Math.pow(2,8),a=1;a!=c;)p=w.val&w.position,w.position>>=1,0==w.position&&(w.position=e,w.val=n(w.index++)),i|=(p>0?1:0)*a,a<<=1;l[h++]=o(i),u=h-1,f--;break;case 1:for(i=0,c=Math.pow(2,16),a=1;a!=c;)p=w.val&w.position,w.position>>=1,0==w.position&&(w.position=e,w.val=n(w.index++)),i|=(p>0?1:0)*a,a<<=1;l[h++]=o(i),u=h-1,f--;break;case 2:return v.join("")}if(0==f&&(f=Math.pow(2,d),d++),l[u])m=l[u];else{if(u!==h)return null;m=s+s.charAt(0)}v.push(m),l[h++]=s+m.charAt(0),s=m,0==--f&&(f=Math.pow(2,d),d++)}}};exports.LZString=s;
3
3
  },{}],"EHrm":[function(require,module,exports) {
4
- module.exports={name:"posthog-js",version:"1.24.0",description:"Posthog-js allows you to automatically capture usage and send events to PostHog.",repository:"https://github.com/PostHog/posthog-js",author:"hey@posthog.com",license:"MIT",scripts:{start:"parcel watch src/loader-globals.js --out-file dist/array.js",serve:"parcel serve src/loader-globals.js --port 3001 --out-file dist/array.js",build:"yarn build-array && yarn build-module && yarn build-es-module && yarn process-types && yarn build-react","build-array":"parcel build src/loader-globals.js --out-file dist/array.js --no-source-maps","build-module":"rollup -i src/loader-module.js -f cjs -o dist/module.js -c rollup.config.js","build-es-module":"rollup -i src/loader-module.js -f es -o dist/es.js -c rollup.config.js","build-react":"cd react; yarn; yarn build;","process-types":"mkdir -p dist; eslint src --ext .ts -c .eslintrc.ts.js --fix && tsc && cp -f src/*.d.ts dist/",lint:"eslint src --fix",prepublishOnly:"yarn lint && yarn test && yarn build && yarn test-react",test:"jest src","test-react":"cd react; yarn test","test-watch":"jest --watch src",cypress:"cypress open"},main:"dist/module.js",module:"dist/es.js",files:["dist/*","react/dist/*"],dependencies:{"@sentry/types":"^6.11.0",fflate:"^0.4.1","rrweb-snapshot":"^1.1.14"},devDependencies:{"@babel/core":"7.12.10","@babel/preset-env":"7.12.11","@rollup/plugin-babel":"^5.2.1","@rollup/plugin-json":"^4.1.0","@rollup/plugin-node-resolve":"^8.1.0","@typescript-eslint/eslint-plugin":"^3.5.0","@typescript-eslint/parser":"^3.5.0","babel-eslint":"10.1.0","babel-jest":"^26.6.3",cypress:"^9.2.0",eslint:"7.3.1","eslint-plugin-prettier":"^3.1.4","eslint-plugin-react":"^7.21.5","eslint-plugin-react-hooks":"^4.2.0","fast-check":"^2.17.0",given2:"^2.1.7",husky:"^4.2.5",jest:"^27.5.1",jsdom:"16.2.2","jsdom-global":"3.0.2","lint-staged":"^10.2.11",localStorage:"1.0.4","node-fetch":"^2.6.1",parcel:"^1.12.4","posthog-js":"link:.",prettier:"^2.0.5",rollup:"^2.18.2",rrweb:"^1.1.3",sinon:"9.0.2",testcafe:"^1.19.0","testcafe-browser-provider-browserstack":"^1.14.0",typescript:"^3.9.6"},husky:{hooks:{"pre-commit":"lint-staged"}},"lint-staged":{"*.{ts,tsx,js,json}":"prettier --write","*.{ts,tsx}":["eslint -c .eslintrc.ts.js --fix","tsc --noEmit --esModuleInterop --jsx react"]},jest:{testPathIgnorePatterns:["/node_modules/","/cypress/","/react/","/test_data/"],moduleFileExtensions:["js","json"],setupFilesAfterEnv:["given2/setup","./src/__tests__/setup.js"],modulePathIgnorePatterns:["src/__tests__/setup.js"],clearMocks:!0,testEnvironment:"jsdom"}};
4
+ module.exports={name:"posthog-js",version:"1.25.0",description:"Posthog-js allows you to automatically capture usage and send events to PostHog.",repository:"https://github.com/PostHog/posthog-js",author:"hey@posthog.com",license:"MIT",scripts:{start:"parcel watch src/loader-globals.js --out-file dist/array.js",serve:"parcel serve src/loader-globals.js --port 3001 --out-file dist/array.js",build:"yarn build-array && yarn build-module && yarn build-es-module && yarn process-types && yarn build-react","build-array":"parcel build src/loader-globals.js --out-file dist/array.js --no-source-maps","build-module":"rollup -i src/loader-module.js -f cjs -o dist/module.js -c rollup.config.js","build-es-module":"rollup -i src/loader-module.js -f es -o dist/es.js -c rollup.config.js","build-react":"cd react; yarn; yarn build;","process-types":"mkdir -p dist; eslint src --ext .ts -c .eslintrc.ts.js --fix && tsc && cp -f src/*.d.ts dist/",lint:"eslint src --fix",prepublishOnly:"yarn lint && yarn test && yarn build && yarn test-react",test:"jest src","test-react":"cd react; yarn test","test-watch":"jest --watch src",cypress:"cypress open"},main:"dist/module.js",module:"dist/es.js",files:["dist/*","react/dist/*"],dependencies:{"@sentry/types":"^6.11.0",fflate:"^0.4.1","rrweb-snapshot":"^1.1.14"},devDependencies:{"@babel/core":"7.12.10","@babel/preset-env":"7.12.11","@rollup/plugin-babel":"^5.2.1","@rollup/plugin-json":"^4.1.0","@rollup/plugin-node-resolve":"^8.1.0","@typescript-eslint/eslint-plugin":"^3.5.0","@typescript-eslint/parser":"^3.5.0","babel-eslint":"10.1.0","babel-jest":"^26.6.3",cypress:"^9.2.0",eslint:"7.3.1","eslint-plugin-prettier":"^3.1.4","eslint-plugin-react":"^7.21.5","eslint-plugin-react-hooks":"^4.2.0","fast-check":"^2.17.0",given2:"^2.1.7",husky:"^4.2.5",jest:"^27.5.1",jsdom:"16.2.2","jsdom-global":"3.0.2","lint-staged":"^10.2.11",localStorage:"1.0.4","node-fetch":"^2.6.1",parcel:"^1.12.4","posthog-js":"link:.",prettier:"^2.0.5",rollup:"^2.18.2",rrweb:"^1.1.3",sinon:"9.0.2",testcafe:"^1.19.0","testcafe-browser-provider-browserstack":"^1.14.0",typescript:"^3.9.6"},husky:{hooks:{"pre-commit":"lint-staged"}},"lint-staged":{"*.{ts,tsx,js,json}":"prettier --write","*.{ts,tsx}":["eslint -c .eslintrc.ts.js --fix","tsc --noEmit --esModuleInterop --jsx react"]},jest:{testPathIgnorePatterns:["/node_modules/","/cypress/","/react/","/test_data/"],moduleFileExtensions:["js","json"],setupFilesAfterEnv:["given2/setup","./src/__tests__/setup.js"],modulePathIgnorePatterns:["src/__tests__/setup.js"],clearMocks:!0,testEnvironment:"jsdom"}};
5
5
  },{}],"itQ5":[function(require,module,exports) {
6
6
  "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var e=require("../package.json"),r={DEBUG:!1,LIB_VERSION:e.version},t=r;exports.default=t;
7
7
  },{"../package.json":"EHrm"}],"FOZT":[function(require,module,exports) {
@@ -21,7 +21,7 @@ module.exports={name:"posthog-js",version:"1.24.0",description:"Posthog-js allow
21
21
  },{"./utils":"FOZT"}],"ecEG":[function(require,module,exports) {
22
22
  "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PostHogPeople=void 0;var t=require("./gdpr-utils"),e=require("./api-actions"),o=require("./utils"),i=function(){};exports.PostHogPeople=i,o._.extend(i.prototype,e.apiActions),i.prototype._init=function(t){this._posthog=t},i.prototype.set=(0,t.addOptOutCheckPostHogPeople)(function(t,i,r){var s=this.set_action(t,i);return o._.isObject(t)&&(r=i),this._get_config("save_referrer")&&this._posthog.persistence.update_referrer_info(document.referrer),s[e.SET_ACTION]=o._.extend({},o._.info.people_properties(),this._posthog.persistence.get_referrer_info(),s[e.SET_ACTION]),this._send_request(s,r)}),i.prototype.set_once=(0,t.addOptOutCheckPostHogPeople)(function(t,e,i){var r=this.set_once_action(t,e);return o._.isObject(t)&&(i=e),this._send_request(r,i)}),i.prototype.toString=function(){return this._posthog.toString()+".people"},i.prototype._send_request=function(t,e){t.$token=this._get_config("token"),t.$distinct_id=this._posthog.get_distinct_id();var i=this._posthog.get_property("$device_id"),r=this._posthog.get_property("$user_id"),s=this._posthog.get_property("$had_persisted_distinct_id");i&&(t.$device_id=i),r&&(t.$user_id=r),s&&(t.$had_persisted_distinct_id=s);var _=o._.encodeDates(t),p=o._.copyAndTruncateStrings(_,this._get_config("properties_string_max_length")),n=JSON.stringify(_),d=o._.base64Encode(n);return this._posthog._send_request(this._get_config("api_host")+"/engage/",{data:d},{},this._posthog._prepare_callback(e,p)),p},i.prototype._get_config=function(t){return this._posthog.get_config(t)},i.prototype._is_reserved_property=function(t){return"$distinct_id"===t||"$token"===t||"$device_id"===t||"$user_id"===t||"$had_persisted_distinct_id"===t},i.prototype.set=i.prototype.set,i.prototype.set_once=i.prototype.set_once,i.prototype.toString=i.prototype.toString;
23
23
  },{"./gdpr-utils":"rxSh","./api-actions":"os8r","./utils":"FOZT"}],"aVqC":[function(require,module,exports) {
24
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PostHogFeatureFlags=exports.parseFeatureFlagDecideResponse=void 0;var e=require("./utils");function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function a(e,t){for(var a=0;a<t.length;a++){var r=t[a];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function r(e,t,r){return t&&a(e.prototype,t),r&&a(e,r),e}var s=function(e,t){var a=e.featureFlags;if(a)if(Array.isArray(a)){var r={};if(a)for(var s=0;s<a.length;s++)r[a[s]]=!0;t&&t.register({$active_feature_flags:a,$enabled_feature_flags:r})}else t&&t.register({$active_feature_flags:Object.keys(a||{}),$enabled_feature_flags:a||{}});else t&&(t.unregister("$active_feature_flags"),t.unregister("$enabled_feature_flags"))};exports.parseFeatureFlagDecideResponse=s;var i=function(){function a(e){t(this,a),this.instance=e,this._override_warning=!1,this.flagCallReported={},this.featureFlagEventHandlers=[],this.reloadFeatureFlagsQueued=!1,this.reloadFeatureFlagsInAction=!1}return r(a,[{key:"getFlags",value:function(){return Object.keys(this.getFlagVariants())}},{key:"getFlagVariants",value:function(){var t=this.instance.get_property("$enabled_feature_flags"),a=this.instance.get_property("$override_feature_flags");if(!a)return t||{};for(var r=e._.extend({},t),s=Object.keys(a),i=0;i<s.length;i++)!1===a[s[i]]?delete r[s[i]]:r[s[i]]=a[s[i]];return this._override_warning||(console.warn("[PostHog] Overriding feature flags!",{enabledFlags:t,overriddenFlags:a,finalFlags:r}),this._override_warning=!0),r}},{key:"reloadFeatureFlags",value:function(){this.reloadFeatureFlagsQueued||(this.reloadFeatureFlagsQueued=!0,this._startReloadTimer())}},{key:"setReloadingPaused",value:function(e){this.reloadFeatureFlagsInAction=e}},{key:"resetRequestQueue",value:function(){this.reloadFeatureFlagsQueued=!1}},{key:"_startReloadTimer",value:function(){var e=this;this.reloadFeatureFlagsQueued&&!this.reloadFeatureFlagsInAction&&setTimeout(function(){!e.reloadFeatureFlagsInAction&&e.reloadFeatureFlagsQueued&&(e.reloadFeatureFlagsQueued=!1,e._reloadFeatureFlagsRequest())},5)}},{key:"_reloadFeatureFlagsRequest",value:function(){var t=this;this.setReloadingPaused(!0);var a=this.instance.get_config("token"),r=JSON.stringify({token:a,distinct_id:this.instance.get_distinct_id(),groups:this.instance.getGroups()}),s=e._.base64Encode(r);this.instance._send_request(this.instance.get_config("api_host")+"/decide/?v=2",{data:s},{method:"POST"},this.instance._prepare_callback(function(e){t.receivedFeatureFlags(e),t.setReloadingPaused(!1),t._startReloadTimer()}))}},{key:"getFeatureFlag",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!this.getFlags())return console.warn('getFeatureFlag for key "'+e+"\" failed. Feature flags didn't load in time."),!1;var a=this.getFlagVariants()[e];return!t.send_event&&"send_event"in t||this.flagCallReported[e]||(this.flagCallReported[e]=!0,this.instance.capture("$feature_flag_called",{$feature_flag:e,$feature_flag_response:a})),a}},{key:"isFeatureEnabled",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this.getFlags()?!!this.getFeatureFlag(e,t):(console.warn('isFeatureEnabled for key "'+e+"\" failed. Feature flags didn't load in time."),!1)}},{key:"addFeatureFlagsHandler",value:function(e){this.featureFlagEventHandlers.push(e)}},{key:"receivedFeatureFlags",value:function(e){s(e,this.instance.persistence);var t=this.getFlags(),a=this.getFlagVariants();this.featureFlagEventHandlers.forEach(function(e){return e(t,a)})}},{key:"override",value:function(e){if(this._override_warning=!1,!1===e)this.instance.persistence.unregister("$override_feature_flags");else if(Array.isArray(e)){for(var t={},a=0;a<e.length;a++)t[e[a]]=!0;this.instance.persistence.register({$override_feature_flags:t})}else this.instance.persistence.register({$override_feature_flags:e})}},{key:"onFeatureFlags",value:function(e){(this.addFeatureFlagsHandler(e),this.instance.decideEndpointWasHit)&&e(this.getFlags(),this.getFlagVariants())}}]),a}();exports.PostHogFeatureFlags=i;
24
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PostHogFeatureFlags=exports.parseFeatureFlagDecideResponse=void 0;var e=require("./utils");function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function a(e,t){for(var a=0;a<t.length;a++){var r=t[a];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function r(e,t,r){return t&&a(e.prototype,t),r&&a(e,r),e}var s=function(e,t){var a=e.featureFlags;if(a)if(Array.isArray(a)){var r={};if(a)for(var s=0;s<a.length;s++)r[a[s]]=!0;t&&t.register({$active_feature_flags:a,$enabled_feature_flags:r})}else t&&t.register({$active_feature_flags:Object.keys(a||{}),$enabled_feature_flags:a||{}});else t&&(t.unregister("$active_feature_flags"),t.unregister("$enabled_feature_flags"))};exports.parseFeatureFlagDecideResponse=s;var i=function(){function a(e){t(this,a),this.instance=e,this._override_warning=!1,this.flagCallReported={},this.featureFlagEventHandlers=[],this.reloadFeatureFlagsQueued=!1,this.reloadFeatureFlagsInAction=!1}return r(a,[{key:"getFlags",value:function(){return Object.keys(this.getFlagVariants())}},{key:"getFlagVariants",value:function(){var t=this.instance.get_property("$enabled_feature_flags"),a=this.instance.get_property("$override_feature_flags");if(!a)return t||{};for(var r=e._.extend({},t),s=Object.keys(a),i=0;i<s.length;i++)!1===a[s[i]]?delete r[s[i]]:r[s[i]]=a[s[i]];return this._override_warning||(console.warn("[PostHog] Overriding feature flags!",{enabledFlags:t,overriddenFlags:a,finalFlags:r}),this._override_warning=!0),r}},{key:"reloadFeatureFlags",value:function(){this.reloadFeatureFlagsQueued||(this.reloadFeatureFlagsQueued=!0,this._startReloadTimer())}},{key:"setAnonymousDistinctId",value:function(e){this.$anon_distinct_id=e}},{key:"setReloadingPaused",value:function(e){this.reloadFeatureFlagsInAction=e}},{key:"resetRequestQueue",value:function(){this.reloadFeatureFlagsQueued=!1}},{key:"_startReloadTimer",value:function(){var e=this;this.reloadFeatureFlagsQueued&&!this.reloadFeatureFlagsInAction&&setTimeout(function(){!e.reloadFeatureFlagsInAction&&e.reloadFeatureFlagsQueued&&(e.reloadFeatureFlagsQueued=!1,e._reloadFeatureFlagsRequest())},5)}},{key:"_reloadFeatureFlagsRequest",value:function(){var t=this;this.setReloadingPaused(!0);var a=this.instance.get_config("token"),r=JSON.stringify({token:a,distinct_id:this.instance.get_distinct_id(),groups:this.instance.getGroups(),$anon_distinct_id:this.$anon_distinct_id}),s=e._.base64Encode(r);this.instance._send_request(this.instance.get_config("api_host")+"/decide/?v=2",{data:s},{method:"POST"},this.instance._prepare_callback(function(e){t.$anon_distinct_id=void 0,t.receivedFeatureFlags(e),t.setReloadingPaused(!1),t._startReloadTimer()}))}},{key:"getFeatureFlag",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!this.getFlags())return console.warn('getFeatureFlag for key "'+e+"\" failed. Feature flags didn't load in time."),!1;var a=this.getFlagVariants()[e];return!t.send_event&&"send_event"in t||this.flagCallReported[e]||(this.flagCallReported[e]=!0,this.instance.capture("$feature_flag_called",{$feature_flag:e,$feature_flag_response:a})),a}},{key:"isFeatureEnabled",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this.getFlags()?!!this.getFeatureFlag(e,t):(console.warn('isFeatureEnabled for key "'+e+"\" failed. Feature flags didn't load in time."),!1)}},{key:"addFeatureFlagsHandler",value:function(e){this.featureFlagEventHandlers.push(e)}},{key:"receivedFeatureFlags",value:function(e){s(e,this.instance.persistence);var t=this.getFlags(),a=this.getFlagVariants();this.featureFlagEventHandlers.forEach(function(e){return e(t,a)})}},{key:"override",value:function(e){if(this._override_warning=!1,!1===e)this.instance.persistence.unregister("$override_feature_flags");else if(Array.isArray(e)){for(var t={},a=0;a<e.length;a++)t[e[a]]=!0;this.instance.persistence.register({$override_feature_flags:t})}else this.instance.persistence.register({$override_feature_flags:e})}},{key:"onFeatureFlags",value:function(e){(this.addFeatureFlagsHandler(e),this.instance.decideEndpointWasHit)&&e(this.getFlags(),this.getFlagVariants())}}]),a}();exports.PostHogFeatureFlags=i;
25
25
  },{"./utils":"FOZT"}],"MAdm":[function(require,module,exports) {
26
26
  "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.SESSION_ID=exports.SESSION_RECORDING_ENABLED_SERVER_SIDE=exports.EVENT_TIMERS_KEY=exports.CAMPAIGN_IDS_KEY=exports.ALIAS_ID_KEY=exports.PEOPLE_DISTINCT_ID_KEY=exports.SET_ONCE_QUEUE_KEY=exports.SET_QUEUE_KEY=exports.PostHogPersistence=void 0;var e=require("./utils"),t=require("./storage");function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}var s="__mps";exports.SET_QUEUE_KEY=s;var o="__mpso";exports.SET_ONCE_QUEUE_KEY=o;var i="__mpus",p="__mpa",n="__mpap",_="__mpr",a="__mpu",c="$people_distinct_id";exports.PEOPLE_DISTINCT_ID_KEY=c;var h="__alias";exports.ALIAS_ID_KEY=h;var u="__cmpns";exports.CAMPAIGN_IDS_KEY=u;var d="__timers";exports.EVENT_TIMERS_KEY=d;var f="$session_recording_enabled_server_side";exports.SESSION_RECORDING_ENABLED_SERVER_SIDE=f;var m="$sesid";exports.SESSION_ID=m;var l="$enabled_feature_flags",E=[s,o,i,p,n,_,a,c,h,u,d,f,m,l],y=function(r){var s="";r.token&&(s=r.token.replace(/\+/g,"PL").replace(/\//g,"SL").replace(/=/g,"EQ")),this.props={},this.campaign_params_saved=!1,r.persistence_name?this.name="ph_"+r.persistence_name:this.name="ph_"+s+"_posthog";var o=r.persistence.toLowerCase();"cookie"!==o&&-1===o.indexOf("localstorage")&&"memory"!==o&&(e.logger.critical("Unknown persistence type "+o+"; falling back to cookie"),o=r.persistence="cookie"),"localstorage"===o&&t.localStore.is_supported()?this.storage=t.localStore:"localstorage+cookie"===o&&t.localPlusCookieStore.is_supported()?this.storage=t.localPlusCookieStore:this.storage="memory"===o?t.memoryStore:t.cookieStore,this.load(),this.update_config(r),this.save()};exports.PostHogPersistence=y,y.prototype.properties=function(){var t={};return e._.each(this.props,function(s,o){if(o===l&&"object"===r(s))for(var i=Object.keys(s),p=0;p<i.length;p++)t["$feature/".concat(i[p])]=s[i[p]];else e._.include(E,o)||(t[o]=s)}),t},y.prototype.load=function(){if(!this.disabled){var t=this.storage.parse(this.name);t&&(this.props=e._.extend({},t))}},y.prototype.save=function(){this.disabled||this.storage.set(this.name,this.props,this.expire_days,this.cross_subdomain,this.secure)},y.prototype.remove=function(){this.storage.remove(this.name,!1),this.storage.remove(this.name,!0)},y.prototype.clear=function(){this.remove(),this.props={}},y.prototype.register_once=function(t,r,s){return!!e._.isObject(t)&&(void 0===r&&(r="None"),this.expire_days=void 0===s?this.default_expiry:s,e._.each(t,function(e,t){this.props.hasOwnProperty(t)&&this.props[t]!==r||(this.props[t]=e)},this),this.save(),!0)},y.prototype.register=function(t,r){return!!e._.isObject(t)&&(this.expire_days=void 0===r?this.default_expiry:r,e._.extend(this.props,t),this.save(),!0)},y.prototype.unregister=function(e){e in this.props&&(delete this.props[e],this.save())},y.prototype.update_campaign_params=function(){this.campaign_params_saved||(this.register(e._.info.campaignParams()),this.campaign_params_saved=!0)},y.prototype.update_search_keyword=function(t){this.register(e._.info.searchInfo(t))},y.prototype.update_referrer_info=function(t){this.register_once({$initial_referrer:t||"$direct",$initial_referring_domain:e._.info.referringDomain(t)||"$direct"},""),this.register({$referrer:t||this.props.$referrer||"$direct",$referring_domain:e._.info.referringDomain(t)||this.props.$referring_domain||"$direct"})},y.prototype.get_referrer_info=function(){return e._.strip_empty_properties({$initial_referrer:this.props.$initial_referrer,$initial_referring_domain:this.props.$initial_referring_domain})},y.prototype.safe_merge=function(t){return e._.each(this.props,function(e,r){r in t||(t[r]=e)}),t},y.prototype.update_config=function(e){this.default_expiry=this.expire_days=e.cookie_expiration,this.set_disabled(e.disable_persistence),this.set_cross_subdomain(e.cross_subdomain_cookie),this.set_secure(e.secure_cookie)},y.prototype.set_disabled=function(e){this.disabled=e,this.disabled?this.remove():this.save()},y.prototype.set_cross_subdomain=function(e){e!==this.cross_subdomain&&(this.cross_subdomain=e,this.remove(),this.save())},y.prototype.get_cross_subdomain=function(){return this.cross_subdomain},y.prototype.set_secure=function(e){e!==this.secure&&(this.secure=!!e,this.remove(),this.save())},y.prototype.set_event_timer=function(e,t){var r=this.props[d]||{};r[e]=t,this.props[d]=r,this.save()},y.prototype.remove_event_timer=function(t){var r=(this.props[d]||{})[t];return e._.isUndefined(r)||(delete this.props[d][t],this.save()),r};
27
27
  },{"./utils":"FOZT","./storage":"KZ7Y"}],"vmk3":[function(require,module,exports) {
@@ -51,7 +51,7 @@ module.exports={name:"posthog-js",version:"1.24.0",description:"Posthog-js allow
51
51
  },{"./posthog-persistence":"MAdm","./storage":"KZ7Y","./utils":"FOZT"}],"eWVp":[function(require,module,exports) {
52
52
  "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.optimisePerformanceData=i,exports.getPerformanceEntriesByType=a,exports.deduplicateKeys=u,exports.pageLoadFrom=c,exports.getPerformanceData=f;var e=require("./utils"),r=n(require("./config"));function n(e){return e&&e.__esModule?e:{default:e}}function t(e){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function o(e){return Number(e)===e&&e%1!=0}function i(e){return e.forEach(function(r,n){for(var t in r)o(r[t])&&r[t].toString().match(/^\d+\.\d{4,}$/)&&(e[n][t]=Number(r[t].toFixed(3))),["serverTiming","workerTiming"].includes(t)&&0===r[t].length&&delete e[n][t],"entryType"===t&&"resource"===r[t]&&delete e[n][t],"nextHopProtocol"===t&&delete e[n][t],0===r[t]&&delete e[n][t]}),u(e)}function a(n){try{return i(JSON.parse(JSON.stringify(e.window.performance.getEntriesByType(n))))}catch(t){return r.default.DEBUG&&console.warn("not able to capture performance data ("+n+") - "+t),[]}}function u(e){if(0===e.length)return[];var r=Object.keys(e[0]);return[r,e.map(function(e){return r.map(function(r){return e[r]})})]}function c(e){var r=e.navigation&&e.navigation[0],n=e.navigation&&e.navigation[1]&&e.navigation[1][0],t=r&&r.indexOf("duration");if(t>-1)return n[t];var o=r&&r.indexOf("loadEventEnd"),i=r&&r.indexOf("startTime");return o>-1?(n&&n[o])-(n&&n[i]||0):void 0}function f(){var r={navigation:a("navigation"),paint:a("paint"),resource:a("resource")};void 0!==t(e.window)&&e.window.performance&&e.window.performance.clearResourceTimings&&e.window.performance.clearResourceTimings();var n={},o=c(r);return o&&(n.$performance_page_loaded=o),n.$performance_raw=JSON.stringify(r),n}
53
53
  },{"./utils":"FOZT","./config":"itQ5"}],"ok3T":[function(require,module,exports) {
54
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.init_from_snippet=N,exports.init_as_module=Y,exports.PostHogLib=void 0;var e,t,o=require("./lz-string"),r=w(require("./config")),i=require("./utils"),n=require("./autocapture"),s=require("./posthog-people"),p=require("./posthog-featureflags"),a=require("./posthog-persistence"),c=require("./extensions/sessionrecording"),_=require("./decide"),u=require("./extensions/toolbar"),d=require("./gdpr-utils"),g=require("./storage"),l=require("./request-queue"),h=require("./capture-metrics"),f=require("./compression"),y=require("./send-request"),b=require("./retry-queue"),v=require("./sessionid"),m=require("./apm");function w(e){return e&&e.__esModule?e:{default:e}}function k(e,t){var o=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),o.push.apply(o,r)}return o}function q(e){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{};t%2?k(Object(o),!0).forEach(function(t){P(e,t,o[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):k(Object(o)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))})}return e}function P(e,t,o){return t in e?Object.defineProperty(e,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[t]=o,e}function S(e,t){return $(e)||E(e,t)||F(e,t)||x()}function x(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function F(e,t){if(e){if("string"==typeof e)return O(e,t);var o=Object.prototype.toString.call(e).slice(8,-1);return"Object"===o&&e.constructor&&(o=e.constructor.name),"Map"===o||"Set"===o?Array.from(e):"Arguments"===o||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(o)?O(e,t):void 0}}function O(e,t){(null==t||t>e.length)&&(t=e.length);for(var o=0,r=new Array(t);o<t;o++)r[o]=e[o];return r}function E(e,t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e)){var o=[],r=!0,i=!1,n=void 0;try{for(var s,p=e[Symbol.iterator]();!(r=(s=p.next()).done)&&(o.push(s.value),!t||o.length!==t);r=!0);}catch(a){i=!0,n=a}finally{try{r||null==p.return||p.return()}finally{if(i)throw n}}return o}}function $(e){if(Array.isArray(e))return e}var I=0,R=1,A=function(){},H={},j="posthog",M=i.window.XMLHttpRequest&&"withCredentials"in new XMLHttpRequest,L=!M&&-1===i.userAgent.indexOf("MSIE")&&-1===i.userAgent.indexOf("Mozilla"),D=function(){return{api_host:"https://app.posthog.com",api_method:"POST",api_transport:"XHR",autocapture:!0,rageclick:!1,cross_subdomain_cookie:-1===i.document.location.hostname.indexOf("herokuapp.com"),persistence:"cookie",persistence_name:"",cookie_name:"",loaded:function(){},store_google:!0,save_referrer:!0,test:!1,verbose:!1,img:!1,capture_pageview:!0,debug:!1,cookie_expiration:365,upgrade:!1,disable_session_recording:!1,disable_persistence:!1,disable_cookie:!1,enable_recording_console_log:!1,secure_cookie:"https:"===i.window.location.protocol,ip:!0,opt_out_capturing_by_default:!1,opt_out_persistence_by_default:!1,opt_out_capturing_persistence_type:"localStorage",opt_out_capturing_cookie_prefix:null,property_blacklist:[],sanitize_properties:null,xhr_headers:{},inapp_protocol:"//",inapp_link_new_window:!1,request_batching:!0,properties_string_max_length:65535,session_recording:{blockClass:"ph-no-capture",blockSelector:null,ignoreClass:"ph-ignore-input",maskAllInputs:!0,maskInputOptions:{},maskInputFn:null,slimDOMOptions:{},collectFonts:!1,inlineStylesheet:!0},mask_all_element_attributes:!1,mask_all_text:!1,advanced_disable_decide:!1,advanced_disable_toolbar_metrics:!1,on_xhr_error:function(e){var t="Bad HTTP status: "+e.status+" "+e.statusText;console.error(t)},get_device_id:function(e){return e},_onCapture:function(){},_capture_metrics:!1,_capture_performance:!1}},U=function(){};exports.PostHogLib=U;var C=function(o,a,_){var d,g=_!==j&&t?t[_]:t;if(g&&e===I)d=g;else{if(g&&!i._.isArray(g))return void console.error("You have already initialized "+_);d=new U}if(d._init(o,a,_),d.people=new s.PostHogPeople,d.people._init(d),d.featureFlags=new p.PostHogFeatureFlags(d),d.feature_flags=d.featureFlags,d.toolbar=new u.Toolbar(d),d.toolbar.maybeLoadEditor(),d.sessionRecording=new c.SessionRecording(d),d.sessionRecording.startRecordingIfEnabled(),d.__autocapture_enabled=d.get_config("autocapture"),d.get_config("autocapture")){n.autocapture.enabledForProject(d.get_config("token"),100,100)?n.autocapture.isBrowserSupported()?n.autocapture.init(d):(d.__autocapture_enabled=!1,i.logger.log("Disabling Automatic Event Collection because this browser is not supported")):(d.__autocapture_enabled=!1,i.logger.log("Not in active bucket: disabling Automatic Event Collection."))}return r.default.DEBUG=r.default.DEBUG||d.get_config("debug"),!i._.isUndefined(g)&&i._.isArray(g)&&(d._execute_array.call(d.people,g.people),d._execute_array(g)),d};U.prototype.init=function(e,o,r){if(i._.isUndefined(r))console.error("You must name your new library: init(token, config, name)");else{if(r!==j){var n=C(e,o,r);return t[r]=n,n._loaded(),n}console.error("You must initialize the main posthog object right after you include the PostHog js snippet")}},U.prototype._init=function(e,t,o){if(this.__loaded=!0,this.config={},this._triggered_notifs=[],this.compression={},this.set_config(i._.extend({},D(),t,{name:o,token:e,callback_fn:(o===j?o:j+"."+o)+"._jsc"})),this._jsc=function(){},this._captureMetrics=new h.CaptureMetrics(this.get_config("_capture_metrics")),this._requestQueue=new l.RequestQueue(this._captureMetrics,i._.bind(this._handle_queued_event,this)),this._retryQueue=new b.RetryQueue(this._captureMetrics,this.get_config("on_xhr_error")),this.__captureHooks=[],this.__request_queue=[],this.persistence=new a.PostHogPersistence(this.config),this.sessionManager=new v.SessionIdManager(this.config,this.persistence),this._gdpr_init(),!this.get_distinct_id()){var r=this.get_config("get_device_id")(i._.UUID());this.register_once({distinct_id:r,$device_id:r},"")}i.window.addEventListener&&i.window.addEventListener("unload",this._handle_unload.bind(this))},U.prototype._loaded=function(){this.featureFlags.setReloadingPaused(!0);try{this.get_config("loaded")(this)}catch(e){console.error("`loaded` function failed",e)}this._start_queue_if_opted_in(),this.get_config("capture_pageview")&&this.capture("$pageview",{},{send_instantly:!0}),this.get_config("advanced_disable_decide")||new _.Decide(this).call(),this.featureFlags.resetRequestQueue(),this.featureFlags.setReloadingPaused(!1)},U.prototype._start_queue_if_opted_in=function(){this.has_opted_out_capturing()||this.get_config("request_batching")&&this._requestQueue.poll()},U.prototype._dom_loaded=function(){this.has_opted_out_capturing()||i._.each(this.__request_queue,function(e){this._send_request.apply(this,e)},this),delete this.__request_queue,this._start_queue_if_opted_in()},U.prototype._prepare_callback=function(e,t){if(i._.isUndefined(e))return null;if(M){return function(o){e(o,t)}}var o=this._jsc,r=""+Math.floor(1e8*Math.random()),n=this.get_config("callback_fn")+"["+r+"]";return o[r]=function(i){delete o[r],e(i,t)},n},U.prototype._handle_unload=function(){this.get_config("request_batching")?(this.get_config("capture_pageview")&&this.capture("$pageleave"),this.get_config("_capture_metrics")&&(this._requestQueue.updateUnloadMetrics(),this.capture("$capture_metrics",this._captureMetrics.metrics)),this._requestQueue.unload(),this._retryQueue.unload()):this.get_config("capture_pageview")&&this.capture("$pageleave",null,{transport:"sendbeacon"})},U.prototype._handle_queued_event=function(e,t,o){var r=JSON.stringify(t);this.__compress_and_send_json_request(e,r,o||H,A)},U.prototype.__compress_and_send_json_request=function(e,t,o,r){var i=S((0,f.compressData)((0,f.decideCompression)(this.compression),t,o),2),n=i[0],s=i[1];this._send_request(e,n,s,r)},U.prototype._send_request=function(e,t,o,r){if(L)this.__request_queue.push(arguments);else{var n={method:this.get_config("api_method"),transport:this.get_config("api_transport"),verbose:this.get_config("verbose")};o=i._.extend(n,o||{}),M||(o.method="GET");var s=i.window.navigator.sendBeacon&&"sendbeacon"===o.transport.toLowerCase();if(e=(0,y.addParamsToURL)(e,o.urlQueryArgs,{ip:this.get_config("ip")}),i._.isObject(t)&&this.get_config("img")){var p=i.document.createElement("img");p.src=e,i.document.body.appendChild(p)}else if(s)try{i.window.navigator.sendBeacon(e,(0,y.encodePostData)(t,q(q({},o),{},{sendBeacon:!0})))}catch(_){this.get_config("debug")&&console.error(_)}else if(M)try{(0,y.xhr)({url:e,data:t,headers:this.get_config("xhr_headers"),options:o,captureMetrics:this._captureMetrics,callback:r,retriesPerformedSoFar:0,retryQueue:this._retryQueue,onXHRError:this.get_config("on_xhr_error")})}catch(_){console.error(_)}else{var a=i.document.createElement("script");a.type="text/javascript",a.async=!0,a.defer=!0,a.src=e;var c=i.document.getElementsByTagName("script")[0];c.parentNode.insertBefore(a,c)}}},U.prototype._execute_array=function(e){var t,o=[],r=[],n=[];i._.each(e,function(e){e&&(t=e[0],i._.isArray(t)?n.push(e):"function"==typeof e?e.call(this):i._.isArray(e)&&"alias"===t?o.push(e):i._.isArray(e)&&-1!==t.indexOf("capture")&&"function"==typeof this[t]?n.push(e):r.push(e))},this);var s=function(e,t){i._.each(e,function(e){if(i._.isArray(e[0])){var o=t;i._.each(e,function(e){o=o[e[0]].apply(o,e.slice(1))})}else this[e[0]].apply(this,e.slice(1))},t)};s(o,this),s(r,this),s(n,this)},U.prototype.push=function(e){this._execute_array([e])},U.prototype.capture=(0,d.addOptOutCheckPostHogLib)(function(e,t,o){if(this.__loaded){this._captureMetrics.incr("capture"),"$snapshot"===e&&this._captureMetrics.incr("snapshot");var r=(o=o||H).transport;if(r&&(o.transport=r),i._.isUndefined(e)||"string"!=typeof e)console.error("No event name provided to posthog.capture");else if(!i._.isBlockedUA(i.userAgent)){var n=this.persistence.remove_event_timer(e);this.persistence.update_search_keyword(i.document.referrer),this.get_config("store_google")&&this.persistence.update_campaign_params(),this.get_config("save_referrer")&&this.persistence.update_referrer_info(i.document.referrer);var s={event:e,properties:this._calculate_event_properties(e,t,n)};"$identify"===e&&o.$set&&(s.$set=o.$set),s=i._.copyAndTruncateStrings(s,o._noTruncate?null:this.get_config("properties_string_max_length")),this.get_config("debug")&&i.logger.log("PostHog.js send",s);var p=JSON.stringify(s),a=this.get_config("api_host")+(o.endpoint||"/e/"),c=o!==H;return!this.get_config("request_batching")||c&&!o._batchKey||o.send_instantly?this.__compress_and_send_json_request(a,p,o):(s.timestamp=new Date,this._requestQueue.enqueue(a,s,o)),this._invokeCaptureHooks(e,s),s}}}),U.prototype._addCaptureHook=function(e){this.__captureHooks.push(e)},U.prototype._invokeCaptureHooks=function(e,t){this.config._onCapture(e,t),i._.each(this.__captureHooks,function(t){return t(e)})},U.prototype._calculate_event_properties=function(e,t,o){var r=q({},t);if(r.token=this.get_config("token"),"$snapshot"===e){var n=this.persistence.properties();return r.distinct_id=n.distinct_id,r}if(!i._.isUndefined(o)){var s=(new Date).getTime()-o;r.$duration=parseFloat((s/1e3).toFixed(3))}if(this.sessionManager){var p=this.sessionManager.checkAndGetSessionAndWindowId(),a=p.sessionId,c=p.windowId;r.$session_id=a,r.$window_id=c}r=i._.extend({},i._.info.properties(),this.persistence.properties(),r),"$pageview"===e&&this.get_config("_capture_performance")&&(r=i._.extend(r,(0,m.getPerformanceData)()));var _=this.get_config("property_blacklist");i._.isArray(_)?i._.each(_,function(e){delete r[e]}):console.error("Invalid value for property_blacklist config: "+_);var u=this.get_config("sanitize_properties");return u&&(r=u(r,e)),r},U.prototype.register=function(e,t){this.persistence.register(e,t)},U.prototype.register_once=function(e,t,o){this.persistence.register_once(e,t,o)},U.prototype.unregister=function(e){this.persistence.unregister(e)},U.prototype._register_single=function(e,t){var o={};o[e]=t,this.register(o)},U.prototype.getFeatureFlag=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this.featureFlags.getFeatureFlag(e,t)},U.prototype.isFeatureEnabled=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this.featureFlags.isFeatureEnabled(e,t)},U.prototype.reloadFeatureFlags=function(){return this.featureFlags.reloadFeatureFlags()},U.prototype.onFeatureFlags=function(e){this.featureFlags.onFeatureFlags(e)},U.prototype.identify=function(e,t,o){if(e){this._captureMetrics.incr("identify");var r=this.get_distinct_id();if(this.register({$user_id:e}),!this.get_property("$device_id")){var i=r;this.register_once({$had_persisted_distinct_id:!0,$device_id:i},"")}e!==r&&e!==this.get_property(a.ALIAS_ID_KEY)&&(this.unregister(a.ALIAS_ID_KEY),this.register({distinct_id:e})),e===r||this.get_property("$device_id")&&r!==this.get_property("$device_id")?(t&&this.people.set(t),o&&this.people.set_once(o)):this.capture("$identify",{distinct_id:e,$anon_distinct_id:r},{$set:t||{}},{$set_once:o||{}}),e!==r&&this.reloadFeatureFlags()}else console.error("Unique user id has not been set in posthog.identify")},U.prototype.group=function(e,t,o){if(e&&t){this._captureMetrics.incr("group");var r=this.getGroups();this.register({$groups:q(q({},r),{},P({},e,t))}),o&&this.capture("$groupidentify",{$group_type:e,$group_key:t,$group_set:o}),r[e]!==t&&this.reloadFeatureFlags()}else console.error("posthog.group requires a group type and group key")},U.prototype.reset=function(e){var t=this.get_property("$device_id");this.persistence.clear();var o=this.get_config("get_device_id")(i._.UUID());this.register_once({distinct_id:o,$device_id:e?o:t},"")},U.prototype.get_distinct_id=function(){return this.get_property("distinct_id")},U.prototype.getGroups=function(){return this.get_property("$groups")||{}},U.prototype.alias=function(e,t){if(e===this.get_property(a.PEOPLE_DISTINCT_ID_KEY))return console.critical("Attempting to create alias for existing People user - aborting."),-2;var o=this;return i._.isUndefined(t)&&(t=this.get_distinct_id()),e!==t?(this._register_single(a.ALIAS_ID_KEY,e),this.capture("$create_alias",{alias:e,distinct_id:t},function(){o.identify(e)})):(console.error("alias matches current distinct_id - skipping api call."),this.identify(e),-1)},U.prototype.set_config=function(e){var t=q({},this.config);i._.isObject(e)&&(i._.extend(this.config,e),this.get_config("persistence_name")||(this.config.persistence_name=this.config.cookie_name),this.get_config("disable_persistence")||(this.config.disable_persistence=this.config.disable_cookie),this.persistence&&this.persistence.update_config(this.config),g.localStore.is_supported()&&"true"===g.localStore.get("ph_debug")&&(this.config.debug=!0),r.default.DEBUG=r.default.DEBUG||this.get_config("debug"),this.sessionRecording&&void 0!==e.disable_session_recording&&t.disable_session_recording!==e.disable_session_recording&&(e.disable_session_recording?this.sessionRecording.stopRecording():this.sessionRecording.startRecordingIfEnabled()))},U.prototype.startSessionRecording=function(){this.set_config({disable_session_recording:!1})},U.prototype.stopSessionRecording=function(){this.set_config({disable_session_recording:!0})},U.prototype.sessionRecordingStarted=function(){return this.sessionRecording.started()},U.prototype.get_config=function(e){var t;return null===(t=this.config)||void 0===t?void 0:t[e]},U.prototype.get_property=function(e){return this.persistence.props[e]},U.prototype.toString=function(){var e=this.get_config("name");return e!==j&&(e=j+"."+e),e},U.prototype._gdpr_init=function(){"localStorage"===this.get_config("opt_out_capturing_persistence_type")&&g.localStore.is_supported()&&(!this.has_opted_in_capturing()&&this.has_opted_in_capturing({persistence_type:"cookie"})&&this.opt_in_capturing({enable_persistence:!1}),!this.has_opted_out_capturing()&&this.has_opted_out_capturing({persistence_type:"cookie"})&&this.opt_out_capturing({clear_persistence:!1}),this.clear_opt_in_out_capturing({persistence_type:"cookie",enable_persistence:!1})),this.has_opted_out_capturing()?this._gdpr_update_persistence({clear_persistence:!0}):this.has_opted_in_capturing()||!this.get_config("opt_out_capturing_by_default")&&!g.cookieStore.get("ph_optout")||(g.cookieStore.remove("ph_optout"),this.opt_out_capturing({clear_persistence:this.get_config("opt_out_persistence_by_default")}))},U.prototype._gdpr_update_persistence=function(e){var t;if(e&&e.clear_persistence)t=!0;else{if(!e||!e.enable_persistence)return;t=!1}this.get_config("disable_persistence")||this.persistence.disabled===t||this.persistence.set_disabled(t)},U.prototype._gdpr_call_func=function(e,t){return t=i._.extend({capture:i._.bind(this.capture,this),persistence_type:this.get_config("opt_out_capturing_persistence_type"),cookie_prefix:this.get_config("opt_out_capturing_cookie_prefix"),cookie_expiration:this.get_config("cookie_expiration"),cross_subdomain_cookie:this.get_config("cross_subdomain_cookie"),secure_cookie:this.get_config("secure_cookie")},t),g.localStore.is_supported()||"localStorage"!==t.persistence_type||(t.persistence_type="cookie"),e(this.get_config("token"),{capture:t.capture,captureEventName:t.capture_event_name,captureProperties:t.capture_properties,persistenceType:t.persistence_type,persistencePrefix:t.cookie_prefix,cookieExpiration:t.cookie_expiration,crossSubdomainCookie:t.cross_subdomain_cookie,secureCookie:t.secure_cookie})},U.prototype.opt_in_capturing=function(e){e=i._.extend({enable_persistence:!0},e),this._gdpr_call_func(d.optIn,e),this._gdpr_update_persistence(e)},U.prototype.opt_out_capturing=function(e){e=i._.extend({clear_persistence:!0},e),this._gdpr_call_func(d.optOut,e),this._gdpr_update_persistence(e)},U.prototype.has_opted_in_capturing=function(e){return this._gdpr_call_func(d.hasOptedIn,e)},U.prototype.has_opted_out_capturing=function(e){return this._gdpr_call_func(d.hasOptedOut,e)},U.prototype.clear_opt_in_out_capturing=function(e){e=i._.extend({enable_persistence:!0},e),this._gdpr_call_func(d.clearOptInOut,e),this._gdpr_update_persistence(e)},U.prototype.sentry_integration=function(e,t,o,r){this.name="posthog-js",this.setupOnce=function(i){i(function(i){if("error"!==i.level||!e.__loaded)return i;i.tags||(i.tags={}),i.tags["PostHog Person URL"]=e.config.api_host+"/person/"+e.get_distinct_id(),e.sessionRecordingStarted()&&(i.tags["PostHog Recording URL"]=e.config.api_host+"/recordings/#sessionRecordingId="+e.sessionManager.checkAndGetSessionAndWindowId(!0).sessionId);var n={$sentry_event_id:i.event_id,$sentry_exception:i.exception};return t&&o&&(n.$sentry_url=(r||"https://sentry.io/organizations/")+t+"/issues/?project="+o+"&query="+i.event_id),e.capture("$exception",n),i})}},U.prototype.debug=function(e){!1===e?(i.window.console.log("You've disabled debug mode."),localStorage&&localStorage.setItem("ph_debug",void 0),this.set_config({debug:!1})):(i.window.console.log("You're now in debug mode. All calls to PostHog will be logged in your console.\nYou can disable this with `posthog.debug(false)`."),localStorage&&localStorage.setItem("ph_debug","true"),this.set_config({debug:!0}))},U.prototype.decodeLZ64=o.LZString.decompressFromBase64,U.prototype.init=U.prototype.init,U.prototype.reset=U.prototype.reset,U.prototype.capture=U.prototype.capture,U.prototype.register=U.prototype.register,U.prototype.register_once=U.prototype.register_once,U.prototype.unregister=U.prototype.unregister,U.prototype.identify=U.prototype.identify,U.prototype.getGroups=U.prototype.getGroups,U.prototype.group=U.prototype.group,U.prototype.alias=U.prototype.alias,U.prototype.set_config=U.prototype.set_config,U.prototype.get_config=U.prototype.get_config,U.prototype.get_property=U.prototype.get_property,U.prototype.get_distinct_id=U.prototype.get_distinct_id,U.prototype.toString=U.prototype.toString,U.prototype.opt_out_captureing=U.prototype.opt_out_captureing,U.prototype.opt_in_captureing=U.prototype.opt_in_captureing,U.prototype.has_opted_out_captureing=U.prototype.has_opted_out_captureing,U.prototype.has_opted_in_captureing=U.prototype.has_opted_in_captureing,U.prototype.clear_opt_in_out_captureing=U.prototype.clear_opt_in_out_captureing,U.prototype.opt_out_capturing=U.prototype.opt_out_capturing,U.prototype.opt_in_capturing=U.prototype.opt_in_capturing,U.prototype.has_opted_out_capturing=U.prototype.has_opted_out_capturing,U.prototype.has_opted_in_capturing=U.prototype.has_opted_in_capturing,U.prototype.clear_opt_in_out_capturing=U.prototype.clear_opt_in_out_capturing,U.prototype.getFeatureFlag=U.prototype.getFeatureFlag,U.prototype.isFeatureEnabled=U.prototype.isFeatureEnabled,U.prototype.reloadFeatureFlags=U.prototype.reloadFeatureFlags,U.prototype.onFeatureFlags=U.prototype.onFeatureFlags,U.prototype.decodeLZ64=U.prototype.decodeLZ64,U.prototype.SentryIntegration=U.prototype.sentry_integration,U.prototype.debug=U.prototype.debug,U.prototype.LIB_VERSION=r.default.LIB_VERSION,U.prototype.startSessionRecording=U.prototype.startSessionRecording,U.prototype.stopSessionRecording=U.prototype.stopSessionRecording,U.prototype.sessionRecordingStarted=U.prototype.sessionRecordingStarted,a.PostHogPersistence.prototype.properties=a.PostHogPersistence.prototype.properties,a.PostHogPersistence.prototype.update_search_keyword=a.PostHogPersistence.prototype.update_search_keyword,a.PostHogPersistence.prototype.update_referrer_info=a.PostHogPersistence.prototype.update_referrer_info,a.PostHogPersistence.prototype.get_cross_subdomain=a.PostHogPersistence.prototype.get_cross_subdomain,a.PostHogPersistence.prototype.clear=a.PostHogPersistence.prototype.clear,i._.safewrap_class(U,["identify"]);var T={},B=function(){i._.each(T,function(e,o){o!==j&&(t[o]=e)}),t._=i._},Q=function(){t.init=function(o,r,n){if(n)return t[n]||(t[n]=T[n]=C(o,r,n),t[n]._loaded()),t[n];var s=t;T[j]?s=T[j]:o&&((s=C(o,r,j))._loaded(),T[j]=s),t=s,e===R&&(i.window[j]=t),B()}},G=function(){function e(){e.done||(e.done=!0,L=!1,i._.each(T,function(e){e._dom_loaded()}))}if(i.document.addEventListener)"complete"===i.document.readyState?e():i.document.addEventListener("DOMContentLoaded",e,!1);else if(i.document.attachEvent){i.document.attachEvent("onreadystatechange",e);var t=!1;try{t=null===i.window.frameElement}catch(o){}i.document.documentElement.doScroll&&t&&function t(){try{i.document.documentElement.doScroll("left")}catch(o){return void setTimeout(t,1)}e()}()}i._.register_event(i.window,"load",e,!0)};function N(){e=R,i._.isUndefined(i.window.posthog)&&(i.window.posthog=[]),(t=i.window.posthog).__loaded||t.config&&t.persistence?console.error("PostHog library has already been downloaded at least once."):(i._.each(t._i,function(e){e&&i._.isArray(e)&&(T[e[e.length-1]]=C.apply(this,e))}),Q(),t.init(),i._.each(T,function(e){e._loaded()}),G())}function Y(){return e=I,t=new U,Q(),t.init(),G(),t}
54
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.init_from_snippet=N,exports.init_as_module=Y,exports.PostHogLib=void 0;var e,t,o=require("./lz-string"),r=w(require("./config")),i=require("./utils"),n=require("./autocapture"),s=require("./posthog-people"),p=require("./posthog-featureflags"),a=require("./posthog-persistence"),c=require("./extensions/sessionrecording"),_=require("./decide"),u=require("./extensions/toolbar"),d=require("./gdpr-utils"),g=require("./storage"),l=require("./request-queue"),h=require("./capture-metrics"),f=require("./compression"),y=require("./send-request"),b=require("./retry-queue"),v=require("./sessionid"),m=require("./apm");function w(e){return e&&e.__esModule?e:{default:e}}function k(e,t){var o=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),o.push.apply(o,r)}return o}function q(e){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{};t%2?k(Object(o),!0).forEach(function(t){P(e,t,o[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):k(Object(o)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))})}return e}function P(e,t,o){return t in e?Object.defineProperty(e,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[t]=o,e}function S(e,t){return I(e)||E(e,t)||F(e,t)||x()}function x(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function F(e,t){if(e){if("string"==typeof e)return O(e,t);var o=Object.prototype.toString.call(e).slice(8,-1);return"Object"===o&&e.constructor&&(o=e.constructor.name),"Map"===o||"Set"===o?Array.from(e):"Arguments"===o||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(o)?O(e,t):void 0}}function O(e,t){(null==t||t>e.length)&&(t=e.length);for(var o=0,r=new Array(t);o<t;o++)r[o]=e[o];return r}function E(e,t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e)){var o=[],r=!0,i=!1,n=void 0;try{for(var s,p=e[Symbol.iterator]();!(r=(s=p.next()).done)&&(o.push(s.value),!t||o.length!==t);r=!0);}catch(a){i=!0,n=a}finally{try{r||null==p.return||p.return()}finally{if(i)throw n}}return o}}function I(e){if(Array.isArray(e))return e}var $=0,A=1,R=function(){},H={},j="posthog",M=i.window.XMLHttpRequest&&"withCredentials"in new XMLHttpRequest,D=!M&&-1===i.userAgent.indexOf("MSIE")&&-1===i.userAgent.indexOf("Mozilla"),L=function(){return{api_host:"https://app.posthog.com",api_method:"POST",api_transport:"XHR",autocapture:!0,rageclick:!1,cross_subdomain_cookie:-1===i.document.location.hostname.indexOf("herokuapp.com"),persistence:"cookie",persistence_name:"",cookie_name:"",loaded:function(){},store_google:!0,save_referrer:!0,test:!1,verbose:!1,img:!1,capture_pageview:!0,debug:!1,cookie_expiration:365,upgrade:!1,disable_session_recording:!1,disable_persistence:!1,disable_cookie:!1,enable_recording_console_log:!1,secure_cookie:"https:"===i.window.location.protocol,ip:!0,opt_out_capturing_by_default:!1,opt_out_persistence_by_default:!1,opt_out_capturing_persistence_type:"localStorage",opt_out_capturing_cookie_prefix:null,property_blacklist:[],sanitize_properties:null,xhr_headers:{},inapp_protocol:"//",inapp_link_new_window:!1,request_batching:!0,properties_string_max_length:65535,session_recording:{blockClass:"ph-no-capture",blockSelector:null,ignoreClass:"ph-ignore-input",maskAllInputs:!0,maskInputOptions:{},maskInputFn:null,slimDOMOptions:{},collectFonts:!1,inlineStylesheet:!0},mask_all_element_attributes:!1,mask_all_text:!1,advanced_disable_decide:!1,advanced_disable_toolbar_metrics:!1,on_xhr_error:function(e){var t="Bad HTTP status: "+e.status+" "+e.statusText;console.error(t)},get_device_id:function(e){return e},_onCapture:function(){},_capture_metrics:!1,_capture_performance:!1}},U=function(){};exports.PostHogLib=U;var C=function(o,a,_){var d,g=_!==j&&t?t[_]:t;if(g&&e===$)d=g;else{if(g&&!i._.isArray(g))return void console.error("You have already initialized "+_);d=new U}if(d._init(o,a,_),d.people=new s.PostHogPeople,d.people._init(d),d.featureFlags=new p.PostHogFeatureFlags(d),d.feature_flags=d.featureFlags,d.toolbar=new u.Toolbar(d),d.toolbar.maybeLoadEditor(),d.sessionRecording=new c.SessionRecording(d),d.sessionRecording.startRecordingIfEnabled(),d.__autocapture_enabled=d.get_config("autocapture"),d.get_config("autocapture")){n.autocapture.enabledForProject(d.get_config("token"),100,100)?n.autocapture.isBrowserSupported()?n.autocapture.init(d):(d.__autocapture_enabled=!1,i.logger.log("Disabling Automatic Event Collection because this browser is not supported")):(d.__autocapture_enabled=!1,i.logger.log("Not in active bucket: disabling Automatic Event Collection."))}return r.default.DEBUG=r.default.DEBUG||d.get_config("debug"),!i._.isUndefined(g)&&i._.isArray(g)&&(d._execute_array.call(d.people,g.people),d._execute_array(g)),d};U.prototype.init=function(e,o,r){if(i._.isUndefined(r))console.error("You must name your new library: init(token, config, name)");else{if(r!==j){var n=C(e,o,r);return t[r]=n,n._loaded(),n}console.error("You must initialize the main posthog object right after you include the PostHog js snippet")}},U.prototype._init=function(e,t,o){if(this.__loaded=!0,this.config={},this._triggered_notifs=[],this.compression={},this.set_config(i._.extend({},L(),t,{name:o,token:e,callback_fn:(o===j?o:j+"."+o)+"._jsc"})),this._jsc=function(){},this._captureMetrics=new h.CaptureMetrics(this.get_config("_capture_metrics")),this._requestQueue=new l.RequestQueue(this._captureMetrics,i._.bind(this._handle_queued_event,this)),this._retryQueue=new b.RetryQueue(this._captureMetrics,this.get_config("on_xhr_error")),this.__captureHooks=[],this.__request_queue=[],this.persistence=new a.PostHogPersistence(this.config),this.sessionManager=new v.SessionIdManager(this.config,this.persistence),this._gdpr_init(),!this.get_distinct_id()){var r=this.get_config("get_device_id")(i._.UUID());this.register_once({distinct_id:r,$device_id:r},"")}i.window.addEventListener&&i.window.addEventListener("unload",this._handle_unload.bind(this))},U.prototype._loaded=function(){this.featureFlags.setReloadingPaused(!0);try{this.get_config("loaded")(this)}catch(e){console.error("`loaded` function failed",e)}this._start_queue_if_opted_in(),this.get_config("capture_pageview")&&this.capture("$pageview",{},{send_instantly:!0}),this.get_config("advanced_disable_decide")||new _.Decide(this).call(),this.featureFlags.resetRequestQueue(),this.featureFlags.setReloadingPaused(!1)},U.prototype._start_queue_if_opted_in=function(){this.has_opted_out_capturing()||this.get_config("request_batching")&&this._requestQueue.poll()},U.prototype._dom_loaded=function(){this.has_opted_out_capturing()||i._.each(this.__request_queue,function(e){this._send_request.apply(this,e)},this),delete this.__request_queue,this._start_queue_if_opted_in()},U.prototype._prepare_callback=function(e,t){if(i._.isUndefined(e))return null;if(M){return function(o){e(o,t)}}var o=this._jsc,r=""+Math.floor(1e8*Math.random()),n=this.get_config("callback_fn")+"["+r+"]";return o[r]=function(i){delete o[r],e(i,t)},n},U.prototype._handle_unload=function(){this.get_config("request_batching")?(this.get_config("capture_pageview")&&this.capture("$pageleave"),this.get_config("_capture_metrics")&&(this._requestQueue.updateUnloadMetrics(),this.capture("$capture_metrics",this._captureMetrics.metrics)),this._requestQueue.unload(),this._retryQueue.unload()):this.get_config("capture_pageview")&&this.capture("$pageleave",null,{transport:"sendbeacon"})},U.prototype._handle_queued_event=function(e,t,o){var r=JSON.stringify(t);this.__compress_and_send_json_request(e,r,o||H,R)},U.prototype.__compress_and_send_json_request=function(e,t,o,r){var i=S((0,f.compressData)((0,f.decideCompression)(this.compression),t,o),2),n=i[0],s=i[1];this._send_request(e,n,s,r)},U.prototype._send_request=function(e,t,o,r){if(D)this.__request_queue.push(arguments);else{var n={method:this.get_config("api_method"),transport:this.get_config("api_transport"),verbose:this.get_config("verbose")};o=i._.extend(n,o||{}),M||(o.method="GET");var s=i.window.navigator.sendBeacon&&"sendbeacon"===o.transport.toLowerCase();if(e=(0,y.addParamsToURL)(e,o.urlQueryArgs,{ip:this.get_config("ip")}),i._.isObject(t)&&this.get_config("img")){var p=i.document.createElement("img");p.src=e,i.document.body.appendChild(p)}else if(s)try{i.window.navigator.sendBeacon(e,(0,y.encodePostData)(t,q(q({},o),{},{sendBeacon:!0})))}catch(_){this.get_config("debug")&&console.error(_)}else if(M)try{(0,y.xhr)({url:e,data:t,headers:this.get_config("xhr_headers"),options:o,captureMetrics:this._captureMetrics,callback:r,retriesPerformedSoFar:0,retryQueue:this._retryQueue,onXHRError:this.get_config("on_xhr_error")})}catch(_){console.error(_)}else{var a=i.document.createElement("script");a.type="text/javascript",a.async=!0,a.defer=!0,a.src=e;var c=i.document.getElementsByTagName("script")[0];c.parentNode.insertBefore(a,c)}}},U.prototype._execute_array=function(e){var t,o=[],r=[],n=[];i._.each(e,function(e){e&&(t=e[0],i._.isArray(t)?n.push(e):"function"==typeof e?e.call(this):i._.isArray(e)&&"alias"===t?o.push(e):i._.isArray(e)&&-1!==t.indexOf("capture")&&"function"==typeof this[t]?n.push(e):r.push(e))},this);var s=function(e,t){i._.each(e,function(e){if(i._.isArray(e[0])){var o=t;i._.each(e,function(e){o=o[e[0]].apply(o,e.slice(1))})}else this[e[0]].apply(this,e.slice(1))},t)};s(o,this),s(r,this),s(n,this)},U.prototype.push=function(e){this._execute_array([e])},U.prototype.capture=(0,d.addOptOutCheckPostHogLib)(function(e,t,o){if(this.__loaded){this._captureMetrics.incr("capture"),"$snapshot"===e&&this._captureMetrics.incr("snapshot");var r=(o=o||H).transport;if(r&&(o.transport=r),i._.isUndefined(e)||"string"!=typeof e)console.error("No event name provided to posthog.capture");else if(!i._.isBlockedUA(i.userAgent)){var n=this.persistence.remove_event_timer(e);this.persistence.update_search_keyword(i.document.referrer),this.get_config("store_google")&&this.persistence.update_campaign_params(),this.get_config("save_referrer")&&this.persistence.update_referrer_info(i.document.referrer);var s={event:e,properties:this._calculate_event_properties(e,t,n)};"$identify"===e&&o.$set&&(s.$set=o.$set),s=i._.copyAndTruncateStrings(s,o._noTruncate?null:this.get_config("properties_string_max_length")),this.get_config("debug")&&i.logger.log("PostHog.js send",s);var p=JSON.stringify(s),a=this.get_config("api_host")+(o.endpoint||"/e/"),c=o!==H;return!this.get_config("request_batching")||c&&!o._batchKey||o.send_instantly?this.__compress_and_send_json_request(a,p,o):(s.timestamp=new Date,this._requestQueue.enqueue(a,s,o)),this._invokeCaptureHooks(e,s),s}}}),U.prototype._addCaptureHook=function(e){this.__captureHooks.push(e)},U.prototype._invokeCaptureHooks=function(e,t){this.config._onCapture(e,t),i._.each(this.__captureHooks,function(t){return t(e)})},U.prototype._calculate_event_properties=function(e,t,o){var r=q({},t);if(r.token=this.get_config("token"),"$snapshot"===e){var n=this.persistence.properties();return r.distinct_id=n.distinct_id,r}if(!i._.isUndefined(o)){var s=(new Date).getTime()-o;r.$duration=parseFloat((s/1e3).toFixed(3))}if(this.sessionManager){var p=this.sessionManager.checkAndGetSessionAndWindowId(),a=p.sessionId,c=p.windowId;r.$session_id=a,r.$window_id=c}r=i._.extend({},i._.info.properties(),this.persistence.properties(),r),"$pageview"===e&&this.get_config("_capture_performance")&&(r=i._.extend(r,(0,m.getPerformanceData)()));var _=this.get_config("property_blacklist");i._.isArray(_)?i._.each(_,function(e){delete r[e]}):console.error("Invalid value for property_blacklist config: "+_);var u=this.get_config("sanitize_properties");return u&&(r=u(r,e)),r},U.prototype.register=function(e,t){this.persistence.register(e,t)},U.prototype.register_once=function(e,t,o){this.persistence.register_once(e,t,o)},U.prototype.unregister=function(e){this.persistence.unregister(e)},U.prototype._register_single=function(e,t){var o={};o[e]=t,this.register(o)},U.prototype.getFeatureFlag=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this.featureFlags.getFeatureFlag(e,t)},U.prototype.isFeatureEnabled=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this.featureFlags.isFeatureEnabled(e,t)},U.prototype.reloadFeatureFlags=function(){return this.featureFlags.reloadFeatureFlags()},U.prototype.onFeatureFlags=function(e){this.featureFlags.onFeatureFlags(e)},U.prototype.identify=function(e,t,o){if(e){this._captureMetrics.incr("identify");var r=this.get_distinct_id();if(this.register({$user_id:e}),!this.get_property("$device_id")){var i=r;this.register_once({$had_persisted_distinct_id:!0,$device_id:i},"")}e!==r&&e!==this.get_property(a.ALIAS_ID_KEY)&&(this.unregister(a.ALIAS_ID_KEY),this.register({distinct_id:e})),e===r||this.get_property("$device_id")&&r!==this.get_property("$device_id")?(t&&this.people.set(t),o&&this.people.set_once(o)):(this.capture("$identify",{distinct_id:e,$anon_distinct_id:r},{$set:t||{}},{$set_once:o||{}}),this.featureFlags.setAnonymousDistinctId(r)),e!==r&&this.reloadFeatureFlags()}else console.error("Unique user id has not been set in posthog.identify")},U.prototype.group=function(e,t,o){if(e&&t){this._captureMetrics.incr("group");var r=this.getGroups();this.register({$groups:q(q({},r),{},P({},e,t))}),o&&this.capture("$groupidentify",{$group_type:e,$group_key:t,$group_set:o}),r[e]!==t&&this.reloadFeatureFlags()}else console.error("posthog.group requires a group type and group key")},U.prototype.reset=function(e){var t=this.get_property("$device_id");this.persistence.clear();var o=this.get_config("get_device_id")(i._.UUID());this.register_once({distinct_id:o,$device_id:e?o:t},"")},U.prototype.get_distinct_id=function(){return this.get_property("distinct_id")},U.prototype.getGroups=function(){return this.get_property("$groups")||{}},U.prototype.alias=function(e,t){if(e===this.get_property(a.PEOPLE_DISTINCT_ID_KEY))return console.critical("Attempting to create alias for existing People user - aborting."),-2;var o=this;return i._.isUndefined(t)&&(t=this.get_distinct_id()),e!==t?(this._register_single(a.ALIAS_ID_KEY,e),this.capture("$create_alias",{alias:e,distinct_id:t},function(){o.identify(e)})):(console.error("alias matches current distinct_id - skipping api call."),this.identify(e),-1)},U.prototype.set_config=function(e){var t=q({},this.config);i._.isObject(e)&&(i._.extend(this.config,e),this.get_config("persistence_name")||(this.config.persistence_name=this.config.cookie_name),this.get_config("disable_persistence")||(this.config.disable_persistence=this.config.disable_cookie),this.persistence&&this.persistence.update_config(this.config),g.localStore.is_supported()&&"true"===g.localStore.get("ph_debug")&&(this.config.debug=!0),r.default.DEBUG=r.default.DEBUG||this.get_config("debug"),this.sessionRecording&&void 0!==e.disable_session_recording&&t.disable_session_recording!==e.disable_session_recording&&(e.disable_session_recording?this.sessionRecording.stopRecording():this.sessionRecording.startRecordingIfEnabled()))},U.prototype.startSessionRecording=function(){this.set_config({disable_session_recording:!1})},U.prototype.stopSessionRecording=function(){this.set_config({disable_session_recording:!0})},U.prototype.sessionRecordingStarted=function(){return this.sessionRecording.started()},U.prototype.get_config=function(e){var t;return null===(t=this.config)||void 0===t?void 0:t[e]},U.prototype.get_property=function(e){return this.persistence.props[e]},U.prototype.toString=function(){var e=this.get_config("name");return e!==j&&(e=j+"."+e),e},U.prototype._gdpr_init=function(){"localStorage"===this.get_config("opt_out_capturing_persistence_type")&&g.localStore.is_supported()&&(!this.has_opted_in_capturing()&&this.has_opted_in_capturing({persistence_type:"cookie"})&&this.opt_in_capturing({enable_persistence:!1}),!this.has_opted_out_capturing()&&this.has_opted_out_capturing({persistence_type:"cookie"})&&this.opt_out_capturing({clear_persistence:!1}),this.clear_opt_in_out_capturing({persistence_type:"cookie",enable_persistence:!1})),this.has_opted_out_capturing()?this._gdpr_update_persistence({clear_persistence:!0}):this.has_opted_in_capturing()||!this.get_config("opt_out_capturing_by_default")&&!g.cookieStore.get("ph_optout")||(g.cookieStore.remove("ph_optout"),this.opt_out_capturing({clear_persistence:this.get_config("opt_out_persistence_by_default")}))},U.prototype._gdpr_update_persistence=function(e){var t;if(e&&e.clear_persistence)t=!0;else{if(!e||!e.enable_persistence)return;t=!1}this.get_config("disable_persistence")||this.persistence.disabled===t||this.persistence.set_disabled(t)},U.prototype._gdpr_call_func=function(e,t){return t=i._.extend({capture:i._.bind(this.capture,this),persistence_type:this.get_config("opt_out_capturing_persistence_type"),cookie_prefix:this.get_config("opt_out_capturing_cookie_prefix"),cookie_expiration:this.get_config("cookie_expiration"),cross_subdomain_cookie:this.get_config("cross_subdomain_cookie"),secure_cookie:this.get_config("secure_cookie")},t),g.localStore.is_supported()||"localStorage"!==t.persistence_type||(t.persistence_type="cookie"),e(this.get_config("token"),{capture:t.capture,captureEventName:t.capture_event_name,captureProperties:t.capture_properties,persistenceType:t.persistence_type,persistencePrefix:t.cookie_prefix,cookieExpiration:t.cookie_expiration,crossSubdomainCookie:t.cross_subdomain_cookie,secureCookie:t.secure_cookie})},U.prototype.opt_in_capturing=function(e){e=i._.extend({enable_persistence:!0},e),this._gdpr_call_func(d.optIn,e),this._gdpr_update_persistence(e)},U.prototype.opt_out_capturing=function(e){e=i._.extend({clear_persistence:!0},e),this._gdpr_call_func(d.optOut,e),this._gdpr_update_persistence(e)},U.prototype.has_opted_in_capturing=function(e){return this._gdpr_call_func(d.hasOptedIn,e)},U.prototype.has_opted_out_capturing=function(e){return this._gdpr_call_func(d.hasOptedOut,e)},U.prototype.clear_opt_in_out_capturing=function(e){e=i._.extend({enable_persistence:!0},e),this._gdpr_call_func(d.clearOptInOut,e),this._gdpr_update_persistence(e)},U.prototype.sentry_integration=function(e,t,o,r){this.name="posthog-js",this.setupOnce=function(i){i(function(i){if("error"!==i.level||!e.__loaded)return i;i.tags||(i.tags={}),i.tags["PostHog Person URL"]=e.config.api_host+"/person/"+e.get_distinct_id(),e.sessionRecordingStarted()&&(i.tags["PostHog Recording URL"]=e.config.api_host+"/recordings/#sessionRecordingId="+e.sessionManager.checkAndGetSessionAndWindowId(!0).sessionId);var n={$sentry_event_id:i.event_id,$sentry_exception:i.exception};return t&&o&&(n.$sentry_url=(r||"https://sentry.io/organizations/")+t+"/issues/?project="+o+"&query="+i.event_id),e.capture("$exception",n),i})}},U.prototype.debug=function(e){!1===e?(i.window.console.log("You've disabled debug mode."),localStorage&&localStorage.setItem("ph_debug",void 0),this.set_config({debug:!1})):(i.window.console.log("You're now in debug mode. All calls to PostHog will be logged in your console.\nYou can disable this with `posthog.debug(false)`."),localStorage&&localStorage.setItem("ph_debug","true"),this.set_config({debug:!0}))},U.prototype.decodeLZ64=o.LZString.decompressFromBase64,U.prototype.init=U.prototype.init,U.prototype.reset=U.prototype.reset,U.prototype.capture=U.prototype.capture,U.prototype.register=U.prototype.register,U.prototype.register_once=U.prototype.register_once,U.prototype.unregister=U.prototype.unregister,U.prototype.identify=U.prototype.identify,U.prototype.getGroups=U.prototype.getGroups,U.prototype.group=U.prototype.group,U.prototype.alias=U.prototype.alias,U.prototype.set_config=U.prototype.set_config,U.prototype.get_config=U.prototype.get_config,U.prototype.get_property=U.prototype.get_property,U.prototype.get_distinct_id=U.prototype.get_distinct_id,U.prototype.toString=U.prototype.toString,U.prototype.opt_out_captureing=U.prototype.opt_out_captureing,U.prototype.opt_in_captureing=U.prototype.opt_in_captureing,U.prototype.has_opted_out_captureing=U.prototype.has_opted_out_captureing,U.prototype.has_opted_in_captureing=U.prototype.has_opted_in_captureing,U.prototype.clear_opt_in_out_captureing=U.prototype.clear_opt_in_out_captureing,U.prototype.opt_out_capturing=U.prototype.opt_out_capturing,U.prototype.opt_in_capturing=U.prototype.opt_in_capturing,U.prototype.has_opted_out_capturing=U.prototype.has_opted_out_capturing,U.prototype.has_opted_in_capturing=U.prototype.has_opted_in_capturing,U.prototype.clear_opt_in_out_capturing=U.prototype.clear_opt_in_out_capturing,U.prototype.getFeatureFlag=U.prototype.getFeatureFlag,U.prototype.isFeatureEnabled=U.prototype.isFeatureEnabled,U.prototype.reloadFeatureFlags=U.prototype.reloadFeatureFlags,U.prototype.onFeatureFlags=U.prototype.onFeatureFlags,U.prototype.decodeLZ64=U.prototype.decodeLZ64,U.prototype.SentryIntegration=U.prototype.sentry_integration,U.prototype.debug=U.prototype.debug,U.prototype.LIB_VERSION=r.default.LIB_VERSION,U.prototype.startSessionRecording=U.prototype.startSessionRecording,U.prototype.stopSessionRecording=U.prototype.stopSessionRecording,U.prototype.sessionRecordingStarted=U.prototype.sessionRecordingStarted,a.PostHogPersistence.prototype.properties=a.PostHogPersistence.prototype.properties,a.PostHogPersistence.prototype.update_search_keyword=a.PostHogPersistence.prototype.update_search_keyword,a.PostHogPersistence.prototype.update_referrer_info=a.PostHogPersistence.prototype.update_referrer_info,a.PostHogPersistence.prototype.get_cross_subdomain=a.PostHogPersistence.prototype.get_cross_subdomain,a.PostHogPersistence.prototype.clear=a.PostHogPersistence.prototype.clear,i._.safewrap_class(U,["identify"]);var T={},B=function(){i._.each(T,function(e,o){o!==j&&(t[o]=e)}),t._=i._},Q=function(){t.init=function(o,r,n){if(n)return t[n]||(t[n]=T[n]=C(o,r,n),t[n]._loaded()),t[n];var s=t;T[j]?s=T[j]:o&&((s=C(o,r,j))._loaded(),T[j]=s),t=s,e===A&&(i.window[j]=t),B()}},G=function(){function e(){e.done||(e.done=!0,D=!1,i._.each(T,function(e){e._dom_loaded()}))}if(i.document.addEventListener)"complete"===i.document.readyState?e():i.document.addEventListener("DOMContentLoaded",e,!1);else if(i.document.attachEvent){i.document.attachEvent("onreadystatechange",e);var t=!1;try{t=null===i.window.frameElement}catch(o){}i.document.documentElement.doScroll&&t&&function t(){try{i.document.documentElement.doScroll("left")}catch(o){return void setTimeout(t,1)}e()}()}i._.register_event(i.window,"load",e,!0)};function N(){e=A,i._.isUndefined(i.window.posthog)&&(i.window.posthog=[]),(t=i.window.posthog).__loaded||t.config&&t.persistence?console.error("PostHog library has already been downloaded at least once."):(i._.each(t._i,function(e){e&&i._.isArray(e)&&(T[e[e.length-1]]=C.apply(this,e))}),Q(),t.init(),i._.each(T,function(e){e._loaded()}),G())}function Y(){return e=$,t=new U,Q(),t.init(),G(),t}
55
55
  },{"./lz-string":"zdbk","./config":"itQ5","./utils":"FOZT","./autocapture":"gR3r","./posthog-people":"ecEG","./posthog-featureflags":"aVqC","./posthog-persistence":"MAdm","./extensions/sessionrecording":"Z2N4","./decide":"auG7","./extensions/toolbar":"ZEpJ","./gdpr-utils":"rxSh","./storage":"KZ7Y","./request-queue":"Je4H","./capture-metrics":"TeHW","./compression":"Ie9M","./send-request":"tOu2","./retry-queue":"ennf","./sessionid":"tci7","./apm":"eWVp"}],"e2xX":[function(require,module,exports) {
56
56
  "use strict";var r=require("./posthog-core");(0,r.init_from_snippet)();
57
57
  },{"./posthog-core":"ok3T"}]},{},["e2xX"], null)
package/dist/es.js CHANGED
@@ -863,7 +863,7 @@ var LZString = {
863
863
  }
864
864
  };
865
865
 
866
- var version = "1.24.0";
866
+ var version = "1.25.0";
867
867
 
868
868
  var Config$1 = {
869
869
  DEBUG: false,
@@ -3186,6 +3186,11 @@ var PostHogFeatureFlags = /*#__PURE__*/function () {
3186
3186
  this._startReloadTimer();
3187
3187
  }
3188
3188
  }
3189
+ }, {
3190
+ key: "setAnonymousDistinctId",
3191
+ value: function setAnonymousDistinctId(anon_distinct_id) {
3192
+ this.$anon_distinct_id = anon_distinct_id;
3193
+ }
3189
3194
  }, {
3190
3195
  key: "setReloadingPaused",
3191
3196
  value: function setReloadingPaused(isPaused) {
@@ -3221,7 +3226,8 @@ var PostHogFeatureFlags = /*#__PURE__*/function () {
3221
3226
  var json_data = JSON.stringify({
3222
3227
  token: token,
3223
3228
  distinct_id: this.instance.get_distinct_id(),
3224
- groups: this.instance.getGroups()
3229
+ groups: this.instance.getGroups(),
3230
+ $anon_distinct_id: this.$anon_distinct_id
3225
3231
  });
3226
3232
 
3227
3233
  var encoded_data = _.base64Encode(json_data);
@@ -3231,6 +3237,10 @@ var PostHogFeatureFlags = /*#__PURE__*/function () {
3231
3237
  }, {
3232
3238
  method: 'POST'
3233
3239
  }, this.instance._prepare_callback(function (response) {
3240
+ // reset anon_distinct_id after at least a single request with it
3241
+ // makes it through
3242
+ _this2.$anon_distinct_id = undefined;
3243
+
3234
3244
  _this2.receivedFeatureFlags(response); // :TRICKY: Reload - start another request if queued!
3235
3245
 
3236
3246
 
@@ -6673,7 +6683,10 @@ PostHogLib.prototype.identify = function (new_distinct_id, userPropertiesToSet,
6673
6683
  $set: userPropertiesToSet || {}
6674
6684
  }, {
6675
6685
  $set_once: userPropertiesToSetOnce || {}
6676
- });
6686
+ }); // let the reload feature flag request know to send this previous distinct id
6687
+ // for flag consistency
6688
+
6689
+ this.featureFlags.setAnonymousDistinctId(previous_distinct_id);
6677
6690
  } else {
6678
6691
  if (userPropertiesToSet) {
6679
6692
  this['people'].set(userPropertiesToSet);
package/dist/module.js CHANGED
@@ -865,7 +865,7 @@ var LZString = {
865
865
  }
866
866
  };
867
867
 
868
- var version = "1.24.0";
868
+ var version = "1.25.0";
869
869
 
870
870
  var Config$1 = {
871
871
  DEBUG: false,
@@ -3188,6 +3188,11 @@ var PostHogFeatureFlags = /*#__PURE__*/function () {
3188
3188
  this._startReloadTimer();
3189
3189
  }
3190
3190
  }
3191
+ }, {
3192
+ key: "setAnonymousDistinctId",
3193
+ value: function setAnonymousDistinctId(anon_distinct_id) {
3194
+ this.$anon_distinct_id = anon_distinct_id;
3195
+ }
3191
3196
  }, {
3192
3197
  key: "setReloadingPaused",
3193
3198
  value: function setReloadingPaused(isPaused) {
@@ -3223,7 +3228,8 @@ var PostHogFeatureFlags = /*#__PURE__*/function () {
3223
3228
  var json_data = JSON.stringify({
3224
3229
  token: token,
3225
3230
  distinct_id: this.instance.get_distinct_id(),
3226
- groups: this.instance.getGroups()
3231
+ groups: this.instance.getGroups(),
3232
+ $anon_distinct_id: this.$anon_distinct_id
3227
3233
  });
3228
3234
 
3229
3235
  var encoded_data = _.base64Encode(json_data);
@@ -3233,6 +3239,10 @@ var PostHogFeatureFlags = /*#__PURE__*/function () {
3233
3239
  }, {
3234
3240
  method: 'POST'
3235
3241
  }, this.instance._prepare_callback(function (response) {
3242
+ // reset anon_distinct_id after at least a single request with it
3243
+ // makes it through
3244
+ _this2.$anon_distinct_id = undefined;
3245
+
3236
3246
  _this2.receivedFeatureFlags(response); // :TRICKY: Reload - start another request if queued!
3237
3247
 
3238
3248
 
@@ -6675,7 +6685,10 @@ PostHogLib.prototype.identify = function (new_distinct_id, userPropertiesToSet,
6675
6685
  $set: userPropertiesToSet || {}
6676
6686
  }, {
6677
6687
  $set_once: userPropertiesToSetOnce || {}
6678
- });
6688
+ }); // let the reload feature flag request know to send this previous distinct id
6689
+ // for flag consistency
6690
+
6691
+ this.featureFlags.setAnonymousDistinctId(previous_distinct_id);
6679
6692
  } else {
6680
6693
  if (userPropertiesToSet) {
6681
6694
  this['people'].set(userPropertiesToSet);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "posthog-js",
3
- "version": "1.24.0",
3
+ "version": "1.25.0",
4
4
  "description": "Posthog-js allows you to automatically capture usage and send events to PostHog.",
5
5
  "repository": "https://github.com/PostHog/posthog-js",
6
6
  "author": "hey@posthog.com",