File "analytics.min.js"
Full Path: /home/buyiwexj/public_html/wp-content/plugins/wpforms-lite/assets/js/frontend/analytics.min.js
File size: 5.2 KB
MIME-type: text/plain
Charset: utf-8
var WPForms=window.WPForms||{};WPForms.Analytics=WPForms.Analytics||((s,o,i)=>{let n={config:{VISIBILITY_THRESHOLD:0,SESSION_ID_MAX_LENGTH:64,MOBILE_TAB_DEBOUNCE_MS:1e3,TRIGGER_TAB_SWITCH:1,TRIGGER_FORM_SUBMISSION:2,SUBMIT_ANALYTICS_INPUT_NAME:"wpforms[analytics]"},el:{},filters:{},actions:{},states:new Map,bootstrappedForms:new WeakSet,sessionId:"",init(){n.sessionId=n.generateSessionId(),n.el.$doc=i(s),n.attachGlobalTriggers(),n.attachPopupTriggers(),i(()=>n.bootstrapForms()),n.el.$doc.on("wpformsReady",()=>n.bootstrapForms())},sendBeacon(e){var t,s=o.wpforms_settings?.ajaxurl;s&&("undefined"!=typeof navigator&&"function"==typeof navigator.sendBeacon?navigator.sendBeacon(s,e):((t=new XMLHttpRequest).open("POST",s,!0),t.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),t.send(e.toString())))},buildPayload(e){return n.applyFilters("payload",{page:e.currentPage,fields:[],viewDurationMs:0<e.viewStartedAt?Math.max(Date.now()-e.viewStartedAt,0):0},e)},sendTabSwitchSnapshot(e){var t,e="number"==typeof e?n.states.get(e):e;e&&!e.snapshotSent&&e.dirty&&n.applyFilters("shouldSend",!0,e)&&(t=n.buildPayload(e),t=JSON.stringify(t),n.doAction("beforeSnapshotSend",e),t=new URLSearchParams({action:"wpforms_analytics_snapshot",nonce:o.wpforms_settings?.nonce,form_id:String(e.formId),session_id:e.sessionId,trigger:String(n.config.TRIGGER_TAB_SWITCH),form_visible:e.hasBeenVisible?"1":"0",payload:o.wpforms_settings?.analytics_base64?btoa(t):t}),n.sendBeacon(t),e.snapshotSent=!0,e.dirty=!1,n.doAction("afterSnapshotSend",e))},attachGlobalTriggers(){s.addEventListener("visibilitychange",n.onVisibilityChange),o.addEventListener("beforeunload",n.onBeforeUnload)},attachPopupTriggers(){o.addEventListener("elementor/popup/show",n.onPopupShow),o.addEventListener("elementor/popup/hide",n.onPopupHide)},onPopupShow(e){n.bootstrapForms();e=e?.detail?.instance?.$element;e&&e.length&&e.find(".wpforms-form").each(function(){var e=n.states.get(Number.parseInt(i(this).data("formid"),10));e&&!e.hasBeenVisible&&(e.hasBeenVisible=!0,e.dirty=!0,e.viewStartedAt=Date.now(),n.doAction("formVisible",this,e))})},onPopupHide(e){e=e?.detail?.instance?.$element;e&&e.length&&e.find(".wpforms-form").each(function(){var e=Number.parseInt(i(this).data("formid"),10);e&&n.flush(e)})},onVisibilityChange(){var t=n.config.MOBILE_TAB_DEBOUNCE_MS;for(let e of n.states.values())"visible"===s.visibilityState?(clearTimeout(e._tabSwitchTimer),e._tabSwitchTimer=null,e.snapshotSent=!1):e.hasBeenVisible&&(0<t?e._tabSwitchTimer=setTimeout(()=>n.sendTabSwitchSnapshot(e),t):n.sendTabSwitchSnapshot(e))},onBeforeUnload(){for(var e of n.states.values())e.hasBeenVisible&&n.sendTabSwitchSnapshot(e)},addFilter(e,t){n.filters[e]??=[],n.filters[e].push(t)},addAction(e,t){n.actions[e]??=[],n.actions[e].push(t)},applyFilters(e,t,...s){for(var o of n.filters[e]??[])t=o(t,...s);return t},doAction(e,...t){for(var s of n.actions[e]??[])s(...t)},generateSessionId(){var e;return"undefined"!=typeof crypto&&"function"==typeof crypto.randomUUID?crypto.randomUUID():(e=()=>Math.random().toString(16).slice(2),(`${Date.now().toString(16)}-${e()}-`+e()).slice(0,n.config.SESSION_ID_MAX_LENGTH))},createState(e){var t={formId:e,sessionId:n.sessionId,hasBeenVisible:!1,currentPage:1,snapshotSent:!1,dirty:!1,viewStartedAt:0,_tabSwitchTimer:null};return n.applyFilters("stateDefaults",t,e)},getState(e){return n.states.get(e)},registerForm(e){var t,e=Number.parseInt(i(e).data("formid"),10);return e?n.states.has(e)?n.states.get(e):(t=n.createState(e),n.states.set(e,t),t):null},isComputedVisible(e){for(;e&&e!==s.body;){var t=o.getComputedStyle(e);if("none"===t.display||"hidden"===t.visibility||0===Number.parseFloat(t.opacity))return!1;e=e.parentElement}return!0},observeForm(s,o){let i=new IntersectionObserver(e=>{for(var t of e)t.isIntersecting&&n.isComputedVisible(t.target)&&(o.hasBeenVisible=!0,o.dirty=!0,o.viewStartedAt=Date.now(),n.doAction("formVisible",s,o),i.unobserve(t.target))},{threshold:n.config.VISIBILITY_THRESHOLD});i.observe(s)},bootstrapForms(){i(".wpforms-form").each(function(){var e=n.registerForm(this);e&&!n.bootstrappedForms.has(this)&&(n.bootstrappedForms.add(this),n.observeForm(this,e),n.attachSubmitListeners(this,e),n.doAction("init",this,e))})},injectSubmissionEnvelope(e,t){e=i(e),t={session_id:t.sessionId,trigger:n.config.TRIGGER_FORM_SUBMISSION,form_visible:t.hasBeenVisible?1:0,payload:n.buildPayload(t)},t=JSON.stringify(t),t=o.wpforms_settings?.analytics_base64?btoa(t):t;e.find(`input[name="${n.config.SUBMIT_ANALYTICS_INPUT_NAME}"]`).remove(),i('<input type="hidden">').attr("name",n.config.SUBMIT_ANALYTICS_INPUT_NAME).val(t).appendTo(e)},markSubmissionComplete(e){e.snapshotSent=!0,e.dirty=!1},attachSubmitListeners(e,t){i(e).on("wpformsBeforeFormSubmit",()=>{n.injectSubmissionEnvelope(e,t),n.markSubmissionComplete(t)}).on("wpformsAjaxSubmitSuccess",()=>n.markSubmissionComplete(t)).on("wpformsAjaxSubmitFailed wpformsAjaxSubmitError",()=>{t.snapshotSent=!1}).on("submit",()=>n.markSubmissionComplete(t))},flush(e){let t=n.states.get(e);t&&(n.sendTabSwitchSnapshot(t),t.hasBeenVisible=!1,t.dirty=!1,t.snapshotSent=!1,t.viewStartedAt=0,n.doAction("flush",t),i(`.wpforms-form[data-formid="${e}"]`).each(function(){n.observeForm(this,t)}))}};return n})(document,window,jQuery),WPForms.Analytics.init();