UNPKG

overcentric

Version:

Overcentric watches your website, product, and users - and tells you what matters and what to do about it.

1 lines 2.57 kB
"use strict";(this.webpackChunkovercentric=this.webpackChunkovercentric||[]).push([[775],{775:(t,e,i)=>{function n(t,e){const i=t.target;if(!i)return;const n=function(t){const e={tag:t.tagName.toLowerCase()};t.id&&(e.id=t.id),t instanceof HTMLAnchorElement&&t.href&&(e.href=t.href);const i=t.getAttribute("role");return i&&(e.role=i),e}(i),o={element:{tag:n.tag,text:"BUTTON"===i.tagName||"A"===i.tagName?i.innerText||"":void 0}};n.id&&(o.element.id=n.id),i.hasAttribute("data-oc-value")&&(o.custom_value=i.getAttribute("data-oc-value")||""),t instanceof MouseEvent&&(o.x=t.clientX,o.y=t.clientY),e("$click",o)}function o(t){const e={},i=new URLSearchParams(window.location.search);[["title",document.title],["path",window.location.pathname],["utm_source",i.get("utm_source")],["utm_medium",i.get("utm_medium")],["utm_campaign",i.get("utm_campaign")],["utm_term",i.get("utm_term")],["utm_content",i.get("utm_content")]].forEach((([t,i])=>{t&&i&&(e[t]=i)})),t("$page_view",e)}function c(t,e){if(o(t),e.captureClick&&document.addEventListener("click",(e=>n(e,t)),!0),e.captureFormSubmit&&document.addEventListener("submit",(e=>function(t,e){const i=t.target;if(!i)return;e("$form_submit",{id:i.id,action:i.action,method:i.method,fields:Array.from(i.elements).length})}(e,t)),!0),e.captureInputFocus&&document.addEventListener("focus",(e=>function(t,e){const i=t.target;if(!i)return;e("$input_focus",{type:i.type,id:i.id,name:i.name})}(e,t)),!0),e.captureScroll){const e=function(t){let e,i=window.scrollY;return()=>{clearTimeout(e),e=setTimeout((()=>{const e=window.scrollY,n=window.innerHeight,o=document.documentElement.scrollHeight,c=e/(o-n)*100;Math.abs(e-i)>.25*n&&(t("$scroll",{scroll_percentage:Math.round(c),scroll_position:e,viewport_height:n,document_height:o}),i=e)}),500)}}(t);document.addEventListener("scroll",e,{passive:!0})}if(e.captureVisibilityChange&&document.addEventListener("visibilitychange",(()=>{"visible"===document.visibilityState?t("$page_visible",{title:document.title,url:window.location.href}):t("$page_hidden",{title:document.title,url:window.location.href})})),e.captureHistoryChange){window.addEventListener("popstate",(()=>o(t)));const e=window.history.pushState,i=window.history.replaceState;window.history.pushState=function(...i){e.apply(this,i),o(t)},window.history.replaceState=function(...e){var n,c,r;(null===(c=null===(n=e[0])||void 0===n?void 0:n.id)||void 0===c?void 0:c.startsWith("phx-"))||(null===(r=e[0])||void 0===r?void 0:r.hasOwnProperty("scroll"))||(i.apply(this,e),o(t))}}}i.r(e),i.d(e,{startAutoCapture:()=>c})}}]);