import{t as d}from"./google-tag-manager-utils-cbc0cd1f.js";const h={attributeName:"data-search-uuid",init(){const t="search-uuid",e=()=>{try{const n=localStorage.getItem(t);if(!n)return;const r=new Date().getTime(),{uuid:i,timestamp:s}=JSON.parse(n);r-s<1e4&&this.set(i)}catch(n){console.error("Error extracting UUID from storage",n)}finally{localStorage.removeItem(t)}},a=n=>{if(!n.target.closest("[data-uuid-passthrough]"))return;const r=this.get(n.target);if(!r)return;const i={uuid:r,timestamp:new Date().getTime()};localStorage.setItem(t,JSON.stringify(i))},c=n=>{const r=this.get(n.target);r&&this.set(r)};document.addEventListener("click",n=>{c(n),a(n)},!0),e()},set(t,e=null){const a=e||document.querySelector("body");a==null||a.setAttribute(this.attributeName,t)},get(t=null){var a;const e=t||document.querySelector("body");return e?(a=e.closest(`[${this.attributeName}]`))==null?void 0:a.getAttribute(this.attributeName):""},clear(t=null){t&&t.removeAttribute(this.attributeName)}},k={getCSRFToken(){const t=document.querySelector('meta[name="csrf-token"]');return(t==null?void 0:t.getAttribute("content"))||""},getABTestValues(){const t=document.querySelectorAll("drb-ab-test"),e={};return t.forEach(a=>{const c=a.getAttribute("name"),n=a.getAttribute("value");c&&n&&(e[c]=n)}),e},trackAdClicked(t){return this.trackInternally("AdClicked",t)},trackAdRequestFailed(t){return this.trackInternally("AdRequestFailed",t)},trackAdRequested(t){return this.trackInternally("AdRequested",t)},trackAdServed(t){return this.trackInternally("AdServed",t)},trackAdExpanded(t){return this.trackInternally("AdExpanded",t)},trackAdCollapsed(t){return this.trackInternally("AdCollapsed",t)},trackAdDismissed(t){return this.trackInternally("AdDismissed",t)},trackCheckoutViewed(t){return this.trackInternally("CheckoutViewed",t)},trackCTAClicked(t){return this.trackInternally("CTAClicked",t)},trackContactInfoWarningShown(t){return this.trackInternally("ContactInfoWarningShown",t)},trackProjectBriefFlowLanded(t){return this.trackInternally("ProjectBriefFlowLanded",t)},trackProjectBriefFlowStarted(t){return this.trackInternally("ProjectBriefFlowStarted",t)},trackProjectBriefCreated(t){return this.trackInternally("ProjectBriefCreated",t)},trackInternally(t,e={}){return fetch("/client_app/events",{body:JSON.stringify({event:{name:t,payload:{...(()=>{var c,n,r,i,s,o;return{page_url:window.location.href,anonymous_id:((r=(n=(c=window.Dribbble)==null?void 0:c.JsConfig)==null?void 0:n.user)==null?void 0:r.anonymousId)||null,user_id:((o=(s=(i=window.Dribbble)==null?void 0:i.JsConfig)==null?void 0:s.user)==null?void 0:o.id)||null,ab_tests:this.getABTestValues()}})(),...e}}}),headers:{"Content-Type":"application/json","X-CSRF-Token":this.getCSRFToken()},method:"POST"})},bindGlobalListeners(){const t=e=>{var n;const a=(n=e.target)==null?void 0:n.closest("[data-internal-track-cta]");if(!a)return;const c={subject_id:a.getAttribute("data-internal-subject-id")||"",subject_type:a.getAttribute("data-internal-subject-type")||"",name:a.getAttribute("data-internal-track-cta")||a.textContent.trim()};this.trackCTAClicked(c)};document.addEventListener("click",e=>{t(e)})},bindGlobalSearchActivityListeners(){const t=r=>{var u;const i=r.target.closest(".js-contact-overlay-trigger"),s=r.target.closest("[data-message-dialog-button]");if(!(!!i||!!s))return;const l=(u=r.target.closest("[data-message-recipient]"))==null?void 0:u.getAttribute("data-message-recipient");l&&(this.trackSearchMessageCTAClicked(l,r.target),d("MessageCTAClicked",{userID:l}))},e=r=>{var s;const i=(s=r.target.closest("[data-search-profile-clicked]"))==null?void 0:s.getAttribute("data-search-profile-clicked");i&&(this.trackSearchProfileClicked(i,r.target),d("ProfileClicked",{userID:i}))},a=r=>{var s;const i=(s=r.target.closest("[data-search-service-clicked]"))==null?void 0:s.getAttribute("data-search-service-clicked");i&&this.trackSearchServiceClicked(i,r.target)},c=r=>{var o,l;const i=(o=r.target.closest("[data-shot-thumbnail-link]"))==null?void 0:o.getAttribute("data-shot-thumbnail-link");if(!i)return;const s=(l=r.target.closest("[data-boost-data]"))==null?void 0:l.getAttribute("data-boost-data");s?this.trackBoostedShotClicked(s):this.trackSearchShotClicked(i,r.target)};document.addEventListener("click",r=>{t(r),e(r),a(r),c(r)},!0),document.addEventListener("auxclick",r=>{r.button===1&&(e(r),a(r),c(r))},!0);const n=r=>{if(!r||r.length===0)return;const i=Array.from(r).reduce((s,o)=>{const l=document.querySelector(`[data-shot-thumbnail-link="${o}"]`);if(!l)return s;const u=h.get(l);return s[u]||(s[u]=[]),s[u].push(o),s},{});Object.entries(i).forEach(([s,o])=>{this.trackSearchShotsSeen(o,s)})};Dribbble.EventBus.$on("shotViewRecorder:shotsSeen",n),document.addEventListener("shotViewQueue:shotsSeen",r=>{n(r.detail.shotIds)})},trackBoostedShotClicked(t){const e=JSON.parse(t);this.trackAdClicked(e);const a=new URL("/screenshot_boost/click",window.location.origin);a.searchParams.set("id",e.ad_id),a.searchParams.set("request_source",e.placement);try{fetch(a.toString())}catch(c){console.warn("Error logging boost click:",c)}},trackSearchUserMessaged(t,e=null){return this.trackSearchActivity({target:t,target_type:"User",name:"UserMessaged"},e)},trackSearchMessageCTAClicked(t,e=null){return this.trackSearchActivity({target:t,target_type:"User",name:"MessageCTAClicked"},e)},trackSearchMessageModalDisplayed(t,e=null){return this.trackSearchActivity({target:t,target_type:"User",name:"MessageModalDisplayed"},e)},trackSearchShotClicked(t,e=null){return this.trackSearchActivity({target:t,target_type:"Screenshot",name:"ShotClicked"},e)},trackSearchServiceClicked(t,e=null){return this.trackSearchActivity({target:t,target_type:"ServiceOffering",name:"ServiceClicked"},e)},trackSearchShotLiked(t,e=null){return this.trackSearchActivity({target:t,target_type:"Screenshot",name:"ShotLiked"},e)},trackSearchShotSaved(t,e=null){return this.trackSearchActivity({target:t,target_type:"Screenshot",name:"ShotSaved"},e)},trackSearchUserFollowed(t,e=null){return this.trackSearchActivity({target:t,target_type:"User",name:"UserFollowed"},e)},trackSearchShotsSeen(t,e){if(!t||t.length===0)return null;const a=t.map(c=>({uuid:e,target:c,target_type:"Screenshot",name:"ShotSeen"}));return this.trackSearchActivity(a)},trackSearchProfileClicked(t,e=null){return this.trackSearchActivity({target:t,target_type:"User",name:"ProfileClicked"},e)},trackSearchDesignerBookmarked(t,e=null){return this.trackSearchActivity({target:t,target_type:"User",name:"DesignerBookmarked"},e)},trackSearchDesignersSeen(t,e){if(!t.length)return null;const a=t.map(c=>({uuid:e,target:c,target_type:"User",name:"DesignerSeen"}));return this.trackSearchActivity(a)},trackSearchServicesSeen(t,e){if(!t.length)return null;const a=t.map(c=>({uuid:e,target:c,target_type:"ServiceOffering",name:"ServiceSeen"}));return this.trackSearchActivity(a)},trackSearchActivity(t,e=null){if(!t)return;const c=(Array.isArray(t)?t:[t]).reduce((n,r)=>{r.uuid||(r.uuid=h.get(e)),r.ab_tests||(r.ab_tests=this.getABTestValues());const i=["uuid","target","target_type","name","ab_tests"],s=Object.keys(r);return s.length===i.length&&s.every(l=>i.includes(l))&&n.push(r),n},[]);if(c.length!==0)return fetch("/client_app/search_results",{body:JSON.stringify({events:c}),headers:{"Content-Type":"application/json","X-CSRF-Token":this.getCSRFToken()},method:"POST"})}};export{k as I,h as S}; //# sourceMappingURL=internal-tracking-e8368fc2.js.map