{"version":3,"file":"shopify-web-pixel-relay-section-xxxxxxxxxxxxxxxxxxxx.min.js","mappings":"yBAuBA,MAAMA,EAAkD,CAItD,kBAAmBC,EACnB,wBAAyBA,EACzB,cAAeA,EACf,oBAAqBA,GA0BvB,SAASA,EAAQC,GACf,MAAMC,EAA8BD,EAAMC,OACS,IAAAC,EAE5CC,EAFe,iBAAXF,GAAkC,OAAXA,EACf,OAAjBC,EAAAE,QAAQC,YAARH,EAAmBI,QAAQN,EAAMO,KAAMN,GAEtB,OAAjBE,EAAAC,QAAQC,YAARF,EAAmBG,QAAQN,EAAMO,KAErC,CAEA,SAASC,EAAmBC,GAC1B,GAA0B,WAAtBC,SAASC,UAIa,mBAAtBD,SAASE,SAAb,CAIA,IAAK,MAAML,KAAQT,EACjBe,oBAAoBN,EAAMO,oBAG5B,IAAK,MAAMd,KAASe,gBAClB,IACE,MAAMC,EAAWlB,EAAe,MAALE,OAAK,EAALA,EAAOO,MAC9BS,GACFA,EAAShB,EAEb,CAAE,MAAOiB,GACPC,QAAQC,KAAKF,EACf,CAGFF,gBAAkB,GAElB,IAAK,MAAMR,KAAQT,EACjBsB,iBAAiBb,EAAMT,EAAUS,GApBnC,CAsBF,CAgB4B,aAAxBc,SAASC,YAAqD,gBAAxBD,SAASC,WACjDC,WAAWf,GAEXY,iBAAiB,mBAAoBZ","sources":["webpack://lange/./scripts/sections/shopify-web-pixel-relay/index.ts"],"sourcesContent":["import type * as _ShopifyBrowserTypes from '@integrabeauty/shopify-browser-types';\n\n/**\n * This module is copied from Lange and modified to support the Ofir\n */\ndeclare global {\n  /**\n   * Initialized in swp-relay liquid to the value of localization.market.handle\n   *\n   * @example \"us\"\n   * @example \"ca\"\n   * @example \"gb\"\n   */\n  // eslint-disable-next-line @typescript-eslint/naming-convention\n  var swp_market_handle: string;\n\n  // eslint-disable-next-line @typescript-eslint/naming-convention\n  var swp_event_queue: Event[];\n\n  // eslint-disable-next-line @typescript-eslint/naming-convention\n  var swp_event_listener: (event: Event) => void;\n}\n\nconst listeners: Record<string, (event: any) => void> = {\n  /**\n   * TODO most probably, to remove\n   */\n  'ofir-ad-clicked': forward,\n  'visitor-authenticated': forward,\n  'form-submit': forward,\n  'identity-captured': forward\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 * @todo we cannot naively relay all events to web pixels, only certain kinds of values can be\n * included in the properties of events because the events cross window boundaries into the sandbox\n * and we end up errors in the sandboxes when processing the events, Shopify's WPM library has a\n * validation check that routinely throws. We cannot use a try/catch here to suppress the errors. We\n * will need to refactor this module to explicitly relay only specific events using only specific\n * properties with full knowledge and coupling to each particular event and its impact on downstream\n * services. fixing this will fix the \"value must be on the following types ...\" errors.\n *\n * @see https://shopify.dev/docs/api/pixels/customer-events\n * @see https://shopify.dev/api/consent-tracking\n */\nfunction forward(event: CustomEvent) {\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 onDOMContentLoaded(_event: Event) {\n  if (location.protocol !== 'https:') {\n    return;\n  }\n\n  if (location.hostname !== 'ofirbeauty.com') {\n    return;\n  }\n\n  for (const type in listeners) {\n    removeEventListener(type, swp_event_listener);\n  }\n\n  for (const event of swp_event_queue) {\n    try {\n      const listener = listeners[event?.type];\n      if (listener) {\n        listener(event);\n      }\n    } catch (error) {\n      console.warn(error);\n    }\n  }\n\n  swp_event_queue = [];\n\n  for (const type in listeners) {\n    addEventListener(type, listeners[type]);\n  }\n}\n\n// Wait until the DOM has loaded to register event listeners. The reason this does not replay on\n// module load is because event forwarding needs to use a Shopify WPM API exposed through the\n// Shopify global and it is possible for this script to be loaded prior to Shopify's script.\n// Sometimes Shopify.analytics.publish is not defined prior to the replay. It is not clear why,\n// perhaps Shopify is waiting to define/expose analytics.publish until some other script is loaded.\n// We need Shopify.analytics.publish to be defined in order to replay. By waiting until the DOM has\n// loaded this increases the chance Shopify.analytics.publish is defined in the cases where this\n// script runs too early. Waiting longer is fine because we replay events to late- registered\n// listeners. The only issue is waiting too long, leading to loss of events. Also, we still are not\n// guaranteeing that the publish function is defined, just increasing the chance.\n//\n// TODO: investigate when and how Shopify.analytics.publish is defined, record the research in docs,\n// then implement a way to wait for the function to become defined.\n\nif (document.readyState === 'complete' || document.readyState === 'interactive') {\n  setTimeout(onDOMContentLoaded);\n} else {\n  addEventListener('DOMContentLoaded', onDOMContentLoaded);\n}\n"],"names":["listeners","forward","event","detail","_Shopify$analytics","_Shopify$analytics2","Shopify","analytics","publish","type","onDOMContentLoaded","_event","location","protocol","hostname","removeEventListener","swp_event_listener","swp_event_queue","listener","error","console","warn","addEventListener","document","readyState","setTimeout"],"sourceRoot":""}