Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

posthog-js

Package Overview
Dependencies
Maintainers
1
Versions
662
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

posthog-js - npm Package Compare versions

Comparing version 1.3.1 to 1.3.2

3

CHANGELOG.md

@@ -0,1 +1,4 @@

## 1.3.2 - 2020-07-16
- Fix request batching when loading the library from npm and running `.init()` after DOM load.
## 1.3.1 - 2020-07-13

@@ -2,0 +5,0 @@ - Support loading the toolbar with a `__posthog` has param (was: `state`) and `ph_authorize` action.

2

dist/array.js

@@ -22,5 +22,5 @@ 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}({"itQ5":[function(require,module,exports) {

},{"./api-actions":"os8r","./config":"itQ5","./utils":"FOZT"}],"ok3T":[function(require,module,exports) {
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.init_from_snippet=A,exports.init_as_module=O;var e,t,o=c(require("./config")),i=require("./utils"),r=require("./autocapture"),n=require("./dom-capture"),s=require("./posthog-people"),_=require("./posthog-featureflags"),p=require("./posthog-persistence"),a=require("./gdpr-utils");function c(e){return e&&e.__esModule?e:{default:e}}var u=0,d=1,l=function(){},g={},h="posthog",f=i.window.XMLHttpRequest&&"withCredentials"in new XMLHttpRequest,y=!f&&-1===i.userAgent.indexOf("MSIE")&&-1===i.userAgent.indexOf("Mozilla"),v=i.window.navigator.sendBeacon;v&&(v=i._.bind(v,i.navigator));var m={api_host:"https://t.posthog.com",api_method:"POST",api_transport:"XHR",autocapture:!0,cdn:"https://cdn.posthog.com",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,capture_links_timeout:300,cookie_expiration:365,upgrade:!1,disable_persistence:!1,disable_cookie:!1,secure_cookie:!1,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:[],xhr_headers:{},inapp_protocol:"//",inapp_link_new_window:!1,request_batching:!0},b=!1,w=function(){},k=function(n,p,a){var c,d=a===h?t:t[a];if(d&&e===u)c=d;else{if(d&&!i._.isArray(d))return void i.console.error("You have already initialized "+a);c=new w}if(c._cached_groups={},c._user_decide_check_complete=!1,c._events_captureed_before_user_decide_check_complete=[],c._init(n,p,a),c.people=new s.PostHogPeople,c.people._init(c),c.feature_flags=new _.PostHogFeatureFlags,c.feature_flags._init(c),o.default.DEBUG=o.default.DEBUG||c.get_config("debug"),c.__autocapture_enabled=c.get_config("autocapture"),c.get_config("autocapture")){r.autocapture.enabledForProject(c.get_config("token"),100,100)?r.autocapture.isBrowserSupported()?r.autocapture.init(c):(c.__autocapture_enabled=!1,i.console.log("Disabling Automatic Event Collection because this browser is not supported")):(c.__autocapture_enabled=!1,i.console.log("Not in active bucket: disabling Automatic Event Collection."))}return!i._.isUndefined(d)&&i._.isArray(d)&&(c._execute_array.call(c.people,d.people),c._execute_array(d)),c};function q(e){i.window.console.warn("WARNING! posthog."+e+" is deprecated and will be removed soon! Please use posthog."+e.split("captureing").join("capturing")+' instead (without the "e")!')}w.prototype.init=function(e,o,r){if(i._.isUndefined(r))i.console.error("You must name your new library: init(token, config, name)");else{if(r!==h){var n=k(e,o,r);return t[r]=n,n._loaded(),n}i.console.error("You must initialize the main posthog object right after you include the PostHog js snippet")}},w.prototype._init=function(e,t,o){this.__loaded=!0,this.config={},this._triggered_notifs=[],this.set_config(i._.extend({},m,t,{name:o,token:e,callback_fn:(o===h?o:h+"."+o)+"._jsc"})),this._jsc=function(){},this._event_queue=[],this._empty_queue_count=0,this._should_poll=!0,this._poller=function(){},this.__dom_loaded_queue=[],this.__request_queue=[],this.__disabled_events=[],this._flags={disable_all_events:!1,identify_called:!1},this.persistence=this.cookie=new p.PostHogPersistence(this.config),this._gdpr_init();var r=i._.UUID();this.get_distinct_id()||this.register_once({distinct_id:r,$device_id:r},""),i.window.addEventListener&&i.window.addEventListener("unload",this._handle_unload.bind(this))},w.prototype._loaded=function(){this.get_config("loaded")(this),this.get_config("capture_pageview")&&this.capture_pageview()},w.prototype._dom_loaded=function(){i._.each(this.__dom_loaded_queue,function(e){this._capture_dom.apply(this,e)},this),this.has_opted_out_capturing()||(i._.each(this.__request_queue,function(e){this._send_request.apply(this,e)},this),this.get_config("request_batching")&&this._event_queue_poll()),delete this.__dom_loaded_queue,delete this.__request_queue},w.prototype._capture_dom=function(e,t){if(this.get_config("img"))return i.console.error("You can't use DOM capturing functions with img = true."),!1;if(!b)return this.__dom_loaded_queue.push([e,t]),!1;var o=(new e).init(this);return o.capture.apply(o,t)},w.prototype._prepare_callback=function(e,t){if(i._.isUndefined(e))return null;if(f){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},w.prototype._event_enqueue=function(e,t,o,i){this._event_queue.push({url:e,data:t,options:o,callback:i}),this._should_poll||(this._should_poll=!0,this._event_queue_poll())},w.prototype._format_event_queue_data=function(){var e={};return i._.each(this._event_queue,function(t){var o=t.url,i=t.data;void 0===e[o]&&(e[o]=[]),e[o].push(i)}),e},w.prototype._event_queue_poll=function(){var e=this;this._poller=setTimeout(function(){if(e._event_queue.length>0){var t=e._format_event_queue_data(),o=function(o){var r=t[o];i._.each(r,function(e,t){r[t].offset=Math.abs(r[t].timestamp-new Date),delete r[t].timestamp}),n=i._.JSONEncode(r),s=i._.base64Encode(n),e._send_request(o,{data:s},g,l)};for(var r in t){var n,s;o(r)}e._event_queue.length=0}else e._empty_queue_count++;e._empty_queue_count>4&&(e._should_poll=!1,e._empty_queue_count=0),e._should_poll&&e._event_queue_poll()},3e3)},w.prototype._handle_unload=function(){if(this.get_config("request_batching")){clearInterval(this._poller),this.capture("$pageleave");var e={};for(var t in this._event_queue.length>0&&(e=this._format_event_queue_data()),this._event_queue.length=0,e){var o=i._.base64Encode(i._.JSONEncode(e[t]));this._send_request(t,{data:o},{transport:"sendbeacon"},l)}}else this.capture("$pageleave",null,{transport:"sendbeacon"})},w.prototype._send_request=function(e,t,o,r){if(y)this.__request_queue.push(arguments);else{var n={method:this.get_config("api_method"),transport:this.get_config("api_transport")},s=null;r||!i._.isFunction(o)&&"string"!=typeof o||(r=o,o=null),o=i._.extend(n,o||{}),f||(o.method="GET");var _=v&&"sendbeacon"===o.transport.toLowerCase(),p=_||"POST"===o.method,a=this.get_config("verbose");t.verbose&&(a=!0),this.get_config("test")&&(t.test=1),a&&(t.verbose=1),this.get_config("img")&&(t.img=1),f||(r?t.callback=r:(a||this.get_config("test"))&&(t.callback="(function(){})"));var c={};if(c.ip=this.get_config("ip")?1:0,c._=(new Date).getTime().toString(),p&&(s=Array.isArray(t)?"data="+t:"data="+t.data,delete t.data),e+="?"+i._.HTTPBuildQuery(c),"img"in t){var u=i.document.createElement("img");u.src=e,i.document.body.appendChild(u)}else if(_){var d=new Blob([s],{type:"application/x-www-form-urlencoded"});v(e,d)}else if(f)try{var l=new XMLHttpRequest;l.open(o.method,e,!0);var g=this.get_config("xhr_headers");p&&(g["Content-Type"]="application/x-www-form-urlencoded"),i._.each(g,function(e,t){l.setRequestHeader(t,e)}),l.withCredentials=!0,l.onreadystatechange=function(){if(4===l.readyState)if(200===l.status){if(r){var e;try{e=i._.JSONDecode(l.responseText)}catch(o){return void i.console.error(o)}r(e)}}else{var t="Bad HTTP status: "+l.status+" "+l.statusText;i.console.error(t),r&&r(a?{status:0,error:t}:0)}},l.send(s)}catch(b){i.console.error(b)}else{var h=i.document.createElement("script");h.type="text/javascript",h.async=!0,h.defer=!0,h.src=e;var m=i.document.getElementsByTagName("script")[0];m.parentNode.insertBefore(h,m)}}},w.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)},w.prototype.push=function(e){this._execute_array([e])},w.prototype.capture=(0,a.addOptOutCheckPostHogLib)(function(e,t,o,r){r||"function"!=typeof o||(r=o,o=null);var n=(o=o||g).transport;if(n&&(o.transport=n),"function"!=typeof r&&(r=l),i._.isUndefined(e))i.console.error("No event name provided to posthog.capture");else{if(!this._event_is_disabled(e)){(t=t||{}).token=this.get_config("token");var s=this.persistence.remove_event_timer(e);if(!i._.isUndefined(s)){var _=(new Date).getTime()-s;t.$duration=parseFloat((_/1e3).toFixed(3))}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),t=i._.extend({},i._.info.properties(),this.persistence.properties(),t);var p=this.get_config("property_blacklist");i._.isArray(p)?i._.each(p,function(e){delete t[e]}):i.console.error("Invalid value for property_blacklist config: "+p);var a={event:e,properties:t},c=i._.truncate(a,255),u=i._.JSONEncode(c),d=i._.base64Encode(u),h=this.get_config("api_host")+"/e/",f=this._prepare_callback(r,c),y=r!==l||o!==g;return!this.get_config("request_batching")||y?this._send_request(h,{data:d},o,f):(a.timestamp=new Date,this._event_enqueue(h,a,o,f)),c}r(0)}}),w.prototype._create_map_key=function(e,t){return e+"_"+JSON.stringify(t)},w.prototype._remove_group_from_cache=function(e,t){delete this._cached_groups[this._create_map_key(e,t)]},w.prototype.capture_pageview=function(e){i._.isUndefined(e)&&(e=i.document.location.href),this.capture("$pageview")},w.prototype.capture_links=function(){return this._capture_dom.call(this,n.LinkCapture,arguments)},w.prototype.capture_forms=function(){return this._capture_dom.call(this,FormCaptureer,arguments)},w.prototype.register=function(e,t){this.persistence.register(e,t)},w.prototype.register_once=function(e,t,o){this.persistence.register_once(e,t,o)},w.prototype.unregister=function(e){this.persistence.unregister(e)},w.prototype._register_single=function(e,t){var o={};o[e]=t,this.register(o)},w.prototype.isFeatureEnabled=function(e){return this.feature_flags.isFeatureEnabled(e)},w.prototype.onFeatureFlags=function(e){return this.feature_flags.onFeatureFlags(e)},w.prototype.identify=function(e,t,o){if(e){var r=this.get_distinct_id();if(this.register({$user_id:e}),!this.get_property("$device_id")){var n=r;this.register_once({$had_persisted_distinct_id:!0,$device_id:n},"")}e!==r&&e!==this.get_property(p.ALIAS_ID_KEY)&&(this.unregister(p.ALIAS_ID_KEY),this.register({distinct_id:e})),this._flags.identify_called=!0,this.people._flush(t,o),e!==r&&this.capture("$identify",{distinct_id:e,$anon_distinct_id:r})}else i.console.error("Unique user id has not been set in posthog.identify")},w.prototype.reset=function(e){var t=this.get_property("$device_id");this.persistence.clear(),this._flags.identify_called=!1;var o=i._.UUID();this.register_once({distinct_id:o,$device_id:e?o:t},"")},w.prototype.get_distinct_id=function(){return this.get_property("distinct_id")},w.prototype.alias=function(e,t){if(e===this.get_property(p.PEOPLE_DISTINCT_ID_KEY))return i.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(p.ALIAS_ID_KEY,e),this.capture("$create_alias",{alias:e,distinct_id:t},function(){o.identify(e)})):(i.console.error("alias matches current distinct_id - skipping api call."),this.identify(e),-1)},w.prototype.set_config=function(e){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),o.default.DEBUG=o.default.DEBUG||this.get_config("debug"))},w.prototype.get_config=function(e){return this.config[e]},w.prototype.get_property=function(e){return this.persistence.props[e]},w.prototype.toString=function(){var e=this.get_config("name");return e!==h&&(e=h+"."+e),e},w.prototype._event_is_disabled=function(e){return i._.isBlockedUA(i.userAgent)||this._flags.disable_all_events||i._.include(this.__disabled_events,e)},w.prototype._gdpr_init=function(){"localStorage"===this.get_config("opt_out_capturing_persistence_type")&&i._.localStorage.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")&&!i._.cookie.get("ph_optout")||(i._.cookie.remove("ph_optout"),this.opt_out_capturing({clear_persistence:this.get_config("opt_out_persistence_by_default")}))},w.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)},w.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),i._.localStorage.is_supported()||(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})},w.prototype.opt_in_capturing=function(e){e=i._.extend({enable_persistence:!0},e),this._gdpr_call_func(a.optIn,e),this._gdpr_update_persistence(e)},w.prototype.opt_in_captureing=function(e){q("opt_in_captureing"),this.opt_in_capturing(e)},w.prototype.opt_out_capturing=function(e){(e=i._.extend({clear_persistence:!0,delete_user:!0},e)).delete_user&&this.people&&this.people._identify_called()&&(this.people.delete_user(),this.people.clear_charges()),this._gdpr_call_func(a.optOut,e),this._gdpr_update_persistence(e)},w.prototype.opt_out_captureing=function(e){q("opt_out_captureing"),this.opt_out_capturing(e)},w.prototype.has_opted_in_capturing=function(e){return this._gdpr_call_func(a.hasOptedIn,e)},w.prototype.has_opted_in_captureing=function(e){return q("has_opted_in_captureing"),this.has_opted_in_capturing(e)},w.prototype.has_opted_out_capturing=function(e){return this._gdpr_call_func(a.hasOptedOut,e)},w.prototype.has_opted_out_captureing=function(e){return q("has_opted_out_captureing"),this.has_opted_out_capturing(e)},w.prototype.clear_opt_in_out_capturing=function(e){e=i._.extend({enable_persistence:!0},e),this._gdpr_call_func(a.clearOptInOut,e),this._gdpr_update_persistence(e)},w.prototype.clear_opt_in_out_captureing=function(e){q("clear_opt_in_out_captureing"),this.clear_opt_in_out_capturing(e)},w.prototype.init=w.prototype.init,w.prototype.reset=w.prototype.reset,w.prototype.capture=w.prototype.capture,w.prototype.capture_links=w.prototype.capture_links,w.prototype.capture_forms=w.prototype.capture_forms,w.prototype.capture_pageview=w.prototype.capture_pageview,w.prototype.register=w.prototype.register,w.prototype.register_once=w.prototype.register_once,w.prototype.unregister=w.prototype.unregister,w.prototype.identify=w.prototype.identify,w.prototype.alias=w.prototype.alias,w.prototype.set_config=w.prototype.set_config,w.prototype.get_config=w.prototype.get_config,w.prototype.get_property=w.prototype.get_property,w.prototype.get_distinct_id=w.prototype.get_distinct_id,w.prototype.toString=w.prototype.toString,w.prototype.opt_out_captureing=w.prototype.opt_out_captureing,w.prototype.opt_in_captureing=w.prototype.opt_in_captureing,w.prototype.has_opted_out_captureing=w.prototype.has_opted_out_captureing,w.prototype.has_opted_in_captureing=w.prototype.has_opted_in_captureing,w.prototype.clear_opt_in_out_captureing=w.prototype.clear_opt_in_out_captureing,w.prototype.opt_out_capturing=w.prototype.opt_out_capturing,w.prototype.opt_in_capturing=w.prototype.opt_in_capturing,w.prototype.has_opted_out_capturing=w.prototype.has_opted_out_capturing,w.prototype.has_opted_in_capturing=w.prototype.has_opted_in_capturing,w.prototype.clear_opt_in_out_capturing=w.prototype.clear_opt_in_out_capturing,w.prototype.isFeatureEnabled=w.prototype.isFeatureEnabled,w.prototype.onFeatureFlags=w.prototype.onFeatureFlags,p.PostHogPersistence.prototype.properties=p.PostHogPersistence.prototype.properties,p.PostHogPersistence.prototype.update_search_keyword=p.PostHogPersistence.prototype.update_search_keyword,p.PostHogPersistence.prototype.update_referrer_info=p.PostHogPersistence.prototype.update_referrer_info,p.PostHogPersistence.prototype.get_cross_subdomain=p.PostHogPersistence.prototype.get_cross_subdomain,p.PostHogPersistence.prototype.clear=p.PostHogPersistence.prototype.clear,i._.safewrap_class(w,["identify"]);var P={},x=function(){i._.each(P,function(e,o){o!==h&&(t[o]=e)}),t._=i._},E=function(){t.init=function(o,r,n){if(n)return t[n]||(t[n]=P[n]=k(o,r,n),t[n]._loaded()),t[n];var s=t;P[h]?s=P[h]:o&&((s=k(o,r,h))._loaded(),P[h]=s),t=s,e===d&&(i.window[h]=t),x()}},S=function(){function e(){e.done||(e.done=!0,b=!0,y=!1,i._.each(P,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 A(){e=d,i._.isUndefined(i.window.posthog)&&(i.window.posthog=[]),(t=i.window.posthog).__loaded||t.config&&t.persistence?i.console.error("PostHog library has already been downloaded at least once."):(i._.each(t._i,function(e){e&&i._.isArray(e)&&(P[e[e.length-1]]=k.apply(this,e))}),E(),t.init(),i._.each(P,function(e){e._loaded()}),S())}function O(){return e=u,t=new w,E(),t.init(),S(),t}
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.init_from_snippet=A,exports.init_as_module=O;var e,t,o=c(require("./config")),i=require("./utils"),r=require("./autocapture"),n=require("./dom-capture"),s=require("./posthog-people"),_=require("./posthog-featureflags"),p=require("./posthog-persistence"),a=require("./gdpr-utils");function c(e){return e&&e.__esModule?e:{default:e}}var u=0,d=1,l=function(){},g={},h="posthog",f=i.window.XMLHttpRequest&&"withCredentials"in new XMLHttpRequest,y=!f&&-1===i.userAgent.indexOf("MSIE")&&-1===i.userAgent.indexOf("Mozilla"),v=i.window.navigator.sendBeacon;v&&(v=i._.bind(v,i.navigator));var m={api_host:"https://t.posthog.com",api_method:"POST",api_transport:"XHR",autocapture:!0,cdn:"https://cdn.posthog.com",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,capture_links_timeout:300,cookie_expiration:365,upgrade:!1,disable_persistence:!1,disable_cookie:!1,secure_cookie:!1,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:[],xhr_headers:{},inapp_protocol:"//",inapp_link_new_window:!1,request_batching:!0},b=!1,w=function(){},k=function(n,p,a){var c,d=a===h?t:t[a];if(d&&e===u)c=d;else{if(d&&!i._.isArray(d))return void i.console.error("You have already initialized "+a);c=new w}if(c._cached_groups={},c._user_decide_check_complete=!1,c._events_captureed_before_user_decide_check_complete=[],c._init(n,p,a),c.people=new s.PostHogPeople,c.people._init(c),c.feature_flags=new _.PostHogFeatureFlags,c.feature_flags._init(c),o.default.DEBUG=o.default.DEBUG||c.get_config("debug"),c.__autocapture_enabled=c.get_config("autocapture"),c.get_config("autocapture")){r.autocapture.enabledForProject(c.get_config("token"),100,100)?r.autocapture.isBrowserSupported()?r.autocapture.init(c):(c.__autocapture_enabled=!1,i.console.log("Disabling Automatic Event Collection because this browser is not supported")):(c.__autocapture_enabled=!1,i.console.log("Not in active bucket: disabling Automatic Event Collection."))}return!i._.isUndefined(d)&&i._.isArray(d)&&(c._execute_array.call(c.people,d.people),c._execute_array(d)),c};function q(e){i.window.console.warn("WARNING! posthog."+e+" is deprecated and will be removed soon! Please use posthog."+e.split("captureing").join("capturing")+' instead (without the "e")!')}w.prototype.init=function(e,o,r){if(i._.isUndefined(r))i.console.error("You must name your new library: init(token, config, name)");else{if(r!==h){var n=k(e,o,r);return t[r]=n,n._loaded(),n}i.console.error("You must initialize the main posthog object right after you include the PostHog js snippet")}},w.prototype._init=function(e,t,o){this.__loaded=!0,this.config={},this._triggered_notifs=[],this.set_config(i._.extend({},m,t,{name:o,token:e,callback_fn:(o===h?o:h+"."+o)+"._jsc"})),this._jsc=function(){},this._event_queue=[],this._empty_queue_count=0,this._should_poll=!0,this._poller=function(){},this.__dom_loaded_queue=[],this.__request_queue=[],this.__disabled_events=[],this._flags={disable_all_events:!1,identify_called:!1},this.persistence=this.cookie=new p.PostHogPersistence(this.config),this._gdpr_init();var r=i._.UUID();this.get_distinct_id()||this.register_once({distinct_id:r,$device_id:r},""),i.window.addEventListener&&i.window.addEventListener("unload",this._handle_unload.bind(this))},w.prototype._loaded=function(){this.get_config("loaded")(this),this._start_queue_if_opted_in(),this.get_config("capture_pageview")&&this.capture_pageview()},w.prototype._start_queue_if_opted_in=function(){this.has_opted_out_capturing()||this.get_config("request_batching")&&this._event_queue_poll()},w.prototype._dom_loaded=function(){i._.each(this.__dom_loaded_queue,function(e){this._capture_dom.apply(this,e)},this),this.has_opted_out_capturing()||i._.each(this.__request_queue,function(e){this._send_request.apply(this,e)},this),delete this.__dom_loaded_queue,delete this.__request_queue,this._start_queue_if_opted_in()},w.prototype._capture_dom=function(e,t){if(this.get_config("img"))return i.console.error("You can't use DOM capturing functions with img = true."),!1;if(!b)return this.__dom_loaded_queue.push([e,t]),!1;var o=(new e).init(this);return o.capture.apply(o,t)},w.prototype._prepare_callback=function(e,t){if(i._.isUndefined(e))return null;if(f){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},w.prototype._event_enqueue=function(e,t,o,i){this._event_queue.push({url:e,data:t,options:o,callback:i}),this._should_poll||(this._should_poll=!0,this._event_queue_poll())},w.prototype._format_event_queue_data=function(){var e={};return i._.each(this._event_queue,function(t){var o=t.url,i=t.data;void 0===e[o]&&(e[o]=[]),e[o].push(i)}),e},w.prototype._event_queue_poll=function(){var e=this;clearInterval(this._poller),this._poller=setTimeout(function(){if(e._event_queue.length>0){var t=e._format_event_queue_data(),o=function(o){var r=t[o];i._.each(r,function(e,t){r[t].offset=Math.abs(r[t].timestamp-new Date),delete r[t].timestamp}),n=i._.JSONEncode(r),s=i._.base64Encode(n),e._send_request(o,{data:s},g,l)};for(var r in t){var n,s;o(r)}e._event_queue.length=0}else e._empty_queue_count++;e._empty_queue_count>4&&(e._should_poll=!1,e._empty_queue_count=0),e._should_poll&&e._event_queue_poll()},3e3)},w.prototype._handle_unload=function(){if(this.get_config("request_batching")){clearInterval(this._poller),this.capture("$pageleave");var e={};for(var t in this._event_queue.length>0&&(e=this._format_event_queue_data()),this._event_queue.length=0,e){var o=i._.base64Encode(i._.JSONEncode(e[t]));this._send_request(t,{data:o},{transport:"sendbeacon"},l)}}else this.capture("$pageleave",null,{transport:"sendbeacon"})},w.prototype._send_request=function(e,t,o,r){if(y)this.__request_queue.push(arguments);else{var n={method:this.get_config("api_method"),transport:this.get_config("api_transport")},s=null;r||!i._.isFunction(o)&&"string"!=typeof o||(r=o,o=null),o=i._.extend(n,o||{}),f||(o.method="GET");var _=v&&"sendbeacon"===o.transport.toLowerCase(),p=_||"POST"===o.method,a=this.get_config("verbose");t.verbose&&(a=!0),this.get_config("test")&&(t.test=1),a&&(t.verbose=1),this.get_config("img")&&(t.img=1),f||(r?t.callback=r:(a||this.get_config("test"))&&(t.callback="(function(){})"));var c={};if(c.ip=this.get_config("ip")?1:0,c._=(new Date).getTime().toString(),p&&(s=Array.isArray(t)?"data="+t:"data="+t.data,delete t.data),e+="?"+i._.HTTPBuildQuery(c),"img"in t){var u=i.document.createElement("img");u.src=e,i.document.body.appendChild(u)}else if(_){var d=new Blob([s],{type:"application/x-www-form-urlencoded"});v(e,d)}else if(f)try{var l=new XMLHttpRequest;l.open(o.method,e,!0);var g=this.get_config("xhr_headers");p&&(g["Content-Type"]="application/x-www-form-urlencoded"),i._.each(g,function(e,t){l.setRequestHeader(t,e)}),l.withCredentials=!0,l.onreadystatechange=function(){if(4===l.readyState)if(200===l.status){if(r){var e;try{e=i._.JSONDecode(l.responseText)}catch(o){return void i.console.error(o)}r(e)}}else{var t="Bad HTTP status: "+l.status+" "+l.statusText;i.console.error(t),r&&r(a?{status:0,error:t}:0)}},l.send(s)}catch(b){i.console.error(b)}else{var h=i.document.createElement("script");h.type="text/javascript",h.async=!0,h.defer=!0,h.src=e;var m=i.document.getElementsByTagName("script")[0];m.parentNode.insertBefore(h,m)}}},w.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)},w.prototype.push=function(e){this._execute_array([e])},w.prototype.capture=(0,a.addOptOutCheckPostHogLib)(function(e,t,o,r){r||"function"!=typeof o||(r=o,o=null);var n=(o=o||g).transport;if(n&&(o.transport=n),"function"!=typeof r&&(r=l),i._.isUndefined(e))i.console.error("No event name provided to posthog.capture");else{if(!this._event_is_disabled(e)){(t=t||{}).token=this.get_config("token");var s=this.persistence.remove_event_timer(e);if(!i._.isUndefined(s)){var _=(new Date).getTime()-s;t.$duration=parseFloat((_/1e3).toFixed(3))}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),t=i._.extend({},i._.info.properties(),this.persistence.properties(),t);var p=this.get_config("property_blacklist");i._.isArray(p)?i._.each(p,function(e){delete t[e]}):i.console.error("Invalid value for property_blacklist config: "+p);var a={event:e,properties:t},c=i._.truncate(a,255),u=i._.JSONEncode(c),d=i._.base64Encode(u),h=this.get_config("api_host")+"/e/",f=this._prepare_callback(r,c),y=r!==l||o!==g;return!this.get_config("request_batching")||y?this._send_request(h,{data:d},o,f):(a.timestamp=new Date,this._event_enqueue(h,a,o,f)),c}r(0)}}),w.prototype._create_map_key=function(e,t){return e+"_"+JSON.stringify(t)},w.prototype._remove_group_from_cache=function(e,t){delete this._cached_groups[this._create_map_key(e,t)]},w.prototype.capture_pageview=function(e){i._.isUndefined(e)&&(e=i.document.location.href),this.capture("$pageview")},w.prototype.capture_links=function(){return this._capture_dom.call(this,n.LinkCapture,arguments)},w.prototype.capture_forms=function(){return this._capture_dom.call(this,FormCaptureer,arguments)},w.prototype.register=function(e,t){this.persistence.register(e,t)},w.prototype.register_once=function(e,t,o){this.persistence.register_once(e,t,o)},w.prototype.unregister=function(e){this.persistence.unregister(e)},w.prototype._register_single=function(e,t){var o={};o[e]=t,this.register(o)},w.prototype.isFeatureEnabled=function(e){return this.feature_flags.isFeatureEnabled(e)},w.prototype.onFeatureFlags=function(e){return this.feature_flags.onFeatureFlags(e)},w.prototype.identify=function(e,t,o){if(e){var r=this.get_distinct_id();if(this.register({$user_id:e}),!this.get_property("$device_id")){var n=r;this.register_once({$had_persisted_distinct_id:!0,$device_id:n},"")}e!==r&&e!==this.get_property(p.ALIAS_ID_KEY)&&(this.unregister(p.ALIAS_ID_KEY),this.register({distinct_id:e})),this._flags.identify_called=!0,this.people._flush(t,o),e!==r&&this.capture("$identify",{distinct_id:e,$anon_distinct_id:r})}else i.console.error("Unique user id has not been set in posthog.identify")},w.prototype.reset=function(e){var t=this.get_property("$device_id");this.persistence.clear(),this._flags.identify_called=!1;var o=i._.UUID();this.register_once({distinct_id:o,$device_id:e?o:t},"")},w.prototype.get_distinct_id=function(){return this.get_property("distinct_id")},w.prototype.alias=function(e,t){if(e===this.get_property(p.PEOPLE_DISTINCT_ID_KEY))return i.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(p.ALIAS_ID_KEY,e),this.capture("$create_alias",{alias:e,distinct_id:t},function(){o.identify(e)})):(i.console.error("alias matches current distinct_id - skipping api call."),this.identify(e),-1)},w.prototype.set_config=function(e){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),o.default.DEBUG=o.default.DEBUG||this.get_config("debug"))},w.prototype.get_config=function(e){return this.config[e]},w.prototype.get_property=function(e){return this.persistence.props[e]},w.prototype.toString=function(){var e=this.get_config("name");return e!==h&&(e=h+"."+e),e},w.prototype._event_is_disabled=function(e){return i._.isBlockedUA(i.userAgent)||this._flags.disable_all_events||i._.include(this.__disabled_events,e)},w.prototype._gdpr_init=function(){"localStorage"===this.get_config("opt_out_capturing_persistence_type")&&i._.localStorage.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")&&!i._.cookie.get("ph_optout")||(i._.cookie.remove("ph_optout"),this.opt_out_capturing({clear_persistence:this.get_config("opt_out_persistence_by_default")}))},w.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)},w.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),i._.localStorage.is_supported()||(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})},w.prototype.opt_in_capturing=function(e){e=i._.extend({enable_persistence:!0},e),this._gdpr_call_func(a.optIn,e),this._gdpr_update_persistence(e)},w.prototype.opt_in_captureing=function(e){q("opt_in_captureing"),this.opt_in_capturing(e)},w.prototype.opt_out_capturing=function(e){(e=i._.extend({clear_persistence:!0,delete_user:!0},e)).delete_user&&this.people&&this.people._identify_called()&&(this.people.delete_user(),this.people.clear_charges()),this._gdpr_call_func(a.optOut,e),this._gdpr_update_persistence(e)},w.prototype.opt_out_captureing=function(e){q("opt_out_captureing"),this.opt_out_capturing(e)},w.prototype.has_opted_in_capturing=function(e){return this._gdpr_call_func(a.hasOptedIn,e)},w.prototype.has_opted_in_captureing=function(e){return q("has_opted_in_captureing"),this.has_opted_in_capturing(e)},w.prototype.has_opted_out_capturing=function(e){return this._gdpr_call_func(a.hasOptedOut,e)},w.prototype.has_opted_out_captureing=function(e){return q("has_opted_out_captureing"),this.has_opted_out_capturing(e)},w.prototype.clear_opt_in_out_capturing=function(e){e=i._.extend({enable_persistence:!0},e),this._gdpr_call_func(a.clearOptInOut,e),this._gdpr_update_persistence(e)},w.prototype.clear_opt_in_out_captureing=function(e){q("clear_opt_in_out_captureing"),this.clear_opt_in_out_capturing(e)},w.prototype.init=w.prototype.init,w.prototype.reset=w.prototype.reset,w.prototype.capture=w.prototype.capture,w.prototype.capture_links=w.prototype.capture_links,w.prototype.capture_forms=w.prototype.capture_forms,w.prototype.capture_pageview=w.prototype.capture_pageview,w.prototype.register=w.prototype.register,w.prototype.register_once=w.prototype.register_once,w.prototype.unregister=w.prototype.unregister,w.prototype.identify=w.prototype.identify,w.prototype.alias=w.prototype.alias,w.prototype.set_config=w.prototype.set_config,w.prototype.get_config=w.prototype.get_config,w.prototype.get_property=w.prototype.get_property,w.prototype.get_distinct_id=w.prototype.get_distinct_id,w.prototype.toString=w.prototype.toString,w.prototype.opt_out_captureing=w.prototype.opt_out_captureing,w.prototype.opt_in_captureing=w.prototype.opt_in_captureing,w.prototype.has_opted_out_captureing=w.prototype.has_opted_out_captureing,w.prototype.has_opted_in_captureing=w.prototype.has_opted_in_captureing,w.prototype.clear_opt_in_out_captureing=w.prototype.clear_opt_in_out_captureing,w.prototype.opt_out_capturing=w.prototype.opt_out_capturing,w.prototype.opt_in_capturing=w.prototype.opt_in_capturing,w.prototype.has_opted_out_capturing=w.prototype.has_opted_out_capturing,w.prototype.has_opted_in_capturing=w.prototype.has_opted_in_capturing,w.prototype.clear_opt_in_out_capturing=w.prototype.clear_opt_in_out_capturing,w.prototype.isFeatureEnabled=w.prototype.isFeatureEnabled,w.prototype.onFeatureFlags=w.prototype.onFeatureFlags,p.PostHogPersistence.prototype.properties=p.PostHogPersistence.prototype.properties,p.PostHogPersistence.prototype.update_search_keyword=p.PostHogPersistence.prototype.update_search_keyword,p.PostHogPersistence.prototype.update_referrer_info=p.PostHogPersistence.prototype.update_referrer_info,p.PostHogPersistence.prototype.get_cross_subdomain=p.PostHogPersistence.prototype.get_cross_subdomain,p.PostHogPersistence.prototype.clear=p.PostHogPersistence.prototype.clear,i._.safewrap_class(w,["identify"]);var P={},x=function(){i._.each(P,function(e,o){o!==h&&(t[o]=e)}),t._=i._},E=function(){t.init=function(o,r,n){if(n)return t[n]||(t[n]=P[n]=k(o,r,n),t[n]._loaded()),t[n];var s=t;P[h]?s=P[h]:o&&((s=k(o,r,h))._loaded(),P[h]=s),t=s,e===d&&(i.window[h]=t),x()}},S=function(){function e(){e.done||(e.done=!0,b=!0,y=!1,i._.each(P,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 A(){e=d,i._.isUndefined(i.window.posthog)&&(i.window.posthog=[]),(t=i.window.posthog).__loaded||t.config&&t.persistence?i.console.error("PostHog library has already been downloaded at least once."):(i._.each(t._i,function(e){e&&i._.isArray(e)&&(P[e[e.length-1]]=k.apply(this,e))}),E(),t.init(),i._.each(P,function(e){e._loaded()}),S())}function O(){return e=u,t=new w,E(),t.init(),S(),t}
},{"./config":"itQ5","./utils":"FOZT","./autocapture":"gR3r","./dom-capture":"OjnC","./posthog-people":"ecEG","./posthog-featureflags":"aVqC","./posthog-persistence":"MAdm","./gdpr-utils":"rxSh"}],"e2xX":[function(require,module,exports) {
"use strict";var r=require("./posthog-core");(0,r.init_from_snippet)();
},{"./posthog-core":"ok3T"}]},{},["e2xX"], null)
{
"name": "posthog-js",
"version": "1.3.1",
"version": "1.3.2",
"description": "Posthog-js allows you to automatically capture usage and send events to PostHog.",

@@ -5,0 +5,0 @@ "repository": "https://github.com/PostHog/posthog-js",

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc