!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;nA(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(A(e[n],!0)));const o=t.join(",");return n?"{".concat(o,"}"):o}return"string"==typeof e?'"'.concat(e,'"'):"".concat(e)}function d(e){return function(e){const n=document.cookie?document.cookie.split("; "):[];for(let t=0;te===t[n]))}(Object.keys(e).filter((e=>"region"!==e&&"lim"!==e&&"cus"!==e&&"reg"!==e)),u)}(e))return e}function D(){try{let e=g();if(!e)return;return e}catch(e){return}}function _(){return{m:y(i.MARKETING),a:y(i.ANALYTICS),p:y(i.PREFERENCES),s:y(i.SALE_OF_DATA)}}function O(){return _()[i.SALE_OF_DATA]}function R(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;return null===e&&(e=D()),void 0===e}function S(e){switch(e){case r.ACCEPTED:return o.ACCEPTED;case r.DECLINED:return o.DECLINED;default:return o.NO_VALUE}}function I(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 y(e){const n=D();if(!n)return r.NO_VALUE;const t=n.con.CMP;return t?t[e]:r.NO_VALUE}function h(){const e=D();return R(e)?"":e.region||""}const w="_cmp_a";function m(){return d(w)}function P(e){const n=m();if(!n)return!0;const t=n.purposes[e];return"boolean"!=typeof t||t}function L(){return P(c.PREFERENCES)}function k(){return P(c.ANALYTICS)}function b(){return P(c.MARKETING)}function v(){return P(c.SALE_OF_DATA)}function M(){const e=m();return!!e&&("boolean"==typeof e.display_banner&&e.display_banner)}function F(){const e=m();return e&&e.sale_of_data_region||!1}function K(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]:k(),[c.MARKETING]:b(),[c.SALE_OF_DATA]:v()})}function j(e,n){document.dispatchEvent(new CustomEvent(e,{detail:n||{}}))}const G="_landing_page",U="_orig_referrer";function Y(e){const n=e.granular_consent,t=A({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 B(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(Y(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 T(p,a,r,u),T(w,a,r,l),E&&f&&(T(G,a,c,E),T(U,a,c,f)),s!==a&&(T(p,s,r,u),T(w,s,r,l),E&&f&&(T(G,s,c,E),T(U,s,c,f))),K(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 V(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 B(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 B({granular_consent:{sale_of_data:e}},n)}function H(){if(R())return o.NO_VALUE;const e=_();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 q(){console.warn("getRegulation is deprecated and will be removed.");const e=h();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 J(){return console.warn("getShopPrefs is deprecated and will be removed."),{limit:[]}}function X(){return h()}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 console.warn("isRegulationEnforced is deprecated and will be removed."),!0}function Q(){return!!R()||b()&&k()}function W(){return F()?"string"==typeof navigator.globalPrivacyControl?"1"!==navigator.globalPrivacyControl:"boolean"==typeof navigator.globalPrivacyControl?!navigator.globalPrivacyControl:null:null}function $(){return console.warn("userDataCanBeSold is deprecated and will be replaced with saleOfDataAllowed."),v()}function ee(){return M()&&H()===o.NO_INTERACTION}function ne(){return!1===W()?o.DECLINED:(e=O(),R()?o.NO_VALUE:e===r.NO_VALUE?o.NO_INTERACTION:S(e));var e}function te(){return console.warn("shouldShowCCPABanner is deprecated and will be removed."),F()&&ne()===o.NO_INTERACTION}function oe(){return!0}function re(e){return function(e){const n=D();if(R(n)||!n.cus)return;const t=n.cus[encodeURIComponent(e)];return t?decodeURIComponent(t):t}(e)}const ce="95ba910bcec4542ef2a0b64cd7ca666c";function ie(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",ce),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:se()||(null===(o=window.Shopify)||void 0===o?void 0:o.shop),notes:t})}catch(e){}}function ae(e){return function(){try{return e(...arguments)}catch(e){throw ie(e),e}}}function se(){try{const e=document.getElementById("shopify-features").textContent;return JSON.parse(e).shopId}catch(e){return null}}function ue(){return b()}function le(){return v()}function Ee(){const e={},n=_();for(const t of Object.keys(n))e[I(t)]=S(n[t]);return e}function fe(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 T(p,e.rootDomain,N,u),n(null),new Promise(((e,n)=>{}))}(e,n||(()=>{}))):V(e,n)}const Ae=e=>{let{useBugsnagReporting:n}=e;O()!=r.DECLINED&&!1===W()&&x(!1,(()=>!1));const t={getTrackingConsent:H,setTrackingConsent:fe,userCanBeTracked:Q,getRegulation:q,isRegulationEnforced:z,getShopPrefs:J,shouldShowGDPRBanner:ee,userDataCanBeSold:$,setCCPAConsent:x,getCCPAConsent:ne,shouldShowCCPABanner:te,doesMerchantSupportGranularConsent:oe,analyticsProcessingAllowed:k,preferencesProcessingAllowed:L,marketingAllowed:ue,firstPartyMarketingAllowed:ue,saleOfDataAllowed:le,thirdPartyMarketingAllowed:le,currentVisitorConsent:Ee,shouldShowBanner:M,saleOfDataRegion:F,getRegion:X,getTrackingConsentMetafield:re,unstable:{analyticsProcessingAllowed:k,preferencesProcessingAllowed:L,marketingAllowed:ue,saleOfDataAllowed:le,currentVisitorConsent:Ee,shouldShowBanner:M,saleOfDataRegion:F}};if(!n)return t;const o=["unstable"];for(const e in t)t.hasOwnProperty(e)&&(t[e]=o.includes(e)?t[e]:ae(t[e]));return t};function de(){return Ae(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{useBugsnagReporting:!1})}function Ce(){window.Shopify.customerPrivacy=window.Shopify.trackingConsent=de({useBugsnagReporting:!0}),j(n.CONSENT_TRACKING_API_LOADED)}window.Shopify=window.Shopify?window.Shopify:{},Ce(),e.default=de,e.setGlobalObject=Ce,Object.defineProperty(e,"__esModule",{value:!0})}({}); //# sourceMappingURL=consent-tracking-api.js.map