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://lange/./scripts/integrations/common.ts","webpack://lange/./scripts/integrations/facebook/index.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\n/**\n * Do not use this export. This is a hacky fix to a strange inlining optimization performed by\n * webpack where it removes this module and points identifiers directly to the global values.\n * Without this export, webpack fails to understand that `window.__ofir` must also be inlined.\n *\n * @type {unknown}\n */\nexport const __ofir: unknown = window.__ofir;\n\n/**\n * Cart should never be undefined\n */\nexport const Cart: OfirLiquidGlobals.Cart = window.__ofir?.Cart;\n\n/**\n * Checkout is undefined if user is not loading a checkout page.\n *\n * @type {OfirLiquidGlobals.Checkout}\n */\nexport const Checkout: OfirLiquidGlobals.Checkout = window.__ofir?.Checkout;\n\n/**\n * Collection is undefined if user is not loading a product or collection page.\n *\n * @type {OfirLiquidGlobals.Collection}\n */\nexport const Collection: OfirLiquidGlobals.Collection = window.__ofir?.Collection;\n\n/**\n * Customer is undefined if user is not logged in.\n *\n * @type {OfirLiquidGlobals.Customer}\n */\nexport const Customer: OfirLiquidGlobals.Customer = window.__ofir?.Customer;\n\n/**\n * GiftCard is undefined if user is not on gift card page.\n *\n * @type {OfirLiquidGlobals.GiftCard}\n */\nexport const GiftCard: OfirLiquidGlobals.GiftCard = window.__ofir?.GiftCard;\n\n/**\n * Order is undefined unless user is on thank_you page, order status page or account/order detail\n * page.\n *\n * @type {OfirLiquidGlobals.Order}\n */\nexport const Order: OfirLiquidGlobals.Order = window.__ofir?.Order;\n\n/** @type {OfirLiquidGlobals.Page} */\nexport const Page: OfirLiquidGlobals.Page = window.__ofir?.Page;\n\n/** @type {OfirLiquidGlobals.Pagination} */\nexport const Pagination: OfirLiquidGlobals.Pagination = window.__ofir?.Pagination;\n\n/**\n * Product is undefined if not accessing a product page template.\n *\n * @type {OfirLiquidGlobals.Product}\n */\nexport const Product: OfirLiquidGlobals.Product = window.__ofir?.Product;\n\n/** @type {OfirLiquidGlobals.Request} */\nexport const Request: OfirLiquidGlobals.Request = window.__ofir?.Request;\n\n/** @type {OfirLiquidGlobals.Scripts} */\nexport const Scripts: OfirLiquidGlobals.Scripts = window.__ofir?.Scripts;\n\n/** @type {OfirLiquidGlobals.Search} */\nexport const Search: OfirLiquidGlobals.Search = window.__ofir?.Search;\n\n/** @type {OfirLiquidGlobals.SearchEngineListing} */\nexport const SearchEngineListing: OfirLiquidGlobals.SearchEngineListing =\n  window.__ofir?.SearchEngineListing;\n\n/** @type {OfirLiquidGlobals.SectionSettings} */\nexport const SectionSettings: OfirLiquidGlobals.SectionSettings = window.__ofir?.SectionSettings;\n\n/** @type {OfirLiquidGlobals.Shop} */\nexport const Shop: OfirLiquidGlobals.Shop = window.__ofir?.Shop;\n\n/** @type {OfirLiquidGlobals.Template} */\nexport const Template: OfirLiquidGlobals.Template = window.__ofir?.Template;\n\n/** @type {OfirLiquidGlobals.Theme} */\nexport const Theme: OfirLiquidGlobals.Theme = window.__ofir?.Theme;\n\n/** @type {OfirLiquidGlobals.ThemeSettings} */\nexport const ThemeSettings: OfirLiquidGlobals.ThemeSettings = window.__ofir?.ThemeSettings;\n","/**\n * Appends a script element in the head that loads its url async.\n *\n * @todo set crossorigin or other attributes?\n *\n * @param url The script url to load\n * @returns A promise that resolves to a load event or rejects with an error event\n */\nexport function loadScript(url: string) {\n  return new Promise<Event>((resolve, reject) => {\n    const script = document.createElement('script');\n    script.async = true;\n    script.addEventListener('load', resolve);\n    script.addEventListener('error', reject);\n    document.head.append(script);\n    script.src = url;\n  });\n}\n\n/**\n * Search the queue for events that have already fired. For each event, search for whether we have a\n * listener for the event. If found, directly dispatch the event to the listener. This fixes the\n * issue where the script that loads the registry does not add its event listeners until after the\n * event has fired.\n *\n * Then register event listeners for each key of the registry.\n *\n * We cannot restrict the type of parameters to the callback because we have some special callbacks\n * such as the callback for the global error event. However, most of the time the callback is just\n * one parameter, event of type Event.\n *\n * @param registry An event registry\n */\nexport function setupRegistry(registry: Record<string, (...args: unknown[]) => void>) {\n  for (const event of window.ofir.queue) {\n    const listener = registry[event?.type];\n    if (listener) {\n      listener(event);\n    }\n  }\n\n  for (const eventType in registry) {\n    addEventListener(eventType, registry[eventType]);\n  }\n}\n","import '@integrabeauty/custom-events';\nimport type {} from '@integrabeauty/meta-pixel';\nimport * as LiquidGlobals from '../../common/liquid-global.js';\nimport * as common from '../common.js';\n\n/**\n * @see https://developers.facebook.com/docs/meta-pixel/reference#object-properties\n */\nfunction onViewItem(event: WindowEventMap['ofir-view-item']) {\n  // relevant fields are content_ids, content_category, content_name, content_type, contents,\n  // currency, and value. if using dynamic ads then content_type and contents or content_ids are\n  // required.\n\n  // The producer of the content viewed event is not yet giving us currency so we have to assume it\n  // is USD.\n\n  // price is already in dollars here, we do not divide by 100\n\n  // This used to incorrectly specify content type as product_group but it is always product, we are\n  // viewing a single product.\n\n  // TODO: this is missing contents, it was not even in the legacy GTM implementation\n\n  // the legacy implementation was passing the property content_sku but this is not a real property\n\n  let contentId;\n  if (event.detail.product_id && event.detail.variant_id) {\n    contentId = `shopify_${event.detail.product_id}_${event.detail.variant_id}`;\n  } else if (event.detail.product_id) {\n    contentId = `shopify_${event.detail.product_id}`;\n  }\n\n  fbq('track', 'ViewContent', {\n    content_category: event.detail.product_type,\n    content_name: event.detail.product_title,\n    content_ids: contentId ? [contentId] : undefined,\n    content_type: 'product',\n    currency: 'USD',\n    value: event.detail.price\n  });\n}\n\nfunction onAddToCart(event: OfirCustomEvents.AddToCartEvent) {\n  if (typeof event.detail !== 'object' || event.detail === null) {\n    return;\n  }\n\n  // Ignore failed adds\n  if (!event.detail.success) {\n    return;\n  }\n\n  for (const item of event.detail.items) {\n    fbq('track', 'AddToCart', {\n      content_category: item.product_type,\n      content_name: item.title,\n      content_type: 'product',\n      content_ids: item.product_type.toLowerCase() === 'simple-bundle' ?\n        [`shopify_${item.product_id}`] :\n        [`shopify_${item.product_id}_${item.variant_id}`],\n      currency: LiquidGlobals.Shop.currency || 'USD',\n      value: item.line_price ? item.line_price / 100 : 0\n    });\n  }\n}\n\n/**\n * Handles form-submit events by sending a CompleteRegistration event to Facebook.\n *\n * @see https://developers.facebook.com/docs/meta-pixel/reference\n */\nfunction onFormSubmit(event: WindowEventMap['form-submit']) {\n  const formType = event.detail.form_type;\n  if (formType) {\n    fbq('track', 'CompleteRegistration', {\n      registration_type: formType,\n      currency: event.detail.currency_code || 'USD'\n    });\n  }\n}\n\n/**\n * When a customer email or phone number is captured during user interaction with the site, store it\n * in local storage for potential use in enhanced matching for Facebook Pixel.\n */\nfunction onIdentityCaptured(event: WindowEventMap['identity-captured']) {\n  const email = event.detail.email;\n  if (email && isValidEmail(email)) {\n    try {\n      localStorage.setItem('meta_email_capture_email', email);\n    } catch (error) {\n      // Ignore localStorage errors\n    }\n  }\n\n  const phone = event.detail.phone;\n  if (phone) {\n    try {\n      localStorage.setItem('meta_attentive_phone', phone);\n    } catch (error) {\n      // ignore\n    }\n  }\n}\n\nfunction isValidEmail(email: string) {\n  // eslint-disable-next-line @stylistic/max-len\n  return /^[\\w!#\\$%&\\'\\*\\+\\/\\=\\?\\^`\\{\\|\\}~\\-]+(:?\\.[\\w!#\\$%&\\'\\*\\+\\/\\=\\?\\^`\\{\\|\\}~\\-]+)*@(?:[a-z0-9](?:[a-z0-9\\-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9\\-]*[a-z0-9])?$/i.test(email);\n}\n\nconst registry = <Record<string, (...args: unknown[]) => void>>{\n  'ofir-view-item': onViewItem,\n  'ofir-add-to-cart': onAddToCart,\n  'form-submit': onFormSubmit,\n  'identity-captured': onIdentityCaptured\n};\n\ncommon.setupRegistry(registry);\n"],"names":["window","__ofir","_window$__ofir","Cart","_window$__ofir2","Checkout","_window$__ofir3","Collection","_window$__ofir4","Customer","_window$__ofir5","GiftCard","_window$__ofir6","Order","_window$__ofir7","Page","_window$__ofir8","Pagination","_window$__ofir9","Product","_window$__ofir0","Request","_window$__ofir1","Scripts","_window$__ofir10","Search","_window$__ofir11","SearchEngineListing","_window$__ofir12","SectionSettings","Shop","_window$__ofir13","_window$__ofir14","Template","_window$__ofir15","Theme","_window$__ofir16","ThemeSettings","registry","event","ofir","queue","listener","type","eventType","addEventListener","setupRegistry","contentId","detail","product_id","variant_id","fbq","content_category","product_type","content_name","product_title","content_ids","undefined","content_type","currency","value","price","success","item","items","title","toLowerCase","line_price","formType","form_type","registration_type","currency_code","email","test","isValidEmail","localStorage","setItem","error","phone"],"sourceRoot":""}