!function(e){"use strict";const n={TRACKING_ACCEPTED:"trackingConsentAccepted",TRACKING_DECLINED:"trackingConsentDeclined",MARKETING_ACCEPTED:"firstPartyMarketingConsentAccepted",SALE_OF_DATA_ACCEPTED:"thirdPartyMarketingConsentAccepted",ANALYTICS_ACCEPTED:"analyticsConsentAccepted",PREFERENCES_ACCEPTED:"preferencesConsentAccepted",MARKETING_DECLINED:"firstPartyMarketingConsentDeclined",SALE_OF_DATA_DECLINED:"thirdPartyMarketingConsentDeclined",ANALYTICS_DECLINED:"analyticsConsentDeclined",PREFERENCES_DECLINED:"preferencesConsentDeclined",CONSENT_COLLECTED:"visitorConsentCollected",CONSENT_TRACKING_API_LOADED:"consentTrackingApiLoaded"},t="2.1",o="3",r={ACCEPTED:"yes",DECLINED:"no",NO_INTERACTION:"no_interaction",NO_VALUE:""},i={NO_VALUE:"",ACCEPTED:"1",DECLINED:"0"},c={PREFERENCES:"p",ANALYTICS:"a",MARKETING:"m",SALE_OF_DATA:"t"},a={MARKETING:"m",ANALYTICS:"a",PREFERENCES:"p",SALE_OF_DATA:"s"},s={MARKETING:"marketing",ANALYTICS:"analytics",PREFERENCES:"preferences",SALE_OF_DATA:"sale_of_data",EMAIL:"email"},u={HEADLESS_STOREFRONT:"headlessStorefront",ROOT_DOMAIN:"rootDomain",CHECKOUT_ROOT_DOMAIN:"checkoutRootDomain",STOREFRONT_ROOT_DOMAIN:"storefrontRootDomain",STOREFRONT_ACCESS_TOKEN:"storefrontAccessToken",IS_EXTENSION_TOKEN:"isExtensionToken",METAFIELDS:"metafields"};function l(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);n&&(o=o.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),t.push.apply(t,o)}return t}function E(e){for(var n=1;n{f()||console.warn(e)},A.error=e=>{f()||console.error(e)},A.info=e=>{f()||console.info(e)},A.debug=e=>{f()||console.debug(e)},A.trace=e=>{f()||console.trace(e)};const C=A;function p(e){let n=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const t=document.cookie?document.cookie.split("; "):[];for(let n=0;n0&&void 0!==arguments[0]?arguments[0]:"/";const n=new XMLHttpRequest;n.open("HEAD",e,!1),n.withCredentials=!0,n.send()}(),window.localStorage.setItem("tracking_consent_fetched","true"),p(e,!1)}}function T(e){return e===encodeURIComponent(decodeURIComponent(e))}function g(e,n,t,o){if(!T(o))throw new TypeError("Cookie value is not correctly URI encoded.");if(!T(e))throw new TypeError("Cookie name is not correctly URI encoded.");let r="".concat(e,"=").concat(o);r+="; path=/",n&&(r+="; domain=".concat(n)),r+="; expires=".concat(new Date((new Date).getTime()+t).toUTCString()),document.cookie=r}const _="_tracking_consent",N=31536e6;function h(){const e=p(_);if(void 0!==e)return function(e){const n=e.slice(0,1);if("{"==n)return function(e){var n;let o;try{o=JSON.parse(e)}catch(e){return}if(o.v!==t)return;if(null===(n=o.con)||void 0===n||!n.CMP)return;return o}(e);if("3"==n)return function(e){const n=e.slice(1).split("_"),[t,r,s,u,l]=n;let E,d;try{E=n[5]?JSON.parse(n.slice(5).join("_")):void 0}catch(e){}if(l){const e=Array.from(atob(l)).map((e=>e.charCodeAt(0).toString(16).padStart(2,"0"))).join("");d=[8,13,18,23].reduce(((e,n)=>e.slice(0,n)+"-"+e.slice(n)),e)}function f(e){const n=t.split(".")[0];return n.includes(e.toLowerCase())?i.DECLINED:n.includes(e.toUpperCase())?i.ACCEPTED:i.NO_VALUE}function A(e){return t.includes(e.replace("t","s").toUpperCase())}return{v:o,con:{CMP:{[a.ANALYTICS]:f(a.ANALYTICS),[a.PREFERENCES]:f(a.PREFERENCES),[a.MARKETING]:f(a.MARKETING),[a.SALE_OF_DATA]:f(a.SALE_OF_DATA)}},region:r||"",cus:E,purposes:{[c.ANALYTICS]:A(c.ANALYTICS),[c.PREFERENCES]:A(c.PREFERENCES),[c.MARKETING]:A(c.MARKETING),[c.SALE_OF_DATA]:A(c.SALE_OF_DATA)},sale_of_data_region:"t"==u,display_banner:"t"==s,consent_id:d}}(e);return}(e)}function S(){try{let e=h();if(!e)return;return e}catch(e){return}}function m(){return{m:R(a.MARKETING),a:R(a.ANALYTICS),p:R(a.PREFERENCES),s:R(a.SALE_OF_DATA)}}function y(){return m()[a.SALE_OF_DATA]}function D(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;return null===e&&(e=S()),void 0===e}function I(e){switch(e){case i.ACCEPTED:return r.ACCEPTED;case i.DECLINED:return r.DECLINED;default:return r.NO_VALUE}}function w(e){switch(e){case a.ANALYTICS:return s.ANALYTICS;case a.MARKETING:return s.MARKETING;case a.PREFERENCES:return s.PREFERENCES;case a.SALE_OF_DATA:return s.SALE_OF_DATA}}function R(e){const n=S();if(!n)return i.NO_VALUE;const t=n.con.CMP;return t?t[e]:i.NO_VALUE}function O(){const e=S();return D(e)?"":e.region||""}function P(e){const n=h();if(!n||!n.purposes)return!0;const t=n.purposes[e];return"boolean"!=typeof t||t}function L(){return P(c.PREFERENCES)}function v(){return P(c.ANALYTICS)}function k(){return P(c.MARKETING)}function b(){return P(c.SALE_OF_DATA)}function M(){const e=h();return!!e&&("boolean"==typeof e.display_banner&&e.display_banner)}function F(){const e=h();return e&&e.sale_of_data_region||!1}class K{constructor(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if(this.useInstrumentation=void 0,K.instance)return K.instance;K.instance=this,this.useInstrumentation=e}instrumentationEnabled(){return this.useInstrumentation}setUseInstrumentation(e){this.useInstrumentation=e}produce(e,n){if(this.instrumentationEnabled()&&v())try{const t={schema_id:"customer_privacy_api_events/2.0",payload:{shop_domain:window.location.host,method_name:e,call_details:n||null}},o={accept:"*/*","accept-language":"en-GB,en-US;q=0.9,en;q=0.8","content-type":"application/json; charset=utf-8","x-monorail-edge-event-created-at-ms":String(Date.now()),"x-monorail-edge-event-sent-at-ms":String(Date.now())};if(!window.location.host.endsWith("spin.dev"))return fetch("https://monorail-edge.shopifysvc.com/v1/produce",{headers:o,body:JSON.stringify(t),method:"POST",mode:"cors",credentials:"omit"});console.log("Monorail event from consent API:",o,t)}catch(e){}}}function G(e){void 0!==e.granular_consent&&function(e){const t=e[c.MARKETING],o=e[c.SALE_OF_DATA],r=e[c.ANALYTICS],i=e[c.PREFERENCES];!0===t?j(n.MARKETING_ACCEPTED):!1===t&&j(n.MARKETING_DECLINED);!0===o?j(n.SALE_OF_DATA_ACCEPTED):!1===o&&j(n.SALE_OF_DATA_DECLINED);!0===r?j(n.ANALYTICS_ACCEPTED):!1===r&&j(n.ANALYTICS_DECLINED);!0===i?j(n.PREFERENCES_ACCEPTED):!1===i&&j(n.PREFERENCES_DECLINED);const a=function(e){const n={marketingAllowed:e[c.MARKETING],saleOfDataAllowed:e[c.SALE_OF_DATA],analyticsAllowed:e[c.ANALYTICS],preferencesAllowed:e[c.PREFERENCES],firstPartyMarketingAllowed:e[c.MARKETING],thirdPartyMarketingAllowed:e[c.SALE_OF_DATA]};return n}(e);j(n.CONSENT_COLLECTED,a);const s=[r,i,t,o];s.every((e=>!0===e))&&j(n.TRACKING_ACCEPTED);s.every((e=>!1===e))&&j(n.TRACKING_DECLINED)}({[c.PREFERENCES]:L(),[c.ANALYTICS]:v(),[c.MARKETING]:k(),[c.SALE_OF_DATA]:b()})}function j(e,n){document.dispatchEvent(new CustomEvent(e,{detail:n||{}}))}function U(e,n){if(null===e)return"null";if(Array.isArray(e)){const n=e.map((e=>U(e,!0))).join(",");return"[".concat(n,"]")}if("object"==typeof e){let t=[];for(const n in e)e.hasOwnProperty(n)&&void 0!==e[n]&&t.push("".concat(n,":").concat(U(e[n],!0)));const o=t.join(",");return n?"{".concat(o,"}"):o}return"string"==typeof e?'"'.concat(e,'"'):"".concat(e)}K.instance=void 0;const Y="_landing_page",B="_orig_referrer";function x(e){const n=e.granular_consent,t=U(E(E({visitorConsent:E({marketing:n.marketing,analytics:n.analytics,preferences:n.preferences,saleOfData:n.sale_of_data},n.metafields&&{metafields:n.metafields})},n.email&&{visitorEmail:n.email}),{},{origReferrer:e.referrer,landingPage:e.landing_page}));return{query:"query { consentManagement { cookies(".concat(t,") { trackingConsentCookie cookieDomain landingPageCookie origReferrerCookie } } }"),variables:{}}}function V(e,n){const t=e.granular_consent,o=t.storefrontAccessToken||function(){const e=document.documentElement.querySelector("#shopify-features"),n="Could not find liquid access token";if(!e)return void C.warn(n);const t=JSON.parse(e.textContent||"").accessToken;if(!t)return void C.warn(n);return t}(),r=t.checkoutRootDomain||window.location.host,i=t.isExtensionToken?"Shopify-Storefront-Extension-Token":"x-shopify-storefront-access-token",c={headers:{"content-type":"application/json",[i]:o},body:JSON.stringify(x(e)),method:"POST"};return fetch("https://".concat(r,"/api/unstable/graphql.json"),c).then((e=>{if(e.ok)return e.json();throw new Error("Server error")})).then((o=>{const r=31536e6,i=12096e5,c=o.data.consentManagement.cookies.cookieDomain,a=c||t.checkoutRootDomain||window.location.hostname,s=t.storefrontRootDomain||c||window.location.hostname,u=o.data.consentManagement.cookies.trackingConsentCookie,l=o.data.consentManagement.cookies.landingPageCookie,E=o.data.consentManagement.cookies.origReferrerCookie;return g(_,a,r,u),l&&E&&(g(Y,a,i,l),g(B,a,i,E)),s!==a&&(g(_,s,r,u),l&&E&&(g(Y,s,i,l),g(B,s,i,E))),G(e),void 0!==n&&n(null,o),o})).catch((e=>{const t="Error while setting storefront API consent: "+e.message;if(void 0===n)throw{error:t};n({error:t})}))}function H(e,n){if(function(e){if("boolean"!=typeof e&&"object"!=typeof e)throw TypeError("setTrackingConsent must be called with a boolean or object consent value");if("object"==typeof e){const n=Object.keys(e);if(0===n.length)throw TypeError("The submitted consent object is empty.");const t=[s.MARKETING,s.ANALYTICS,s.PREFERENCES,s.SALE_OF_DATA,s.EMAIL,u.ROOT_DOMAIN,u.CHECKOUT_ROOT_DOMAIN,u.STOREFRONT_ROOT_DOMAIN,u.STOREFRONT_ACCESS_TOKEN,u.HEADLESS_STOREFRONT,u.IS_EXTENSION_TOKEN,u.METAFIELDS];for(const e of n)if(!t.includes(e))throw TypeError("The submitted consent object should only contain the following keys: ".concat(t.join(", "),". Extraneous key: ").concat(e,"."))}}(e),void 0!==n&&"function"!=typeof n)throw TypeError("setTrackingConsent must be called with a callback function if the callback argument is provided");let t;if(!0===e||!1===e){C.warn("Binary consent is deprecated. Please update to granular consent (shopify.dev/docs/api/consent-tracking)");t={analytics:e,preferences:e,marketing:e}}else t=e;const o=function(e){if(!e)return null;return Z()?document.referrer:""}(t.analytics),r=function(e){if(!e)return null;return Z()?window.location.pathname+window.location.search:"/"}(t.analytics);return V(E(E({granular_consent:t},null!==o&&{referrer:o}),null!==r&&{landing_page:r}),n)}function q(e,n){if(C.warn("This method is deprecated. Please read shopify.dev/docs/api/customer-privacy for the latest information."),"boolean"!=typeof e)throw TypeError("setCCPAConsent must be called with a boolean consent value");if("function"!=typeof n)throw TypeError("setCCPAConsent must be called with a callback function");return V({granular_consent:{sale_of_data:e}},n)}function J(){if((new K).produce("getTrackingConsent"),D())return r.NO_VALUE;const e=m();return e[a.MARKETING]===i.ACCEPTED&&e[a.ANALYTICS]===i.ACCEPTED?r.ACCEPTED:e[a.MARKETING]===i.DECLINED||e[a.ANALYTICS]===i.DECLINED?r.DECLINED:r.NO_INTERACTION}function X(){(new K).produce("getRegulation"),C.warn("getRegulation is deprecated and will be removed.");const e=O();return""===e?"":["AT","BE","BG","HR","CY","CZ","DK","EE","FI","FR","DE","GR","HU","IS","IE","IT","LV","LI","LT","LU","MT","NL","NO","PL","PT","RO","SI","SK","ES","SE","GB"].includes(e.slice(0,2))?"GDPR":"US"===e.slice(0,2)&&["CA","VA"].includes(e.slice(2,4))?"CCPA":""}function $(){return(new K).produce("getShopPrefs"),C.warn("getShopPrefs is deprecated and will be removed."),{limit:[]}}function W(){return O()}function Z(){if(""===document.referrer)return!0;const e=document.createElement("a");return e.href=document.referrer,window.location.hostname!=e.hostname}function z(){return(new K).produce("isRegulationEnforced"),C.warn("isRegulationEnforced is deprecated and will be removed."),!0}function Q(){return!!D()||k()&&v()}function ee(){return F()?"string"==typeof navigator.globalPrivacyControl?"1"!==navigator.globalPrivacyControl:"boolean"==typeof navigator.globalPrivacyControl?!navigator.globalPrivacyControl:null:null}function ne(){return C.warn("userDataCanBeSold is deprecated and will be replaced with saleOfDataAllowed."),b()}function te(){return M()&&J()===r.NO_INTERACTION}function oe(){return!1===ee()?r.DECLINED:(e=y(),D()?r.NO_VALUE:e===i.NO_VALUE?r.NO_INTERACTION:I(e));var e}function re(){return(new K).produce("shouldShowCCPABanner"),C.warn("shouldShowCCPABanner is deprecated and will be removed."),F()&&oe()===r.NO_INTERACTION}function ie(){return!0}function ce(e){return function(e){const n=S();if(D(n)||!n.cus)return;const t=n.cus[encodeURIComponent(e)];return t?decodeURIComponent(t):t}(e)}const ae="95ba910bcec4542ef2a0b64cd7ca666c";function se(e,n,t){try{var o;!function(e){const n=new XMLHttpRequest;n.open("POST","https://notify.bugsnag.com/",!0),n.setRequestHeader("Content-Type","application/json"),n.setRequestHeader("Bugsnag-Api-Key",ae),n.setRequestHeader("Bugsnag-Payload-Version","5");const t=function(e){const n=function(e){return e.stackTrace||e.stack||e.description||e.name}(e.error),[t,o]=(n||"unknown error").split("\n")[0].split(":");return JSON.stringify({payloadVersion:5,notifier:{name:"ConsentTrackingAPI",version:"latest",url:"-"},events:[{exceptions:[{errorClass:(t||"").trim(),message:(o||"").trim(),stacktrace:[{file:"consent-tracking-api.js",lineNumber:"1",method:n}],type:"browserjs"}],context:e.context||"general",app:{id:"ConsentTrackingAPI",version:"latest"},metaData:{request:{shopId:e.shopId,shopUrl:window.location.href},device:{userAgent:window.navigator.userAgent},"Additional Notes":e.notes},unhandled:!1}]})}(e);n.send(t)}({error:e,context:n,shopId:le()||(null===(o=window.Shopify)||void 0===o?void 0:o.shop),notes:t})}catch(e){}}function ue(e){return function(){try{return e(...arguments)}catch(e){throw e instanceof TypeError||se(e),e}}}function le(){try{const e=document.getElementById("shopify-features").textContent;return JSON.parse(e).shopId}catch(e){return null}}function Ee(){return k()}function de(){return b()}function fe(){const e={},n=m();for(const t of Object.keys(n))e[w(t)]=I(n[t]);return e}function Ae(e,n){const o=new K;return o.produce("setTrackingConsent"),"object"==typeof e&&e.headlessStorefront&&!e.storefrontAccessToken?(C.warn("Headless consent has been updated. Please read shopify.dev/docs/api/customer-privacy to integrate."),o.produce("setTrackingConsent-Headless"),function(e,n){function o(e){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:i.NO_VALUE;return!0===e?i.ACCEPTED:!1===e?i.DECLINED:n}const r={[a.ANALYTICS]:o(e[s.ANALYTICS],i.DECLINED),[a.MARKETING]:o(e[s.MARKETING],i.DECLINED),[a.PREFERENCES]:o(e[s.PREFERENCES],i.DECLINED),[a.SALE_OF_DATA]:o(e[s.SALE_OF_DATA])},c={v:t,reg:"",con:{CMP:r}},u=encodeURIComponent(JSON.stringify(c));return g(_,e.rootDomain,N,u),n(null),new Promise(((e,n)=>{}))}(e,n||(()=>{}))):H(e,n)}const Ce=e=>{let{useBugsnagReporting:n,useInstrumentation:t}=e;y()!=i.DECLINED&&!1===ee()&&q(!1,(()=>!1));const o={getTrackingConsent:J,setTrackingConsent:Ae,userCanBeTracked:Q,getRegulation:X,isRegulationEnforced:z,getShopPrefs:$,shouldShowGDPRBanner:te,userDataCanBeSold:ne,setCCPAConsent:q,getCCPAConsent:oe,shouldShowCCPABanner:re,doesMerchantSupportGranularConsent:ie,analyticsProcessingAllowed:v,preferencesProcessingAllowed:L,marketingAllowed:Ee,firstPartyMarketingAllowed:Ee,saleOfDataAllowed:de,thirdPartyMarketingAllowed:de,currentVisitorConsent:fe,shouldShowBanner:M,saleOfDataRegion:F,getRegion:W,getTrackingConsentMetafield:ce,unstable:{analyticsProcessingAllowed:v,preferencesProcessingAllowed:L,marketingAllowed:Ee,saleOfDataAllowed:de,currentVisitorConsent:fe,shouldShowBanner:M,saleOfDataRegion:F},__metadata__:{name:"@shopify/consent-tracking-api",version:"v0.1",description:"Shopify Consent Tracking API"}};if(new K(t),!n)return o;const r=["unstable","__metadata__"];for(const e in o)o.hasOwnProperty(e)&&(o[e]=r.includes(e)?o[e]:ue(o[e]));return o};function pe(){return Ce(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{useBugsnagReporting:!1,useInstrumentation:!1})}function Te(){var e,t;const o=pe({useBugsnagReporting:!0,useInstrumentation:!0});if(window.Shopify.trackingConsent||window.Shopify.customerPrivacy){const n=null===(e=window.Shopify.customerPrivacy.__metadata__)||void 0===e?void 0:e.version,r=null===(t=o.__metadata__)||void 0===t?void 0:t.version,i=`Multiple versions of Shopify.trackingConsent or Shopify.customerPrivacy loaded - Version '${n}' is already loaded but replacing with version '${r}'.\n\nThis could result in unexpected behavior. See documentation https://shopify.dev/docs/api/customer-privacy for more information.`,c="Shopify.trackingConsent or Shopify.customerPrivacy already exists.\n\nLoading multiple versions could result in unexpected behavior. See documentation https://shopify.dev/docs/api/customer-privacy for more information.";try{console.warn(n&&r?i:c)}catch(e){if(!(e instanceof ReferenceError))throw e}}window.Shopify.customerPrivacy=window.Shopify.trackingConsent=o,j(n.CONSENT_TRACKING_API_LOADED)}window.Shopify=window.Shopify?window.Shopify:{},Te(),e.default=pe,e.setGlobalObject=Te,Object.defineProperty(e,"__esModule",{value:!0})}({}); //# sourceMappingURL=consent-tracking-api.js.map