{"version":3,"file":"shopify-analytics-bridge-snippet.min.js","mappings":"yBACA,IAAAA,EAAA,CCAAA,EAAA,SAAAC,GACAC,OAAAC,eAAAF,EAAAG,OAAAC,YAAA,CAAsDC,MAAA,WACtDJ,OAAAC,eAAAF,EAAA,cAAgDK,OAAA,GAChD,WCoCA,MAAMC,EAAkD,CACtD,yBAgBF,SAAgCC,GAC9BC,EAAQD,GAERC,EAAQ,IAAIC,YAAY,iBAAkB,CACxCC,OAAQH,EAAMG,SAElB,GAhBA,SAASC,EAAWC,GAElB,OADsCN,EAAUM,IAASJ,CAE3D,CA8BA,SAASA,EAAQD,GAAoB,IAAAM,EACnC,GAA0C,mBAAd,OAAxBA,EAAOC,QAAQC,gBAAS,EAAjBF,EAAmBG,SAE5B,YADAC,QAAQC,MAAM,4DAIhB,MAAMR,EAA8BH,EAAMG,OACpB,iBAAXA,GAAkC,OAAXA,EAChCI,QAAQC,UAAUC,QAAQT,EAAMK,KAAMF,GAEtCI,QAAQC,UAAUC,QAAQT,EAAMK,KAEpC,EAEA,WAAgB,IAAAO,EAGd,GAA0C,mBAAd,OAAxBA,EAAOL,QAAQC,gBAAS,EAAjBI,EAAmBH,UAK9B,GAA0B,WAAtBI,SAASC,UAIa,kBAAtBD,SAASE,SAAb,CAIA,IAAK,MAAMV,KAAQW,yBAAyBC,YAC1CC,oBAAoBb,EAAMW,yBAAyBG,UAGrD,IAAK,MAAMnB,KAASgB,yBAAyBI,MAAO,CAClD,MAAMC,EAAUjB,EAAgB,MAALJ,OAAK,EAALA,EAAOK,MAElC,IACEgB,EAAQrB,EACV,CAAE,MAAOsB,GACPZ,QAAQa,KAAKD,EACf,CACF,CAEAN,yBAAyBI,MAAQ,GAEjC,IAAK,MAAMf,KAAQW,yBAAyBC,YAC1CO,iBAAiBnB,EAAMD,EAAWC,GAnBpC,OAVEK,QAAQC,MAAM,wDA+BlB,CAEAc","sources":["webpack://lange/webpack/bootstrap","webpack://lange/webpack/runtime/make namespace object","webpack://lange/./snippets/shopify-analytics-bridge/index.ts"],"sourcesContent":["// The require scope\nlet __webpack_require__ = {};\n\n","// define __esModule on exports\n__webpack_require__.r = function(exports) {\n\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import type {} from '@integrabeauty/shopify-browser-types';\n\ndeclare global {\n  /**\n   * Holds the global state for the Shopify analytics bridge. Created in the snippet liquid before\n   * this module loads so that events can be captured and replayed once the module initializes.\n   */\n  var shopify_analytics_bridge: {\n    /**\n     * The event names the bridge forwards. Defined in the snippet liquid so that the parse-time\n     * listener and this module work from one list rather than two copies kept in sync by hand.\n     */\n    event_types: string[];\n\n    /**\n     * A listener used by the snippet liquid to capture events before this module loads.\n     *\n     * This is only declared for awareness purposes. Nothing should use this other than the snippet\n     * liquid.\n     */\n    listener: (event: Event) => void;\n\n    /**\n     * Initialized in the snippet liquid to the value of localization.market.handle\n     *\n     * @example \"us\"\n     * @example \"ca\"\n     * @example \"gb\"\n     */\n    market_handle: string;\n\n    /**\n     * Captures events that occurred before this module loaded.\n     */\n    queue: Event[];\n  };\n}\n\n// Event types needing something other than a plain forward. Everything else in the liquid's list\n// falls through to forward, so only the exceptions appear here.\nconst overrides: Record<string, (event: any) => void> = {\n  'product-variant-viewed': onProductVariantViewed\n};\n\n/**\n * Returns the handler for the given event type, falling back to a plain forward.\n */\nfunction handlerFor(type: string) {\n  const handler: (event: any) => void = overrides[type] || forward;\n  return handler;\n}\n\n/**\n * Relays a product-variant-viewed event as both a product-variant-viewed event and also a product-\n * viewed event. The event was renamed, but several live pixels are still using the old name, so we\n * have to emit both events until the pixels are migrated.\n */\nfunction onProductVariantViewed(event: WindowEventMap['product-variant-viewed']) {\n  forward(event);\n\n  forward(new CustomEvent('product-viewed', {\n    detail: event.detail\n  }));\n}\n\n/**\n * Relays the given event to Shopify's Web Pixel Manager.\n *\n * We relay all events regardless of consent because consent is checked downstream by the various\n * service workers.\n *\n * For unclear reasons the publish function is routinely not defined by the time this runs. We were\n * logging this for a while, and have investigated, and there is no explanation. One plausible\n * reason is because someone is using a broken browser extension that messes with globals or an out\n * of date browser. We have decided to stop monitoring this error in Sentry because it just amounts\n * to spam. When this error happens we ignore it and just log a message.\n *\n * @see https://shopify.dev/docs/api/web-pixels-api/standard-events\n * @see https://shopify.dev/docs/api/customer-privacy\n */\nfunction forward(event: CustomEvent) {\n  if (typeof Shopify.analytics?.publish !== 'function') {\n    console.debug('Shopify.analytics.publish is not defined when forwarding');\n    return;\n  }\n\n  const detail: Record<string, any> = event.detail;\n  if (typeof detail === 'object' && detail !== null) {\n    Shopify.analytics.publish(event.type, detail);\n  } else {\n    Shopify.analytics.publish(event.type);\n  }\n}\n\nfunction main() {\n  // This is defined in the content_for_header liquid tag in the head. Provided this script is\n  // loaded after that, this should always be defined.\n  if (typeof Shopify.analytics?.publish !== 'function') {\n    console.debug('Shopify.analytics.publish is not defined when loading');\n    return;\n  }\n\n  if (location.protocol !== 'https:') {\n    return;\n  }\n\n  if (location.hostname !== 'langehair.com') {\n    return;\n  }\n\n  for (const type of shopify_analytics_bridge.event_types) {\n    removeEventListener(type, shopify_analytics_bridge.listener);\n  }\n\n  for (const event of shopify_analytics_bridge.queue) {\n    const handler = handlerFor(event?.type);\n\n    try {\n      handler(event);\n    } catch (error) {\n      console.warn(error);\n    }\n  }\n\n  shopify_analytics_bridge.queue = [];\n\n  for (const type of shopify_analytics_bridge.event_types) {\n    addEventListener(type, handlerFor(type));\n  }\n}\n\nmain();\n"],"names":["__webpack_require__","exports","Object","defineProperty","Symbol","toStringTag","value","overrides","event","forward","CustomEvent","detail","handlerFor","type","_Shopify$analytics","Shopify","analytics","publish","console","debug","_Shopify$analytics2","location","protocol","hostname","shopify_analytics_bridge","event_types","removeEventListener","listener","queue","handler","error","warn","addEventListener","main"],"sourceRoot":""}