posthog-js
Advanced tools
Comparing version 1.3.0 to 1.3.1
@@ -0,1 +1,4 @@ | ||
## 1.3.1 - 2020-07-13 | ||
- Support loading the toolbar with a `__posthog` has param (was: `state`) and `ph_authorize` action. | ||
## 1.3.0 - 2020-07-03 | ||
@@ -2,0 +5,0 @@ - Add TypeScript defintions |
@@ -8,3 +8,3 @@ 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) { | ||
},{"./utils":"FOZT"}],"gR3r":[function(require,module,exports) { | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.autocapture=void 0;var e=require("./utils"),t=require("./autocapture-utils"),o={_initializedTokens:[],_previousElementSibling:function(e){if(e.previousElementSibling)return e.previousElementSibling;do{e=e.previousSibling}while(e&&!(0,t.isElementNode)(e));return e},_loadScript:function(e,t){var o=document.createElement("script");o.type="text/javascript",o.src=e,o.onload=t;var r=document.getElementsByTagName("script");r.length>0?r[0].parentNode.insertBefore(o,r[0]):document.body.appendChild(o)},_getPropertiesFromElement:function(o){var r=o.tagName.toLowerCase(),n={tag_name:r};t.usefulElements.indexOf(r)>-1&&(n.$el_text=(0,t.getSafeText)(o));var i=(0,t.getClassName)(o);i.length>0&&(n.classes=i.split(" ")),(0,t.shouldCaptureElement)(o)&&e._.each(o.attributes,function(e){(0,t.shouldCaptureValue)(e.value)&&(n["attr__"+e.name]=e.value)});for(var a=1,s=1,u=o;u=this._previousElementSibling(u);)a++,u.tagName===o.tagName&&s++;return n.nth_child=a,n.nth_of_type=s,n},_getDefaultProperties:function(e){return{$event_type:e,$ce_version:1}},_extractCustomPropertyValue:function(o){var r=[];return e._.each(document.querySelectorAll(o.css_selector),function(e){var o;["input","select"].indexOf(e.tagName.toLowerCase())>-1?o=e.value:e.textContent&&(o=e.textContent),(0,t.shouldCaptureValue)(o)&&r.push(o)}),r.join(", ")},_getCustomProperties:function(o){var r={};return e._.each(this._customProperties,function(n){e._.each(n.event_selectors,function(i){var a=document.querySelectorAll(i);e._.each(a,function(i){e._.includes(o,i)&&(0,t.shouldCaptureElement)(i)&&(r[n.name]=this._extractCustomPropertyValue(n))},this)},this)},this),r},_getEventTarget:function(e){return void 0===e.target?e.srcElement:e.target},_captureEvent:function(o,r){var n=this._getEventTarget(o);if((0,t.isTextNode)(n)&&(n=n.parentNode),(0,t.shouldCaptureDomEvent)(n,o)){for(var i=[n],a=n;a.parentNode&&!(0,t.isTag)(a,"body");)i.push(a.parentNode),a=a.parentNode;var s,u=[],d=!1;if(e._.each(i,function(o){var r=(0,t.shouldCaptureElement)(o);"a"===o.tagName.toLowerCase()&&(s=o.getAttribute("href"),s=r&&(0,t.shouldCaptureValue)(s)&&s);var n=(0,t.getClassName)(o).split(" ");e._.includes(n,"ph-no-capture")&&(d=!0),u.push(this._getPropertiesFromElement(o))},this),u[0].$el_text=(0,t.getSafeText)(n),s&&(u[0].attr__href=s),d)return!1;var c=(0,t.getSafeText)(n);c&&c.length&&c;var l=e._.extend(this._getDefaultProperties(o.type),{$elements:u},this._getCustomProperties(i));return r.capture("$autocapture",l),!0}},_navigate:function(e){window.location.href=e},_addDomEventHandlers:function(t){var o=e._.bind(function(e){e=e||window.event,this._captureEvent(e,t)},this);e._.register_event(document,"submit",o,!1,!0),e._.register_event(document,"change",o,!1,!0),e._.register_event(document,"click",o,!1,!0)},_customProperties:{},init:function(t){if(!this._maybeLoadEditor(t)){var o=t.get_config("token");if(this._initializedTokens.indexOf(o)>-1)console.log('autocapture already initialized for token "'+o+'"');else{this._initializedTokens.push(o);var r=e._.bind(function(e){if(!document||!document.body)return console.log("document not ready yet, trying again in 500 milliseconds..."),void setTimeout(function(){r(e)},500);var o=e.editorParams||(e.toolbarVersion?{toolbarVersion:e.toolbarVersion}:{});e.isAuthenticated&&o.toolbarVersion&&0===o.toolbarVersion.indexOf("toolbar")&&(this._loadEditor(t,Object.assign({},o,{apiURL:t.get_config("api_host")})),t.set_config({debug:!0})),e&&e.config&&!0===e.config.enable_collect_everything?(e.custom_properties&&(this._customProperties=e.custom_properties),this._addDomEventHandlers(t)):t.__autocapture_enabled=!1,e.featureFlags&&e.featureFlags.length>0?t.persistence.register({$active_feature_flags:e.featureFlags}):t.persistence.unregister("$active_feature_flags")},this),n=e._.JSONEncode({token:o,distinct_id:t.get_distinct_id()}),i=e._.base64Encode(n);t._send_request(t.get_config("api_host")+"/decide/",{data:i},{method:"POST"},t._prepare_callback(r))}}},_editorParamsFromHash:function(t,o){try{var r=e._.getHashParam(o,"state");return JSON.parse(decodeURIComponent(r))}catch(n){console.error("Unable to parse data from hash",n)}return{}},_maybeLoadEditor:function(t){try{var o,r=e._.getHashParam(window.location.hash,"state"),n=r?JSON.parse(decodeURIComponent(r)):null;return n&&"mpeditor"===n.action?(o=n)&&Object.keys(o).length>0&&(window.sessionStorage.setItem("_postHogEditorParams",JSON.stringify(o)),n.desiredHash?window.location.hash=n.desiredHash:window.history?history.replaceState("",document.title,window.location.pathname+window.location.search):window.location.hash=""):delete(o=JSON.parse(window.sessionStorage.getItem("_postHogEditorParams")||"{}")).userIntent,!(!o.token||t.get_config("token")!==o.token)&&(this._loadEditor(t,o),!0)}catch(i){return!1}},_loadEditor:function(t,o){var r=this;if(!window._postHogToolbarLoaded){window._postHogToolbarLoaded=!0;var n=o.jsURL||o.apiURL||t.get_config("api_host"),i=o.toolbarVersion&&0===o.toolbarVersion.indexOf("toolbar")?"toolbar.js":"editor.js",a=n+(n.endsWith("/")?"":"/")+"static/"+i+"?_ts="+(new Date).getTime();return this._loadScript(a,function(){window.ph_load_editor(o)}),e._.register_event(window,"turbolinks:load",function(){window._postHogToolbarLoaded=!1,r._loadEditor(t,o)}),!0}return!1},enabledForProject:function(t,o,r){o=e._.isUndefined(o)?10:o,r=e._.isUndefined(r)?10:r;for(var n=0,i=0;i<t.length;i++)n+=t.charCodeAt(i);return n%o<r},isBrowserSupported:function(){return e._.isFunction(document.querySelectorAll)}};exports.autocapture=o,e._.bind_instance_methods(o),e._.safewrap_instance_methods(o); | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.autocapture=void 0;var e=require("./utils"),t=require("./autocapture-utils"),o={_initializedTokens:[],_previousElementSibling:function(e){if(e.previousElementSibling)return e.previousElementSibling;do{e=e.previousSibling}while(e&&!(0,t.isElementNode)(e));return e},_loadScript:function(e,t){var o=document.createElement("script");o.type="text/javascript",o.src=e,o.onload=t;var n=document.getElementsByTagName("script");n.length>0?n[0].parentNode.insertBefore(o,n[0]):document.body.appendChild(o)},_getPropertiesFromElement:function(o){var n=o.tagName.toLowerCase(),i={tag_name:n};t.usefulElements.indexOf(n)>-1&&(i.$el_text=(0,t.getSafeText)(o));var r=(0,t.getClassName)(o);r.length>0&&(i.classes=r.split(" ")),(0,t.shouldCaptureElement)(o)&&e._.each(o.attributes,function(e){(0,t.shouldCaptureValue)(e.value)&&(i["attr__"+e.name]=e.value)});for(var a=1,s=1,u=o;u=this._previousElementSibling(u);)a++,u.tagName===o.tagName&&s++;return i.nth_child=a,i.nth_of_type=s,i},_getDefaultProperties:function(e){return{$event_type:e,$ce_version:1}},_extractCustomPropertyValue:function(o){var n=[];return e._.each(document.querySelectorAll(o.css_selector),function(e){var o;["input","select"].indexOf(e.tagName.toLowerCase())>-1?o=e.value:e.textContent&&(o=e.textContent),(0,t.shouldCaptureValue)(o)&&n.push(o)}),n.join(", ")},_getCustomProperties:function(o){var n={};return e._.each(this._customProperties,function(i){e._.each(i.event_selectors,function(r){var a=document.querySelectorAll(r);e._.each(a,function(r){e._.includes(o,r)&&(0,t.shouldCaptureElement)(r)&&(n[i.name]=this._extractCustomPropertyValue(i))},this)},this)},this),n},_getEventTarget:function(e){return void 0===e.target?e.srcElement:e.target},_captureEvent:function(o,n){var i=this._getEventTarget(o);if((0,t.isTextNode)(i)&&(i=i.parentNode),(0,t.shouldCaptureDomEvent)(i,o)){for(var r=[i],a=i;a.parentNode&&!(0,t.isTag)(a,"body");)r.push(a.parentNode),a=a.parentNode;var s,u=[],d=!1;if(e._.each(r,function(o){var n=(0,t.shouldCaptureElement)(o);"a"===o.tagName.toLowerCase()&&(s=o.getAttribute("href"),s=n&&(0,t.shouldCaptureValue)(s)&&s);var i=(0,t.getClassName)(o).split(" ");e._.includes(i,"ph-no-capture")&&(d=!0),u.push(this._getPropertiesFromElement(o))},this),u[0].$el_text=(0,t.getSafeText)(i),s&&(u[0].attr__href=s),d)return!1;var c=(0,t.getSafeText)(i);c&&c.length&&c;var l=e._.extend(this._getDefaultProperties(o.type),{$elements:u},this._getCustomProperties(r));return n.capture("$autocapture",l),!0}},_navigate:function(e){window.location.href=e},_addDomEventHandlers:function(t){var o=e._.bind(function(e){e=e||window.event,this._captureEvent(e,t)},this);e._.register_event(document,"submit",o,!1,!0),e._.register_event(document,"change",o,!1,!0),e._.register_event(document,"click",o,!1,!0)},_customProperties:{},init:function(t){if(!this._maybeLoadEditor(t)){var o=t.get_config("token");if(this._initializedTokens.indexOf(o)>-1)console.log('autocapture already initialized for token "'+o+'"');else{this._initializedTokens.push(o);var n=e._.bind(function(e){if(!document||!document.body)return console.log("document not ready yet, trying again in 500 milliseconds..."),void setTimeout(function(){n(e)},500);var o=e.editorParams||(e.toolbarVersion?{toolbarVersion:e.toolbarVersion}:{});e.isAuthenticated&&o.toolbarVersion&&0===o.toolbarVersion.indexOf("toolbar")&&(this._loadEditor(t,Object.assign({},o,{apiURL:t.get_config("api_host")})),t.set_config({debug:!0})),e&&e.config&&!0===e.config.enable_collect_everything?(e.custom_properties&&(this._customProperties=e.custom_properties),this._addDomEventHandlers(t)):t.__autocapture_enabled=!1,e.featureFlags&&e.featureFlags.length>0?t.persistence.register({$active_feature_flags:e.featureFlags}):t.persistence.unregister("$active_feature_flags")},this),i=e._.JSONEncode({token:o,distinct_id:t.get_distinct_id()}),r=e._.base64Encode(i);t._send_request(t.get_config("api_host")+"/decide/",{data:r},{method:"POST"},t._prepare_callback(n))}}},_maybeLoadEditor:function(t){try{var o,n=e._.getHashParam(window.location.hash,"__posthog")||e._.getHashParam(window.location.hash,"state"),i=n?JSON.parse(decodeURIComponent(n)):null;return i&&("mpeditor"===i.action||"ph_authorize"===i.action)?(o=i)&&Object.keys(o).length>0&&(window.sessionStorage.setItem("_postHogEditorParams",JSON.stringify(o)),i.desiredHash?window.location.hash=i.desiredHash:window.history?history.replaceState("",document.title,window.location.pathname+window.location.search):window.location.hash=""):delete(o=JSON.parse(window.sessionStorage.getItem("_postHogEditorParams")||"{}")).userIntent,!(!o.token||t.get_config("token")!==o.token)&&(this._loadEditor(t,o),!0)}catch(r){return!1}},_loadEditor:function(t,o){var n=this;if(!window._postHogToolbarLoaded){window._postHogToolbarLoaded=!0;var i=o.jsURL||o.apiURL||t.get_config("api_host"),r=o.toolbarVersion&&0===o.toolbarVersion.indexOf("toolbar")?"toolbar.js":"editor.js",a=i+(i.endsWith("/")?"":"/")+"static/"+r+"?_ts="+(new Date).getTime();return this._loadScript(a,function(){window.ph_load_editor(o)}),e._.register_event(window,"turbolinks:load",function(){window._postHogToolbarLoaded=!1,n._loadEditor(t,o)}),!0}return!1},enabledForProject:function(t,o,n){o=e._.isUndefined(o)?10:o,n=e._.isUndefined(n)?10:n;for(var i=0,r=0;r<t.length;r++)i+=t.charCodeAt(r);return i%o<n},isBrowserSupported:function(){return e._.isFunction(document.querySelectorAll)}};exports.autocapture=o,e._.bind_instance_methods(o),e._.safewrap_instance_methods(o); | ||
},{"./utils":"FOZT","./autocapture-utils":"RYfg"}],"OjnC":[function(require,module,exports) { | ||
@@ -11,0 +11,0 @@ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LinkCapture=exports.FormCapture=void 0;var e=require("./utils"),t=function(){};t.prototype.create_properties=function(){},t.prototype.event_handler=function(){},t.prototype.after_capture_handler=function(){},t.prototype.init=function(e){return this.mp=e,this},t.prototype.capture=function(t,r,n,o){var i=this,p=e._.dom_query(t);if(0!==p.length)return e._.each(p,function(t){e._.register_event(t,this.override_event,function(e){var t={},p=i.create_properties(n,this),a=i.mp.get_config("capture_links_timeout");i.event_handler(e,this,t),window.setTimeout(i.capture_callback(o,p,t,!0),a),i.mp.capture(r,p,i.capture_callback(o,p,t))})},this),!0;e.console.error("The DOM query ("+t+") returned 0 elements")},t.prototype.capture_callback=function(e,t,r,n){n=n||!1;var o=this;return function(){r.callback_fired||(r.callback_fired=!0,e&&!1===e(n,t)||o.after_capture_handler(t,r,n))}},t.prototype.create_properties=function(t,r){return"function"==typeof t?t(r):e._.extend({},t)};var r=function(){this.override_event="click"};exports.LinkCapture=r,e._.inherit(r,t),r.prototype.create_properties=function(e,t){var n=r.superclass.create_properties.apply(this,arguments);return t.href&&(n.url=t.href),n},r.prototype.event_handler=function(e,t,r){r.new_tab=2===e.which||e.metaKey||e.ctrlKey||"_blank"===t.target,r.href=t.href,r.new_tab||e.preventDefault()},r.prototype.after_capture_handler=function(e,t){t.new_tab||setTimeout(function(){window.location=t.href},0)};var n=function(){this.override_event="submit"};exports.FormCapture=n,e._.inherit(n,t),n.prototype.event_handler=function(e,t,r){r.element=t,e.preventDefault()},n.prototype.after_capture_handler=function(e,t){setTimeout(function(){t.element.submit()},0)}; |
{ | ||
"name": "posthog-js", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "Posthog-js allows you to automatically capture usage and send events to PostHog.", | ||
@@ -17,3 +17,3 @@ "repository": "https://github.com/PostHog/posthog-js", | ||
"prepublish": "yarn test && yarn build && yarn build-module && yarn process-types", | ||
"test": "npm run unit-test", | ||
"test": "jest", | ||
"unit-test": "BABEL_ENV=test mocha --require babel-core/register tests/unit/*.js" | ||
@@ -27,23 +27,21 @@ }, | ||
"devDependencies": { | ||
"@babel/core": "^7.0.0", | ||
"@babel/preset-env": "^7.0.0", | ||
"@rollup/plugin-node-resolve": "^8.1.0", | ||
"@typescript-eslint/eslint-plugin": "^3.5.0", | ||
"@typescript-eslint/parser": "^3.5.0", | ||
"babel": "6.5.2", | ||
"babel-core": "6.7.2", | ||
"babel-eslint": "^10.1.0", | ||
"babel-preset-es2015": "6.6.0", | ||
"chai": "3.5.0", | ||
"babel-jest": "^26.1.0", | ||
"eslint": "^7.3.1", | ||
"eslint-plugin-prettier": "^3.1.4", | ||
"husky": "^4.2.5", | ||
"jsdom": "11.12.0", | ||
"jest": "^26.1.0", | ||
"jsdom": "16.2.2", | ||
"jsdom-global": "3.0.2", | ||
"lint-staged": "^10.2.11", | ||
"localStorage": "1.0.4", | ||
"mocha": "7.1.1", | ||
"parcel": "^1.12.4", | ||
"prettier": "^2.0.5", | ||
"rollup": "^1.32.0", | ||
"rollup-plugin-npm": "1.4.0", | ||
"sinon": "8.1.1", | ||
"sinon-chai": "3.5.0", | ||
"rollup": "^2.18.2", | ||
"sinon": "9.0.2", | ||
"typescript": "^3.9.6" | ||
@@ -50,0 +48,0 @@ }, |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20
280906
5406