and runs during HTML parse, but hubspotutk is set by js.hs-analytics.net, measured loading at ~834ms. On a first visit the cookie does not exist yet, so a single read returns nothing and the visitor gets no external ID at all โ€” and a first visit is exactly what an ad click is. So poll briefly until HubSpot sets it. The SDK loads lazily (~4.5s) and replays a queue, so an init queued a second or two in still lands before any events are transmitted. */ (function attachExternalId() { var attempts = 0; var MAX_ATTEMPTS = 40; /* 40 x 200ms = 8s, then give up quietly */ var timer = null; function tryAttach() { var raw = getExternalId(); if (!raw) { if (++attempts >= MAX_ATTEMPTS && timer) clearInterval(timer); return; } if (timer) clearInterval(timer); sha256Hex(raw).then(function (hash) { oaiq("init", { user: { external_id_sha256: hash } }); }).catch(function () {}); } tryAttach(); /* returning visitor: immediate */ if (!getExternalId()) timer = setInterval(tryAttach, 200); })(); /* --------------------------------------------------------------------------- 2. Load the SDK off the critical path Whichever comes first: the main thread going idle after load, or the first sign of real user intent. No preconnect on purpose โ€” a TLS handshake during LCP for a script we deliberately deferred is a net loss. Measured on clickpost.ai: load event 3614ms, SDK fetched 4508ms. ------------------------------------------------------------------------ */ var loaded = false; var INTENT = ["pointerdown", "keydown", "scroll"]; function loadSdk() { if (loaded) return; loaded = true; INTENT.forEach(function (t) { removeEventListener(t, loadSdk, { passive: true }); }); var s = document.createElement("script"); s.src = SDK; s.async = true; s.fetchPriority = "low"; document.head.appendChild(s); } INTENT.forEach(function (t) { addEventListener(t, loadSdk, { passive: true, once: true }); }); addEventListener("load", function () { window.requestIdleCallback ? requestIdleCallback(loadSdk, { timeout: 2500 }) : setTimeout(loadSdk, 1500); }, { once: true }); /* --------------------------------------------------------------------------- 3. Conversion id sha256(lowercase(email) + "|" + formId + "|" + ISO-hour), first 20 hex, "lead_" prefix. - email lowercased/trimmed so casing does not fork the id - formId keeps two different forms in the same hour from colliding - the hour bucket is only the server's fallback; the id computed here is sent to the relay verbatim, so the two paths cannot disagree even when a submit straddles an hour boundary Ads Manager's own sample omits event_id. We send it so the pixel event and the relay event collapse into one conversion instead of counting twice. ------------------------------------------------------------------------ */ function buildEventId(email, formId) { var seed = [ String(email || "").trim().toLowerCase(), String(formId || ""), new Date().toISOString().slice(0, 13) ].join("|"); return crypto.subtle.digest("SHA-256", new TextEncoder().encode(seed)).then(function (buf) { var hex = Array.prototype.map.call(new Uint8Array(buf), function (b) { return b.toString(16).padStart(2, "0"); }).join(""); return "lead_" + hex.slice(0, 20); }); } /* Guards a re-fire from the history.pushState that book-a-demo-core.js runs after submit, and from back-navigation onto the same state. */ function firedOnce(id) { try { if (sessionStorage.getItem("oaiq_" + id)) return true; sessionStorage.setItem("oaiq_" + id, "1"); return false; } catch (e) { return false; /* private mode / blocked storage: fire rather than lose it */ } } /* Path 2. keepalive lets the request finish even if the page navigates away. Failures are swallowed deliberately: a reporting call must never surface an error to someone who just submitted a form. The relay hashes the email server-side into user.emails_sha256 and adds the caller's IP and user agent, so this event carries the same match signals the pixel gets for free. */ function sendToRelay(email, formId, eventType, eventId) { try { var payload = { token: RELAY_TOKEN, email: email, form_id: formId || "", event_type: eventType, event_id: eventId, /* verbatim, so both paths always match */ source_url: location.href }; var oppref = getOppref(); if (oppref) payload.oppref = oppref; var externalId = getExternalId(); if (externalId) payload.external_id = externalId; fetch(RELAY_URL, { method: "POST", keepalive: true, headers: { "Content-Type": "application/json" }, body: JSON.stringify(payload) }).catch(function () {}); } catch (e) {} } /* Capture the email while the form is still on the page. onFormSubmitted does not reliably carry submissionValues, and by then the form may be removed. */ var lastEmail = ""; document.addEventListener("submit", function (e) { var f = e.target; if (!f || !f.querySelector) return; var i = f.querySelector('input[name="email"], input[type="email"]'); if (i && i.value) lastEmail = i.value; }, true); /* Every HubSpot form on the site reports through this one message event, so no module or theme JS needs editing to add coverage. */ window.addEventListener("message", function (e) { var d = e.data; if (!d || d.type !== "hsFormCallback" || d.eventName !== "onFormSubmitted") return; var email = (d.data && d.data.submissionValues && d.data.submissionValues.email) || lastEmail; if (!email) return; /* without an email there is no stable id to dedupe on */ var eventType = EVENT_BY_FORM[d.id] || EVENT_DEFAULT; buildEventId(email, d.id).then(function (id) { if (firedOnce(id)) return; oaiq("measure", eventType, { type: DATA_TYPE }, { event_id: id }); /* path 1 */ sendToRelay(email, d.id, eventType, id); /* path 2 */ }); }); })();

91สำฦต

Assess Your Post-Purchase Brand Readiness Start Assessment

Free DHL Rate Estimator

DHL Shipping Cost Calculator & Rates Guide (2026)

Calculate DHL shipping costs with our 2026 guide. Compare rates by weight, destination, and service, and understand surcharges and international shipping fees.
  • 5
    DHL service tiers
  • 220+
    Countries & territories
  • 19K+
    Pin codes (India)
  • โ‚น0
    Cost to use
The Calculator

DHL Shipping Rate Calculator

Enter origin & destination details, package weight, dimensions, and shipment type โ€” get instant DHL shipping cost estimates across Express Worldwide, Express 12:00, eCommerce, and Parcel International services.

Route
Package details
KG
CM
CM
CM
Payment mode

Your DHL rate estimate appears here

Enter origin PIN, destination zone, weight, and shipment type to compare rates across DHL Express, eCommerce, and Parcel International services.

Estimates based on indicative DHL published rate slabs. Actual rates depend on contracted account discounts, weekly fuel surcharge, customs duties, and remote area fees.

Brands with ClickPost spend 22% lesser on shipping. Want to know how?

Explore ClickPost
How it works

Get a DHL rate estimate in four steps

No DHL account needed. Enter your shipment details to instantly compare rates across every DHL service tier, with the weekly fuel surcharge and zone-based international pricing already factored in.
  1. Enter origin PIN

    Type the 6-digit Indian PIN code where DHL will pick up your shipment. This determines whether your origin falls in a metro service area or a partner-handled remote zone (which adds surcharges).

  2. Choose destination zone

    Select a destination โ€” India (domestic), or one of DHL's international zones from South Asia (Zone 1) to Latin America/Africa (Zone 9). DHL's global zone matrix sets the base international rate.

  3. Add weight & dimensions

    Enter weight in kilograms and dimensions in centimeters. DHL applies volumetric weight (Lร—Wร—Hรท5,000 for Express; รท6,000 for eCommerce on some lanes) when it exceeds actual weight โ€” bulky lightweight shipments get billed at the higher figure.

  4. Select shipment contents

    Pick Parcel/Goods for commercial shipments (subject to customs and duties at destination) or Documents for non-dutiable paperwork. Documents are typically priced 15โ€“25% lower than parcels of equivalent weight.

Six DHL services compared

Each DHL service is engineered for a specific speedโ€“costโ€“geography trade-off. Here's when to use each one โ€” and what to expect on transit, weight handling, and customs support.

DHL Express 12:00

By noon next business day
 

Premium time-definite delivery guaranteed by 12:00 on the next possible business day. Used for critical international documents and parcels โ€” legal, medical, and high-value B2B. Comes with Money-Back Guarantee on most lanes.

 
  • Transit: 1โ€“2 days ยท International

DHL Express Worldwide

Most popular international tier
 

End-of-day door-to-door international express delivery to 220+ countries. Includes full customs clearance, real-time tracking, and on-demand delivery options. The default DHL service for cross-border B2C and B2B.

  • Transit: 1โ€“4 days ยท International

DHL eCommerce / Parcel International Standard

Affordable cross-border B2C
 

Cost-optimized international service for low-value B2C ecommerce parcels. Tracked, delivered via local postal partners in the destination country. Ideal for D2C brands shipping abroad where 6โ€“14 day transit is acceptable.

  • Transit: 6โ€“14 days ยท International

DHL Parcel International Direct

Faster eCommerce, fully tracked
 

Mid-tier cross-border parcel service with direct injection into destination country networks. Faster than Standard, cheaper than Express. Strong for EU and UK lanes โ€” typically 4โ€“8 business day transit.

  • Transit: 4โ€“8 days ยท International

DHL Global Forwarding (Air Freight)

Heavy & palletized cargo
 

Air freight forwarding for shipments above 70 kg or palletized cargo unsuited to express. Door-to-port or port-to-port options. Used by B2B exporters, manufacturers, and brands with bulk cross-border replenishment needs.

  • Transit: 3โ€“7 days ยท Freight

DHL Same Day / Sprintline

Mission-critical ยท door-to-door
 

Hand-carried, on-board courier, and same-day delivery for the most time-sensitive international shipments. Used for legal documents, AOG aircraft parts, clinical trial samples. Premium pricing, dedicated handling.

  • Transit: Same day ยท Selected lanes
91สำฦต factors

Six factors that determine your DHL shipping cost

DHL pricing is more complex than weight times distance. Six interlocking variables determine what you actually pay, and understanding all of them is what separates accurate shipment planning from invoice surprises at scale.
  • Factor 01

    Chargeable weight

    DHL bills the higher of actual weight or volumetric weight. Volumetric weight punishes bulky-but-light packages โ€” apparel, footwear, low-density consumer goods. Right-sizing the box before you weigh is the single highest-leverage shipping cost lever.

  • Factor 02

    Destination zone

    DHL uses a 9โ€“10 zone international matrix โ€” Zone 1 (South Asia neighbours) is cheapest, Zone 9 (Latin America, Africa) is the most expensive. Two countries on the same continent can sit in different zones based on DHL's network economics.

  • Factor 03

    Volumetric divisor

    DHL Express uses a divisor of 5,000 (cm/kg) globally. A 50ร—40ร—30 cm box weighing 3 kg has volumetric weight of 12 kg โ€” you pay for 12 kg. DHL eCommerce uses 6,000 on certain lanes, slightly more forgiving for lightweight goods.

  • Factor 04

    Service product chosen

    DHL Express 12:00 costs 30โ€“60% more than Express Worldwide for the same lane. Express Worldwide costs 2.5โ€“4ร— more than eCommerce Standard. Matching the right product to actual customer expectations โ€” not internal assumptions โ€” is the largest cost decision.

  • Factor 05

    Customs, duties & taxes

    For international parcels, DDP (Delivered Duty Paid) versus DAP (Delivered at Place) materially changes total landed cost. DHL can collect duty/tax on the buyer's behalf, but adds a brokerage and disbursement fee โ€” typically โ‚น150โ€“โ‚น600 depending on shipment value.

  • Factor 06

    Fuel & emergency surcharges

    DHL applies a fuel surcharge that's recalculated weekly using the U.S. Gulf Coast jet fuel index โ€” currently in the 22โ€“32% range, applied on top of the base rate. Emergency Situation Surcharges may also apply during global disruptions and can add 5โ€“15% on specific lanes.

The math

Key DHL pricing formulas

DHL uses different billing mechanics for volumetric weight, zone-based international rates, and surcharge stacking. These are the core formulas every cross-border shipper should commit to memory.

  • Zone-Based International

    Standard zone pricing

    Cost = Base Rate(Service, Zone)

    + Per-kg Rate ร— Add'l Wt

    + Fuel Surcharge (22โ€“32%)

    + Other surcharges

    Zone 1 = South Asia, cheapest

    Zone 9 = LatAm/Africa, highest rates

  • Total Landed Cost

    What you actually pay

    Total = Base Rate

    + Fuel Surcharge

    + Remote Area Fee (if any)

    + Duty / Tax / Brokerage (DDP)

    + GST (18% on shipping in India)

    Surcharges can add 25โ€“40% on base

    DDP billed separately by destination

DHL zone system

Understanding DHL international zones

Every destination country sits in one of nine DHL zones, assigned by network economics not geography alone. Zone 1 is the most cost-effective international lane. Zone 9 carries the highest base rates and the greatest exposure to remote area surcharges.

1
South Asia
Sri Lanka, Nepal, Bangladesh, Bhutan. Lowest international rates.
3
SE Asia / ME
Singapore, Malaysia, Thailand, UAE, Saudi Arabia.
5
East Asia / Oceania
China, Japan, Hong Kong, Australia, NZ.
7
Europe
UK, Germany, France, Netherlands, Italy.
8
North America
USA, Canada, Mexico. Premium volume lane.
9
LatAm / Africa
Brazil, Argentina, South Africa, Nigeria. Highest rates.
Rate reference

DHL Express published rates by zone

Indicative rates for a 0.5 kg DHL Express Worldwide shipment originating in India. Contracted discounts of 30โ€“60%, weekly fuel surcharge, and remote area or DDP fees will determine your actual cost.

ServiceZone 1 (South Asia)Zone 3 (SE Asia / ME)Zone 7 (Europe)Zone 8 (USA / Canada)Transit
DHL Express 12:00 โ‚น2,400โ€“โ‚น3,200by-noon delivery โ‚น3,200โ€“โ‚น4,400 โ‚น3,200โ€“โ‚น4,400 โ‚น4,500โ€“โ‚น6,200 1โ€“2 days
DHL Express Worldwide โ‚น1,800โ€“โ‚น2,400most popular tier โ‚น2,400โ€“โ‚น3,400 โ‚น2,800โ€“โ‚น4,200 โ‚น3,200โ€“โ‚น4,800 1โ€“4 days
DHL Parcel International Direct โ‚น1,100โ€“โ‚น1,600 โ‚น1,600โ€“โ‚น2,400 โ‚น2,000โ€“โ‚น2,900 โ‚น2,200โ€“โ‚น3,200 4โ€“8 days
DHL eCommerce Standard โ‚น650โ€“โ‚น950cheapest cross-border โ‚น950โ€“โ‚น1,500 โ‚น1,400โ€“โ‚น2,200 โ‚น1,600โ€“โ‚น2,500 6โ€“14 days

* Approximate published rates for a 0.5 kg parcel ex-India. Excludes weekly fuel surcharge (currently 22โ€“32%), 18% GST on India-side shipping charges, customs duties, and any remote-area / DDP / oversized-piece surcharges. Volumetric weight pricing applies when (Lร—Wร—H)รท5,000 exceeds actual weight in kg.

Inbound to India

DHL Express inbound rates to India

Indicative rates for a 0.5 kg DHL Express Worldwide parcel arriving into India from major origin regions. Inbound parcels are subject to Indian customs duties and IGST collected at destination.

OriginExpress 12:00Express WorldwideParcel InternationalTransit (to BOM/DEL)
From USA / Canada $80โ€“$120 $45โ€“$75 $22โ€“$38 2โ€“5 days
From Europe (UK, DE, FR) โ‚ฌ55โ€“โ‚ฌ95 โ‚ฌ35โ€“โ‚ฌ65 โ‚ฌ18โ€“โ‚ฌ32 2โ€“4 days
From China / Hong Kong $50โ€“$80 $28โ€“$45 $14โ€“$24 2โ€“4 days
From Singapore / SEA $45โ€“$70 $25โ€“$40 $12โ€“$22 1โ€“3 days

* Inbound rates are charged in origin currency. India customs duty (BCD + IGST + Social Welfare Surcharge) is collected at destination either by DHL via DDP or directly from the consignee. Documents are typically priced lower than parcels of equivalent weight.

Cost optimization

Seven ways to reduce DHL shipping spend

Concrete tactics that cross-border ecommerce brands and exporters use to cut DHL shipping costs by 20โ€“35% without sacrificing transit reliability or customer experience.

  • 1
    โ†“ 12โ€“20%

    Right-size every box

    DHL's volumetric pricing is unforgiving โ€” a 5,000 divisor means even modest dead space inflates chargeable weight. Switch to right-sized custom cartons or poly mailers for non-fragile goods. A 25% reduction in box volume can shave 12โ€“20% off your DHL invoice instantly.

  • 2
    โ†“ 40โ€“55%

    Move B2C to DHL eCommerce

    For non-urgent international B2C ecommerce, DHL eCommerce / Parcel International Standard is 40โ€“55% cheaper than Express Worldwide. Reserve Express for fashion drops, restocks, and customers paying for premium delivery. Most international shoppers tolerate 6โ€“14 day transit if expectations are set.

  • 3
    โ†“ 30โ€“60%

    Negotiate a contracted account

    Published DHL rates are list prices. Brands shipping 50+ international parcels per day routinely secure 30โ€“60% discounts via contracted account pricing. Quarterly volume reviews are negotiation triggers โ€” DHL's sales team will match competitive offers from FedEx and UPS.

  • 4
    โ†“ 15โ€“25%

    Use multi-carrier allocation

    DHL is rarely cheapest on every lane. ClickPost's carrier allocation engine routes each shipment to the optimal carrier โ€” DHL for Europe and Middle East express, FedEx for North America priority, Aramex for GCC, India Post for low-value documents. Lane-by-lane optimization saves 15โ€“25% across the global ledger.

  • 5
    DDP transparency

    Pre-pay duties via DDP

    Under DAP, your customer gets a surprise duty bill at delivery and may refuse the parcel โ€” driving up returns and refusals. DHL's DDP option lets you pre-pay duties at checkout (passed transparently to the customer), reducing refusals by 20โ€“40% for B2C international.

  • 6
    Avoid surcharges

    Flag remote postcodes upfront

    DHL remote area surcharges range โ‚น150โ€“โ‚น450 per shipment and apply to thousands of international postcodes. Validate destination addresses against DHL's remote-area zone list at checkout โ€” either decline to ship or transparently surface the surcharge to the buyer at the cart stage.

  • 7
    โ†“ 2โ€“4%

    Reconcile DHL invoices weekly

    Volumetric weight discrepancies, duplicate fuel surcharge billing, and DDP brokerage fees are the most common DHL invoice errors. Run automated reconciliation against your shipment records weekly โ€” ClickPost's audit module typically recovers 2โ€“4% of total DHL spend in billing corrections.

Use the calculator at the top of this page. Enter origin ZIP, destination country, package weight, and dimensions โ€” you'll see DHL Express Worldwide, Express Envelope, and eCommerce Packet rates side by side. International rates exclude customs duties and destination taxes, which are billed separately by the destination country.

For international shipping, DHL usually wins on speed and cost to Europe and Asia โ€” often 10โ€“20% cheaper than FedEx International Priority and UPS Worldwide Express on the same lanes. For US domestic, DHL is rarely the right choice; UPS and FedEx Ground typically beat DHL by 30โ€“50%. Rule of thumb: use DHL for outbound international, UPS/FedEx for everything else.

Three reasons stack up: DHL's fuel surcharge runs higher than US carriers (currently 25โ€“30% vs FedEx's 15โ€“18%), most international shipments cross multiple customs zones with handling fees at each, and DHL prices in remote area surcharges aggressively โ€” anything outside major metros adds $25โ€“$50. The base rate is competitive; it's the surcharges that inflate the final bill.

DHL Express is the premium overnight/2-day product โ€” runs $35โ€“$100+ for most domestic packages. DHL eCommerce (formerly DHL SmartMail) is the budget option at $5โ€“$15 for lightweight parcels, but transit takes 3โ€“8 days and final-mile delivery is handed off to USPS. eCommerce only makes sense for non-urgent ecommerce shipments under 5 lbs.

DHL doesn't really compete in US domestic overnight โ€” they exited that market in 2008. What's marketed as "DHL overnight" today is usually DHL Express Worldwide for international urgent shipments. For US-to-US overnight, FedEx Priority Overnight ($45โ€“$85) and UPS Next Day Air ($50โ€“$95) are the standard options, and both significantly cheaper than asking DHL to handle it.

For DHL Express Worldwide US to China: a 1 lb package runs roughly $85โ€“$120 (2โ€“4 day delivery), 5 lbs is $180โ€“$240, and 10 lbs is $280โ€“$380. DHL eCommerce Packet is cheaper at $25โ€“$60 for lightweight packages but takes 7โ€“14 days. Add 25โ€“30% fuel surcharge and check China customs rules โ€” many product categories have restrictions or require additional documentation.

For Europe: USPS Priority Mail International ($45โ€“$90 for 5 lbs) and FedEx International Economy beat DHL on price for non-urgent shipments. For Asia: UPS Worldwide Saver is competitive on cost. For very lightweight items (under 1 lb), USPS First-Class Package International Service is the cheapest at $15โ€“$35, though tracking ends once it leaves the US. Aggregators like Pirate Ship and Easyship pool volume to give you 30โ€“50% off DHL retail.

DHL charges whichever is higher. Dimensional weight for international is calculated as (Length ร— Width ร— Height in cm) รท 5,000, or in inches รท 139. A 20ร—16ร—12 inch box weighing 8 lbs has dimensional weight of 27.6 lbs โ€” and that's what you'll pay for. International dimensional weight pricing is stricter than domestic, so right-sized packaging matters even more for cross-border shipments.

Usually yes โ€” DHL Express runs 8โ€“15% cheaper than FedEx International Priority for sub-5 lb shipments to Europe and Asia, especially to remote destinations where DHL's network is stronger. The gap narrows to North America and major metro lanes. Always check both: small businesses with FedEx contracts sometimes get rates that beat DHL retail, but DHL retail beats FedEx retail on most international routes.

DHL recalculates fuel surcharge monthly based on jet fuel and diesel index averages. The percentage currently sits around 25โ€“30% on international Express shipments and 15โ€“20% on ground/eCommerce services. It's published on DHL's website each month and applied as a separate line item on your invoice. A 5% swing in the fuel index can shift your effective rate by $5โ€“$25 per shipment, so check the current rate when forecasting costs.

Elevate Your Post-Purchase Experience with ClickPost

Keep customers informed and engaged with seamless order tracking, proactive delivery updates, and personalized post-purchase communication. Build customer trust, reduce WISMO queries, and drive repeat purchases with ClickPost.

  • 700+
    Carrier integrations
  • 600+
    Enterprise clients
  • 22%
    Avg. shipping savings
  • 99.9%
    Uptime SLA
. window.disableHubSpotCookieBanner = true; function killNative() { var n = document.getElementById("hs-eu-cookie-confirmation"); if (n && n.parentNode) { n.parentNode.removeChild(n); return true; } return false; } killNative(); if (window.MutationObserver) { var mo = new MutationObserver(function () { killNative(); }); mo.observe(document.documentElement, { childList: true, subtree: true }); setTimeout(function () { mo.disconnect(); }, 15000); } var COOKIE = "cp_cookie_consent"; var EU = ["at","be","bg","hr","cy","cz","dk","ee","fi","fr","de","gr","hu","ie","it","lv","lt","lu","mt","nl","pl","pt","ro","sk","si","es","se","gb","uk","is","li","no","ch"]; function readCookie(nm) { var m = document.cookie.match(new RegExp("(?:^|; )" + nm + "=([^;]*)")); return m ? decodeURIComponent(m[1]) : null; } function writeCookie(nm, val, days) { var d = new Date(); d.setTime(d.getTime() + (days * 864e5)); document.cookie = nm + "=" + encodeURIComponent(val) + ";expires=" + d.toUTCString() + ";path=/;SameSite=Lax" + (location.protocol === "https:" ? ";Secure" : ""); } function stored() { var raw = readCookie(COOKIE); if (!raw) return null; try { var o = JSON.parse(raw); if (typeof o.analytics === "boolean") return o; } catch (e) {} return null; } function apply(state, revoke) { window._hsp = window._hsp || []; window._hsp.push(["setHubSpotConsent", { analytics: !!state.analytics, advertisement: !!state.advertisement, functionality: !!state.functionality }]); if (revoke && !state.analytics && !state.advertisement && !state.functionality) { window._hsp.push(["revokeCookieConsent"]); } window.dataLayer = window.dataLayer || []; window.dataLayer.push({ event: "cp_cookie_consent", cp_consent_analytics: !!state.analytics, cp_consent_advertisement: !!state.advertisement, cp_consent_functionality: !!state.functionality }); document.documentElement.setAttribute("data-cp-consent", "set"); } function inScope(banner) { if (banner.getAttribute("data-scope") !== "eu_only") return true; var geo = (document.body.getAttribute("data-geo_location") || "").toLowerCase(); if (!geo) return true; return EU.indexOf(geo) !== -1; } function init(banner) { var days = parseInt(banner.getAttribute("data-days"), 10) || 180; var prefs = banner.querySelector("[data-cpcb-prefs]"); var compact = banner.querySelector('[data-cpcb-actions="compact"]'); var expanded = banner.querySelector('[data-cpcb-actions="expanded"]'); var toggles = banner.querySelectorAll("[data-cpcb-toggle]"); function show() { banner.hidden = false; requestAnimationFrame(function () { banner.classList.add("is-visible"); }); } function hide() { banner.classList.remove("is-visible"); setTimeout(function () { banner.hidden = true; }, 300); } function collapse() { if (!prefs) return; prefs.hidden = true; if (expanded) expanded.hidden = true; if (compact) compact.hidden = false; } function expand() { if (!prefs) return; prefs.hidden = false; if (compact) compact.hidden = true; if (expanded) expanded.hidden = false; } function paint(state) { Array.prototype.forEach.call(toggles, function (t) { var key = t.getAttribute("data-cpcb-toggle"); if (key === "necessary") { t.setAttribute("aria-checked", "true"); return; } t.setAttribute("aria-checked", state[key] ? "true" : "false"); }); } function fromToggles() { var state = { analytics: false, advertisement: false, functionality: false }; Array.prototype.forEach.call(toggles, function (t) { var key = t.getAttribute("data-cpcb-toggle"); if (key in state) state[key] = t.getAttribute("aria-checked") === "true"; }); return state; } function commit(state, revoke) { writeCookie(COOKIE, JSON.stringify({ analytics: !!state.analytics, advertisement: !!state.advertisement, functionality: !!state.functionality, v: 1, ts: Date.now() }), days); apply(state, revoke); hide(); } Array.prototype.forEach.call(toggles, function (t) { if (t.disabled) return; t.addEventListener("click", function () { t.setAttribute("aria-checked", t.getAttribute("aria-checked") === "true" ? "false" : "true"); }); }); banner.addEventListener("click", function (e) { if (!e.target || !e.target.closest) return; var btn = e.target.closest("[data-cpcb-action]"); if (!btn) return; var action = btn.getAttribute("data-cpcb-action"); if (action === "customise") { expand(); return; } if (action === "accept") { commit({ analytics: true, advertisement: true, functionality: true }, false); return; } if (action === "reject") { commit({ analytics: false, advertisement: false, functionality: false }, true); return; } if (action === "save") { commit(fromToggles(), true); return; } }); var existing = stored(); if (existing) { apply(existing, false); paint(existing); collapse(); } else if (!inScope(banner)) { // Out of the consent-required region: implied consent, banner never shown. commitSilently(); } else { collapse(); show(); } function commitSilently() { var all = { analytics: true, advertisement: true, functionality: true }; writeCookie(COOKIE, JSON.stringify({ analytics: true, advertisement: true, functionality: true, v: 1, ts: Date.now(), implied: true }), days); apply(all, false); } // Public re-open hook for a footer "Cookie settings" link. window.cpCookieBanner = window.cpCookieBanner || {}; window.cpCookieBanner.open = function () { var s = stored() || { analytics: false, advertisement: false, functionality: false }; paint(s); expand(); show(); }; } function boot() { var banners = document.querySelectorAll("[data-cpcb]"); if (!banners.length) return; init(banners[0]); document.addEventListener("click", function (e) { if (!e.target || !e.target.closest) return; var trigger = e.target.closest("[data-cp-cookie-settings]"); if (!trigger) return; e.preventDefault(); if (window.cpCookieBanner && window.cpCookieBanner.open) window.cpCookieBanner.open(); }); } if (document.readyState === "loading") { document.addEventListener("DOMContentLoaded", boot); } else { boot(); } })();