!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={ACCEPTED:"yes",DECLINED:"no",NO_INTERACTION:"no_interaction",NO_VALUE:""},r={NO_VALUE:"",ACCEPTED:"1",DECLINED:"0"},c={PREFERENCES:"p",ANALYTICS:"a",MARKETING:"m",SALE_OF_DATA:"t"},i={MARKETING:"m",ANALYTICS:"a",PREFERENCES:"p",SALE_OF_DATA:"s"},a={MARKETING:"marketing",ANALYTICS:"analytics",PREFERENCES:"preferences",SALE_OF_DATA:"sale_of_data",EMAIL:"email"},s={HEADLESS_STOREFRONT:"headlessStorefront",ROOT_DOMAIN:"rootDomain",CHECKOUT_ROOT_DOMAIN:"checkoutRootDomain",STOREFRONT_ROOT_DOMAIN:"storefrontRootDomain",STOREFRONT_ACCESS_TOKEN:"storefrontAccessToken",IS_EXTENSION_TOKEN:"isExtensionToken",METAFIELDS:"metafields"},u=["v","con"];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;nd(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(d(e[n],!0)));const o=t.join(",");return n?"{".concat(o,"}"):o}return"string"==typeof e?'"'.concat(e,'"'):"".concat(e)}function A(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("cmp_a_fetched","true"),A(e,!1)}function C(e){return A(e)}function T(e){return e===encodeURIComponent(decodeURIComponent(e))}function p(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()),r+="; secure",document.cookie=r}const g="_tracking_consent",N=31536e6;function _(){const e=C(g);if(void 0!==e&&!function(e){if(e.v!==t)return!0;return!function(e,n){const t=n.slice().sort();return e.length===n.length&&e.slice().sort().every(((e,n)=>e===t[n]))}(Object.keys(e).filter((e=>"region"!==e&&"lim"!==e&&"cus"!==e&&"reg"!==e)),u)}(e))return e}function D(){try{let e=_();if(!e)return;return e}catch(e){return}}function O(){return{m:w(i.MARKETING),a:w(i.ANALYTICS),p:w(i.PREFERENCES),s:w(i.SALE_OF_DATA)}}function R(){return O()[i.SALE_OF_DATA]}function S(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;return null===e&&(e=D()),void 0===e}function I(e){switch(e){case r.ACCEPTED:return o.ACCEPTED;case r.DECLINED:return o.DECLINED;default:return o.NO_VALUE}}function h(e){switch(e){case i.ANALYTICS:return a.ANALYTICS;case i.MARKETING:return a.MARKETING;case i.PREFERENCES:return a.PREFERENCES;case i.SALE_OF_DATA:return a.SALE_OF_DATA}}function w(e){const n=D();if(!n)return r.NO_VALUE;const t=n.con.CMP;return t?t[e]:r.NO_VALUE}function y(){const e=D();return S(e)?"":e.region||""}const m="_cmp_a";function P(){return C(m)}function L(e){const n=P();if(!n)return!0;const t=n.purposes[e];return"boolean"!=typeof t||t}function k(){return L(c.PREFERENCES)}function b(){return L(c.ANALYTICS)}function v(){return L(c.MARKETING)}function M(){return L(c.SALE_OF_DATA)}function F(){const e=P();return!!e&&("boolean"==typeof e.display_banner&&e.display_banner)}function K(){const e=P();return e&&e.sale_of_data_region||!1}function j(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?G(n.MARKETING_ACCEPTED):!1===t&&G(n.MARKETING_DECLINED);!0===o?G(n.SALE_OF_DATA_ACCEPTED):!1===o&&G(n.SALE_OF_DATA_DECLINED);!0===r?G(n.ANALYTICS_ACCEPTED):!1===r&&G(n.ANALYTICS_DECLINED);!0===i?G(n.PREFERENCES_ACCEPTED):!1===i&&G(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);G(n.CONSENT_COLLECTED,a);const s=[r,i,t,o];s.every((e=>!0===e))&&G(n.TRACKING_ACCEPTED);s.every((e=>!1===e))&&G(n.TRACKING_DECLINED)}({[c.PREFERENCES]:k(),[c.ANALYTICS]:b(),[c.MARKETING]:v(),[c.SALE_OF_DATA]:M()})}function G(e,n){document.dispatchEvent(new CustomEvent(e,{detail:n||{}}))}const U="_landing_page",Y="_orig_referrer";function B(e){const n=e.granular_consent,t=d({visitorConsent:E({marketing:n.marketing,analytics:n.analytics,preferences:n.preferences,saleOfData:n.sale_of_data},n.metafields&&{metafields:n.metafields}),origReferrer:e.referrer,landingPage:e.landing_page});return{query:"query { consentManagement { cookies(".concat(t,") { answersCookie 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 console.warn(n);const t=JSON.parse(e.textContent||"").accessToken;if(!t)return void console.warn(n);return t}(),r=t.checkoutRootDomain||window.location.host,c=t.isExtensionToken?"Shopify-Storefront-Extension-Token":"x-shopify-storefront-access-token",i={headers:{"content-type":"application/json",[c]:o},body:JSON.stringify(B(e)),method:"POST"};return fetch("https://".concat(r,"/api/unstable/graphql.json"),i).then((e=>{if(e.ok)return e.json();throw new Error("Server error")})).then((o=>{const r=31536e6,c=12096e5,i=o.data.consentManagement.cookies.cookieDomain,a="."+(t.checkoutRootDomain||i||window.location.hostname),s="."+(t.storefrontRootDomain||i||window.location.hostname),u=o.data.consentManagement.cookies.trackingConsentCookie,l=o.data.consentManagement.cookies.answersCookie,E=o.data.consentManagement.cookies.landingPageCookie,f=o.data.consentManagement.cookies.origReferrerCookie;return p(g,a,r,u),p(m,a,r,l),E&&f&&(p(U,a,c,E),p(Y,a,c,f)),s!==a&&(p(g,s,r,u),p(m,s,r,l),E&&f&&(p(U,s,c,E),p(Y,s,c,f))),j(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=[a.MARKETING,a.ANALYTICS,a.PREFERENCES,a.SALE_OF_DATA,a.EMAIL,s.ROOT_DOMAIN,s.CHECKOUT_ROOT_DOMAIN,s.STOREFRONT_ROOT_DOMAIN,s.STOREFRONT_ACCESS_TOKEN,s.HEADLESS_STOREFRONT,s.IS_EXTENSION_TOKEN,s.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){console.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 x(e,n){if(console.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 q(){if(S())return o.NO_VALUE;const e=O();return e[i.MARKETING]===r.ACCEPTED&&e[i.ANALYTICS]===r.ACCEPTED?o.ACCEPTED:e[i.MARKETING]===r.DECLINED||e[i.ANALYTICS]===r.DECLINED?o.DECLINED:o.NO_INTERACTION}function J(){console.warn("getRegulation is deprecated and will be removed.");const e=y();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 X(){return console.warn("getShopPrefs is deprecated and will be removed."),{limit:[]}}function Z(){return y()}function z(){if(""===document.referrer)return!0;const e=document.createElement("a");return e.href=document.referrer,window.location.hostname!=e.hostname}function Q(){return console.warn("isRegulationEnforced is deprecated and will be removed."),!0}function W(){return!!S()||v()&&b()}function $(){return K()?"string"==typeof navigator.globalPrivacyControl?"1"!==navigator.globalPrivacyControl:"boolean"==typeof navigator.globalPrivacyControl?!navigator.globalPrivacyControl:null:null}function ee(){return console.warn("userDataCanBeSold is deprecated and will be replaced with saleOfDataAllowed."),M()}function ne(){return F()&&q()===o.NO_INTERACTION}function te(){return!1===$()?o.DECLINED:(e=R(),S()?o.NO_VALUE:e===r.NO_VALUE?o.NO_INTERACTION:I(e));var e}function oe(){return console.warn("shouldShowCCPABanner is deprecated and will be removed."),K()&&te()===o.NO_INTERACTION}function re(){return!0}function ce(e){return function(e){const n=D();if(S(n)||!n.cus)return;const t=n.cus[encodeURIComponent(e)];return t?decodeURIComponent(t):t}(e)}const ie="95ba910bcec4542ef2a0b64cd7ca666c";function ae(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",ie),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:ue()||(null===(o=window.Shopify)||void 0===o?void 0:o.shop),notes:t})}catch(e){}}function se(e){return function(){try{return e(...arguments)}catch(e){throw ae(e),e}}}function ue(){try{const e=document.getElementById("shopify-features").textContent;return JSON.parse(e).shopId}catch(e){return null}}function le(){return v()}function Ee(){return M()}function fe(){const e={},n=O();for(const t of Object.keys(n))e[h(t)]=I(n[t]);return e}function de(e,n){return"object"==typeof e&&e.headlessStorefront&&!e.storefrontAccessToken?(console.warn("Headless consent has been updated. Please read shopify.dev/docs/api/customer-privacy to integrate."),function(e,n){function o(e){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:r.NO_VALUE;return!0===e?r.ACCEPTED:!1===e?r.DECLINED:n}const c={[i.ANALYTICS]:o(e[a.ANALYTICS],r.DECLINED),[i.MARKETING]:o(e[a.MARKETING],r.DECLINED),[i.PREFERENCES]:o(e[a.PREFERENCES],r.DECLINED),[i.SALE_OF_DATA]:o(e[a.SALE_OF_DATA])},s={v:t,reg:"",con:{CMP:c}},u=encodeURIComponent(JSON.stringify(s));return p(g,e.rootDomain,N,u),n(null),new Promise(((e,n)=>{}))}(e,n||(()=>{}))):H(e,n)}const Ae=e=>{let{useBugsnagReporting:n}=e;R()!=r.DECLINED&&!1===$()&&x(!1,(()=>!1));const t={getTrackingConsent:q,setTrackingConsent:de,userCanBeTracked:W,getRegulation:J,isRegulationEnforced:Q,getShopPrefs:X,shouldShowGDPRBanner:ne,userDataCanBeSold:ee,setCCPAConsent:x,getCCPAConsent:te,shouldShowCCPABanner:oe,doesMerchantSupportGranularConsent:re,analyticsProcessingAllowed:b,preferencesProcessingAllowed:k,marketingAllowed:le,firstPartyMarketingAllowed:le,saleOfDataAllowed:Ee,thirdPartyMarketingAllowed:Ee,currentVisitorConsent:fe,shouldShowBanner:F,saleOfDataRegion:K,getRegion:Z,getTrackingConsentMetafield:ce,unstable:{analyticsProcessingAllowed:b,preferencesProcessingAllowed:k,marketingAllowed:le,saleOfDataAllowed:Ee,currentVisitorConsent:fe,shouldShowBanner:F,saleOfDataRegion:K}};if(!n)return t;const o=["unstable"];for(const e in t)t.hasOwnProperty(e)&&(t[e]=o.includes(e)?t[e]:se(t[e]));return t};function Ce(){return Ae(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{useBugsnagReporting:!1})}function Te(){window.Shopify.customerPrivacy=window.Shopify.trackingConsent=Ce({useBugsnagReporting:!0}),G(n.CONSENT_TRACKING_API_LOADED)}window.Shopify=window.Shopify?window.Shopify:{},Te(),e.default=Ce,e.setGlobalObject=Te,Object.defineProperty(e,"__esModule",{value:!0})}({}); //# sourceMappingURL=consent-tracking-api.js.map