import{n as f}from"./@vue-9028cf14.js";var y=/^(GTM|G)-[0-9A-Z]+$/;function h(t){if(typeof t!="string"||!y.test(t)){let e=String(t).toUpperCase().replace(/.*-|[^0-9A-Z]/g,""),n=e.length===0?"":` Did you mean 'GTM-${e}' or 'G-${e}'?`;throw new Error(`'${t}' is not a valid GTM-ID (${y}).${n}`)}}function m(t,e="dataLayer"){return t[e]||(t[e]=[]),t[e]}function l(t,e){let n=document,i=n.createElement("script"),s=c=>{e.onReady?.({id:t,script:i}),i.removeEventListener("load",s)};i.addEventListener("load",s);let d=e.dataLayerName??"dataLayer";if(m(window,d).push({event:"gtm.js","gtm.start":new Date().getTime()}),!t)return i;i.async=!e.defer,i.defer=!!(e.defer||e.compatibility),e.nonce&&i.setAttribute("nonce",e.nonce),e.scriptType&&(i.type=e.scriptType);let a=new URLSearchParams({id:t,...e.dataLayerName?{l:e.dataLayerName}:{},...e.queryParams??{}}),o=e.source??"https://www.googletagmanager.com/gtm.js";i.src=`${o}?${a}`;let p=e.parentElement??n.body;if(typeof p?.appendChild!="function")throw new Error("parentElement must be a DOM element");return p.appendChild(i),i}function w(t="https://www.googletagmanager.com/gtm.js"){return Array.from(document.getElementsByTagName("script")).some(e=>e.src.includes(t))}var b=class{id;options;scriptElements=[];constructor(t){if(Array.isArray(t.id))for(let e of t.id)h(typeof e=="string"?e:e.id);else h(t.id);this.id=t.id,this.options={enabled:!0,debug:!1,loadScript:!0,defer:!1,compatibility:!1,dataLayerName:"dataLayer",...t},delete this.options.id}isInBrowserContext=()=>typeof window<"u";enabled(){return this.options.enabled??!0}enable(t=!0,e){if(this.options.enabled=t,this.isInBrowserContext()&&t&&!w(e)&&this.options.loadScript)if(Array.isArray(this.id))this.id.forEach(n=>{let i;typeof n=="string"?i=l(n,{...this.options}):i=l(n.id,{...this.options,queryParams:n.queryParams}),this.scriptElements.push(i)});else{let n=l(this.id,{...this.options});this.scriptElements.push(n)}}debugEnabled(){return this.options.debug??!1}debug(t){this.options.debug=t}dataLayer(){return this.isInBrowserContext()&&this.options.enabled?m(window,this.options.dataLayerName):!1}trackView(t,e,n={}){let i=this.isInBrowserContext()&&(this.options.enabled??!1);this.options.debug&&console.log(`[GTM-Support${i?"":"(disabled)"}]: Dispatching TrackView`,{screenName:t,path:e}),i&&m(window,this.options.dataLayerName).push({...n,event:this.options.trackViewEventProperty??"content-view","content-name":e,"content-view-name":t})}trackEvent({event:t,category:e=null,action:n=null,label:i=null,value:s=null,noninteraction:d=!1,...a}={}){let o=this.isInBrowserContext()&&(this.options.enabled??!1);this.options.debug&&console.log(`[GTM-Support${o?"":"(disabled)"}]: Dispatching event`,{event:t,category:e,action:n,label:i,value:s,...a}),o&&m(window,this.options.dataLayerName).push({event:t??"interaction",target:e,action:n,"target-properties":i,value:s,"interaction-type":d,...a})}push(t){let e=this.isInBrowserContext()&&(this.options.enabled??!1);this.options.debug&&console.log(`[GTM-Support${e?"":"(disabled)"}]: Dispatching event`,t),e&&m(window,this.options.dataLayerName).push(t)}},r;function v(t,e={id:""}){e={trackOnNextTick:!1,...e},r=new b(e),t.config.globalProperties.$gtm=r,r.isInBrowserContext()&&(e.vueRouter&&E(t,e.vueRouter,e.ignoredViews,e.trackOnNextTick,e.vueRouterAdditionalEventData),r.options.enabled&&r.options.loadScript&&(Array.isArray(e.id)?e.id.forEach(n=>{if(typeof n=="string")l(n,e);else{let i={...e};n.queryParams!=null&&(i.queryParams={...i.queryParams,...n.queryParams}),l(n.id,i)}}):l(e.id,e))),t.provide("gtm",e)}function E(t,e,n=[],i,s=()=>({})){function d(a,o){return a instanceof Error?!!(a.type&o):!1}e.afterEach(async(a,o,p)=>{if(typeof a.name!="string"||Array.isArray(n)&&n.includes(a.name)||typeof n=="function"&&n(a,o))return;let c=a.meta&&typeof a.meta.gtm=="string"&&a.meta.gtm?a.meta.gtm:a.name;d(p,4)?r?.debugEnabled()&&console.log(`[VueGtm]: '${c}' not tracked due to navigation aborted`):d(p,8)&&r?.debugEnabled()&&console.log(`[VueGtm]: '${c}' not tracked due to navigation cancelled`);let g={...await s(a,o),...a.meta?.gtmAdditionalEventData},u=e.options?.history?.base??"";u.endsWith("/")||(u+="/"),u+=a.fullPath.startsWith("/")?a.fullPath.substring(1):a.fullPath,i?f(()=>{r?.trackView(c,u,g)}):r?.trackView(c,u,g)})}function A(t){return{install:e=>v(e,t)}}export{A as V};
