1// @datapunt/[email protected] downloaded from https://ga.jspm.io/npm:@datapunt/[email protected]/es/index.js 2 3const t={TRACK_EVENT:"trackEvent",TRACK_LINK:"trackLink",TRACK_SEARCH:"trackSiteSearch",TRACK_VIEW:"trackPageView",TRACK_ECOMMERCE_ORDER:"trackEcommerceOrder",TRACK_ECOMMERCE_CART_UPDATE:"trackEcommerceCartUpdate"};var e=(void 0,function(t,e){var r={};for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&e.indexOf(o)<0&&(r[o]=t[o]);if(null!=t&&"function"===typeof Object.getOwnPropertySymbols){var a=0;for(o=Object.getOwnPropertySymbols(t);a<o.length;a++)e.indexOf(o[a])<0&&Object.prototype.propertyIsEnumerable.call(t,o[a])&&(r[o[a]]=t[o[a]])}return r});class MatomoTracker{constructor(t){if(!t.urlBase)throw new Error("Matomo urlBase is required.");if(!t.siteId)throw new Error("Matomo siteId is required.");this.initialize(t)}initialize({urlBase:t,siteId:e,userId:r,trackerUrl:o,srcUrl:a,disabled:n,heartBeat:i,linkTracking:s=true,configurations:c={}}){var u;const m="/"!==t[t.length-1]?`${t}/`:t;if("undefined"===typeof window)return;window._paq=window._paq||[];if(0!==window._paq.length)return;if(n)return;this.pushInstruction("setTrackerUrl",null!==o&&void 0!==o?o:`${m}matomo.php`);this.pushInstruction("setSiteId",e);r&&this.pushInstruction("setUserId",r);Object.entries(c).forEach((([t,e])=>{e instanceof Array?this.pushInstruction(t,...e):this.pushInstruction(t,e)}));(!i||i&&i.active)&&this.enableHeartBeatTimer(null!==(u=i&&i.seconds)&&void 0!==u?u:15);this.enableLinkTracking(s);const d=document;const h=d.createElement("script");const l=d.getElementsByTagName("script")[0];h.type="text/javascript";h.async=true;h.defer=true;h.src=a||`${m}matomo.js`;l&&l.parentNode&&l.parentNode.insertBefore(h,l)}enableHeartBeatTimer(t){this.pushInstruction("enableHeartBeatTimer",t)}enableLinkTracking(t){this.pushInstruction("enableLinkTracking",t)}trackEventsForElements(t){t.length&&t.forEach((t=>{t.addEventListener("click",(()=>{const{matomoCategory:e,matomoAction:r,matomoName:o,matomoValue:a}=t.dataset;if(!e||!r)throw new Error("Error: data-matomo-category and data-matomo-action are required.");this.trackEvent({category:e,action:r,name:o,value:Number(a)})}))}))}trackEvents(){const t='[data-matomo-event="click"]';let e=false;if(!this.mutationObserver){e=true;this.mutationObserver=new MutationObserver((e=>{e.forEach((e=>{e.addedNodes.forEach((e=>{if(!(e instanceof HTMLElement))return;e.matches(t)&&this.trackEventsForElements([e]);const r=Array.from(e.querySelectorAll(t));this.trackEventsForElements(r)}))}))}))}this.mutationObserver.observe(document,{childList:true,subtree:true});if(e){const e=Array.from(document.querySelectorAll(t));this.trackEventsForElements(e)}}stopObserving(){this.mutationObserver&&this.mutationObserver.disconnect()}trackEvent(r){var{category:o,action:a,name:n,value:i}=r,s=e(r,["category","action","name","value"]);if(!o||!a)throw new Error("Error: category and action are required.");this.track(Object.assign({data:[t.TRACK_EVENT,o,a,n,i]},s))}trackSiteSearch(r){var{keyword:o,category:a,count:n}=r,i=e(r,["keyword","category","count"]);if(!o)throw new Error("Error: keyword is required.");this.track(Object.assign({data:[t.TRACK_SEARCH,o,a,n]},i))}trackLink({href:e,linkType:r="link"}){this.pushInstruction(t.TRACK_LINK,e,r)}trackPageView(e){this.track(Object.assign({data:[t.TRACK_VIEW]},e))}addEcommerceItem({sku:t,productName:e,productCategory:r,productPrice:o=0,productQuantity:a=1}){this.pushInstruction("addEcommerceItem",t,e,r,o,a)}removeEcommerceItem({sku:t}){this.pushInstruction("removeEcommerceItem",t)}clearEcommerceCart(){this.pushInstruction("clearEcommerceCart")}trackEcommerceOrder({orderId:e,orderRevenue:r,orderSubTotal:o,taxAmount:a,shippingAmount:n,discountOffered:i=false}){this.track({data:[t.TRACK_ECOMMERCE_ORDER,e,r,o,a,n,i]})}trackEcommerceCartUpdate(e){this.pushInstruction(t.TRACK_ECOMMERCE_CART_UPDATE,e)}setEcommerceView({sku:t,productName:e,productCategory:r,productPrice:o}){this.pushInstruction("setEcommerceView",t,e,r,o)}setEcommerceCategoryView(t){this.setEcommerceView({productCategory:t,productName:false,sku:false})}track({data:t=[],documentTitle:e=window.document.title,href:r,customDimensions:o=false}){if(t.length){o&&Array.isArray(o)&&o.length&&o.map((t=>this.pushInstruction("setCustomDimension",t.id,t.value)));this.pushInstruction("setCustomUrl",null!==r&&void 0!==r?r:window.location.href);this.pushInstruction("setDocumentTitle",e);this.pushInstruction(...t)}} 4/** 5 * Pushes an instruction to Matomo for execution, this is equivalent to pushing entr
5ies into the `_paq` array. 6 * 7 * For example: 8 * 9 * ```ts 10 * pushInstruction('setDocumentTitle', document.title) 11 * ``` 12 * Is the equivalent of: 13 * 14 * ```ts 15 * _paq.push(['setDocumentTitle', document.title]); 16 * ``` 17 * 18 * @param name The name of the instruction to be executed. 19 * @param args The arguments to pass along with the instruction. 20 */pushInstruction(t,...e){"undefined"!==typeof window&&window._paq.push([t,...e]);return this}}var r=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module"});export default MatomoTracker;export{r as types}; 21
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.