!function(e){"use strict";const t="3",n="1.0.2";var r=e.TRACKING_CONFIG||{},a=r.apiUrl||"https://cartpanda.pinha.ai",o="/track_v2",i=t,c=n,l=r.trustedDomains||[],s=r.batchSize||10,u=r.batchWaitMs||3e4,d=r.heartbeatInterval||18e4,f=r.maxHeartbeatDurationMs||216e5,v=r.pageRefreshTimeoutMs||864e5,m=r.videoProgressInterval||5,h=r.funnel||{},p=null,y=null,g=[],_=null,S=!1,w=null,b=null,k=!1,E=Date.now(),x=0,T=null,A=null,R="undefined"!=typeof WeakMap?new WeakMap:null;function L(t){return new URLSearchParams(e.location.search).get(t)||""}function D(){var t=e.location.hash||"",n=t.indexOf("#tblci");if(-1!==n){var r=t.substring(n+6);if(!r)return"";var a="",o=(a="="===r.charAt(0)||"-"===r.charAt(0)?r.substring(1):a).indexOf("#");return-1!==o?a.substring(0,o):a}return""}function q(){if(y)return y;var t=L("_vid")||L("visitor_id");return t?(y=t,localStorage.setItem("tracking_visitor_id",y),function(){if(e.history&&e.history.replaceState){var t=new URL(e.location.href);t.searchParams.delete("_vid"),t.searchParams.delete("visitor_id"),e.history.replaceState({},"",t.toString())}}(),y):((y=localStorage.getItem("tracking_visitor_id"))||(y="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})),localStorage.setItem("tracking_visitor_id",y)),y)}function M(){if(p)return p;var e=sessionStorage.getItem("tracking_session");if(e)try{var t=JSON.parse(e);if(Date.now()-t.lastActivity<18e5)return p=t.sessionId,t.lastActivity=Date.now(),sessionStorage.setItem("tracking_session",JSON.stringify(t)),p}catch(e){}return p="sess_"+Date.now()+"_"+Math.random().toString(36).substr(2,9),sessionStorage.setItem("tracking_session",JSON.stringify({sessionId:p,startTime:Date.now(),lastActivity:Date.now()})),p}async function O(){if(A)return A;var t={screen:e.screen.width+"x"+e.screen.height+"x"+e.screen.colorDepth,timezone:(new Date).getTimezoneOffset(),locale:navigator.language,platform:navigator.platform,cpuCores:navigator.hardwareConcurrency||0,deviceMemory:navigator.deviceMemory||0,touchSupport:"ontouchstart"in e,canvas:await new Promise((function(e){try{var t=document.createElement("canvas"),n=t.getContext("2d");n.textBaseline="top",n.font="14px Arial",n.fillText("Fingerprint",2,2),e(t.toDataURL().substring(0,50))}catch(t){e(null)}}))},n=JSON.stringify(t),r=await async function(t){if(e.crypto&&e.crypto.subtle)try{var n=(new TextEncoder).encode(t),r=await crypto.subtle.digest("SHA-256",n);return Array.from(new Uint8Array(r)).map((function(e){return e.toString(16).padStart(2,"0")})).join("")}catch(e){}for(var a=0,o=0;o=s?N():_||(_=setTimeout((function(){_=null,N()}),u))),f}function C(e){return l.some((function(t){return e===t||e.endsWith("."+t)}))}var F=null,H=[],J=null;function U(e,t){F=e,H=[],J=Date.now(),P("funnel_started",{funnel_id:e,metadata:t})}function V(e,t){if(F){var n=H.length,r=Date.now()-J;H.push({step_name:e,step_index:n,timestamp:Date.now()}),P("funnel_step",{funnel_id:F,step_name:e,step_index:n,time_in_funnel_ms:r,metadata:t}),P("funnel_"+e,t)}}function j(e){if(F){var t=Date.now()-J,n=H[H.length-1];P("funnel_abandoned",{funnel_id:F,abandon_reason:e||"user_exit",steps_completed:H.length,last_step:n?n.step_name:null,time_before_abandon_ms:t},{immediate:!0}),F=null,H=[],J=null}}function B(e){return!!e&&(R&&"function"==typeof R.has?R.has(e):!!e._trackingState)}function z(t){if(t&&!B(t)&&("VIDEO"===t.tagName||e.HTMLVideoElement&&t instanceof HTMLVideoElement)){var n=!1,r=-1,a=function(){n||(P("video_play",{video_src:t.src||t.currentSrc||"",video_duration:t.duration||0,video_current_time:t.currentTime||0}),n=!0)};t.addEventListener("play",a);var o=function(){if(t.duration&&0!==t.duration&&!isNaN(t.duration)){var e=Math.floor(t.currentTime/t.duration*100),n=Math.floor(e/m)*m;t.currentTime,t.duration,n>r&&n<=100&&(r=n,P("video_progress",{video_src:t.src||t.currentSrc||"",progress_percentage:n,progress_seconds:Math.floor(t.currentTime),video_duration:Math.floor(t.duration),is_playing:!t.paused,is_muted:t.muted,playback_rate:t.playbackRate}))}};t.addEventListener("timeupdate",o);var i=function(){P("video_end",{video_src:t.src||t.currentSrc||"",video_duration:Math.floor(t.duration||0)})};t.addEventListener("ended",i),function(e,t){e&&(R&&"function"==typeof R.set?R.set(e,t):e._trackingState=t)}(t,{playHandler:a,timeupdateHandler:o,endedHandler:i})}}function W(e,t){if(e&&"function"==typeof t&&!B(e))if(e.readyState>=1)t(e);else{var n=!1,r=function(){n||(n=!0,t(e))},a=function(){e.removeEventListener("loadedmetadata",a),e.removeEventListener("canplay",a),e.removeEventListener("canplaythrough",a),r()};e.addEventListener("loadedmetadata",a),e.addEventListener("canplay",a),e.addEventListener("canplaythrough",a);var o=setTimeout((function(){e.removeEventListener("loadedmetadata",a),e.removeEventListener("canplay",a),e.removeEventListener("canplaythrough",a),B(e)||r()}),1e4),i=t;t=function(e){clearTimeout(o),i(e)}}}function G(e){var t=[];if(!e||!e.querySelectorAll)return t;var n=e.querySelectorAll("video");n&&n.length&&Array.prototype.forEach.call(n,(function(e){t.push(e)}));var r=e.querySelectorAll("*");Array.prototype.forEach.call(r,(function(e){if(e&&e.shadowRoot){var n=e.shadowRoot.querySelectorAll?e.shadowRoot.querySelectorAll("video"):[];n&&n.length&&Array.prototype.forEach.call(n,(function(e){t.push(e)}));var r=e.shadowRoot.querySelectorAll?e.shadowRoot.querySelectorAll("*"):[];Array.prototype.forEach.call(r,(function(e){if(e.shadowRoot){var n=e.shadowRoot.querySelectorAll?e.shadowRoot.querySelectorAll("video"):[];Array.prototype.forEach.call(n,(function(e){t.push(e)}))}}))}}));try{var a=e.querySelectorAll("vturb-smartplayer");Array.prototype.forEach.call(a,(function(e){if(e.video)t.push(e.video);else if(e.querySelector&&e.querySelector("video"))t.push(e.querySelector("video"));else if(e.shadowRoot){var n=e.shadowRoot.querySelector("video");n&&t.push(n)}}))}catch(e){console.warn("[Tracking] Error accessing vturb player:",e)}for(var o=[],i=[],c=0;ct.lastProgressMilestone&&c<=100){t.lastProgressMilestone=c;var l=n(r);P("video_progress",{video_src:l.src,progress_percentage:c,progress_seconds:Math.floor(l.currentTime),video_duration:Math.floor(l.duration),is_playing:!l.paused,is_muted:l.muted,playback_rate:l.playbackRate})}}}),!0)})),["player:ended","ended","video:ended","complete"].forEach((function(t){e.addEventListener(t,(function(e){var t=n(e);P("video_end",{video_src:t.src,video_duration:t.duration})}),!0)})),t.eventListenersSetup=!0}}}(e);var t=function(){var t=null;if(e.video&&"VIDEO"===e.video.tagName)t=e.video;else if(e.renderRoot&&e.renderRoot.querySelectorAll)try{var n=e.renderRoot.querySelectorAll("video");n&&n.length&&(t=n[0])}catch(e){}if(!t&&e.shadowRoot&&(t=e.shadowRoot.querySelector?e.shadowRoot.querySelector("video"):null),!t&&e.querySelector&&(t=e.querySelector("video")),!t&&e.player){var r=e.player;if(r.shadowRoot&&r.shadowRoot.querySelector&&(t=r.shadowRoot.querySelector("video")),!t&&r.renderRoot&&r.renderRoot.querySelectorAll)try{var a=r.renderRoot.querySelectorAll("video");a&&a.length&&(t=a[0])}catch(e){}}if(!t)for(var o=[function(){return e.shadowRoot&&e.shadowRoot.querySelector?e.shadowRoot.querySelector("video"):null},function(){if(!e.querySelectorAll)return null;for(var t=e.querySelectorAll("*"),n=0;n=b?k||(k=!0,P("heartbeat_stopped",{reason:"max_duration_reached",time_on_page:t(),total_duration_ms:Date.now()-E,max_duration_ms:f},{immediate:!0})):(void 0!==document.hidden?document.hidden:void 0!==document.visibilityState&&"visible"!==document.visibilityState)||P("heartbeat",{time_on_page:t(),scroll_depth:Math.round((e.scrollY+e.innerHeight)/document.documentElement.scrollHeight*100)})}),d)}async function Z(){q(),M(),await O(),P("page_visit",{page_title:document.title,page_path:e.location.pathname}),document.addEventListener("click",(function(e){var t=e.target.closest('a, button, [role="button"], [data-track]');if(t)if(t.hasAttribute("data-track")){var n=t.getAttribute("data-track"),r={};try{r=JSON.parse(t.getAttribute("data-track-data")||"{}")}catch(e){}P(n,r)}else{var a=t.tagName.toLowerCase(),o="a"===a;P(o?"link_click":"button_click",{element_type:a,element_text:t.textContent.trim().substring(0,100),element_id:t.id||"",element_class:t.className||"",href:o?t.href:""},{immediate:!0})}}),!0),document.addEventListener("click",(function(t){var n=t.target.closest("a");if(n&&n.href)try{var r=new URL(n.href),a=e.location.hostname,o=r.hostname;o!==a&&P("outgoing_link_click",{link_url:n.href,link_domain:o,link_text:n.textContent.trim().substring(0,100),link_id:n.id||"",link_class:n.className||"",is_trusted_domain:C(o)},{immediate:!0})}catch(e){}}),!0),function(){var e=G(document);Array.prototype.forEach.call(e,(function(e){W(e,z)})),K();var t="undefined"!=typeof MutationObserver?new MutationObserver((function(e){e.forEach((function(e){Array.prototype.forEach.call(e.addedNodes,(function(e){if(e&&1===e.nodeType)if("VIDEO"===e.tagName)W(e,z);else if("VTURB-SMARTPLAYER"===e.tagName)setTimeout((function(){K()}),500);else if(e.querySelectorAll){var t=G(e);Array.prototype.forEach.call(t,(function(e){B(e)||W(e,z)}))}}))}))})):null;t&&document.body&&t.observe(document.body,{childList:!0,subtree:!0});var n=setInterval((function(){var e=G(document);Array.prototype.forEach.call(e,(function(e){B(e)||W(e,z)})),K()}),2e3);setTimeout((function(){clearInterval(n)}),6e4)}(),document.addEventListener("click",(function(t){var n=t.target.closest("a");if(n&&n.href)try{var r=new URL(n.href),a=e.location.hostname,o=r.hostname;if(o!==a&&C(o)){var i=q();r.searchParams.set("_vid",i),n.href=r.toString()}}catch(e){}}),!0),e.addEventListener("custom_track",(function(e){console.log("custom_track",e);const t=e&&"object"==typeof e.detail&&null!==e.detail?e.detail:{};P(t.name||"custom_track",{metadata:{...t}},{immediate:!0})})),Y(),setTimeout((function(){var t=Date.now()-E,n=t-x;null!==T&&(n-=Date.now()-T),P("page_auto_refresh",{reason:"max_session_timeout",time_on_page_ms:t,active_time_ms:n,timeout_duration_ms:v,heartbeat_stopped:k},{immediate:!0}),N(),setTimeout((function(){e.location.reload()}),500)}),v),h.enabled&&(U(h.name,{entry_url:e.location.href,referrer:document.referrer}),V(h.steps.LANDED,{landing_page:e.location.pathname})),console.log("[Tracking] Initialized - Visitor:",y,"Session:",p),e.dispatchEvent(new Event("trackingReady"))}e.addEventListener("beforeunload",(function(){if(w&&clearInterval(w),g.length>0){var e=JSON.stringify(g);I(a+o,e)||fetch(a+o,{method:"POST",headers:{"Content-Type":"application/json"},body:e,keepalive:!0}).catch((function(){}))}F&&j("page_unload")})),document.addEventListener("visibilitychange",(function(){document.hidden&&N()})),e.Tracking={track:P,startFunnel:U,trackFunnelStep:V,completeFunnel:function(e){if(F){var t=Date.now()-J;P("funnel_completed",{funnel_id:F,total_steps:H.length,total_time_ms:t,steps:H,metadata:e},{immediate:!0}),F=null,H=[],J=null}},abandonFunnel:j,flush:N,getSessionId:M,getVisitorId:q,decorateURL:function(e){try{var t=new URL(e),n=q();return t.searchParams.set("_vid",n),t.toString()}catch(t){return e}},getFingerprint:function(){return A}},"loading"===document.readyState?document.addEventListener("DOMContentLoaded",Z):Z()}(window);