{"version":3,"file":"Fb_pixel.N-MVvpIR.mjs","names":[],"sources":["https:/framerusercontent.com/modules/6Zs9CjkPbKzHjoy8LK08/UlcfEh8799smdhRPoZER/Fb_pixel.js"],"sourcesContent":["/*\n * Framer Commerce\n * Confidential and Proprietary - All Rights Reserved\n * ... [license header omitted for brevity] ...\n */// Utility function to clean Shopify GID to just the numeric ID\nconst cleanShopifyId=gid=>gid?.split(\"/\").pop()||\"\";// Standardized Facebook Pixel AddToCart tracking function\nexport const trackFacebookPixelAddToCart=data=>{if(typeof fbq!==\"function\"){console.warn(\"Facebook Pixel not available\");return;}const{variant,product,quantity=1,currency=\"USD\"}=data;if(!variant||!product){console.warn(\"Missing variant or product data for Facebook Pixel tracking\");return;}const item_id=cleanShopifyId(variant.id);const item_name=product.title||\"\";const item_variant=variant.title||\"\";const price=parseFloat(variant.price?.amount||\"0\");const value=price*quantity;const finalCurrency=variant.price?.currencyCode||currency;// Validate required data\nif(!item_id||!item_name||price<=0){console.warn(\"❌ Skipping Facebook Pixel AddToCart: missing required data\",{item_id,item_name,price,value});return;}const fbqData={content_type:\"product\",content_ids:[item_id],content_name:item_name,content_category:product.productType||\"\",content_brand:product.vendor||\"\",value:parseFloat(value.toFixed(2)),currency:finalCurrency,contents:[{id:item_id,price:parseFloat(price.toFixed(2)),quantity:parseInt(quantity.toString())}]};// console.log('[Facebook Pixel] Firing AddToCart', item_id, item_name);\n// console.log('[Facebook Pixel] AddToCart with data:', fbqData);\n// console.log('[Facebook Pixel] AddToCart timestamp:', new Date().toISOString());\nfbq(\"track\",\"AddToCart\",fbqData,{eventID:\"addtocart_\"+Date.now()});};// Standardized Facebook Pixel InitiateCheckout tracking function\nexport const trackFacebookPixelInitiateCheckout=data=>{if(typeof fbq!==\"function\"){console.warn(\"Facebook Pixel not available\");return;}const{variant,product,quantity=1,currency=\"USD\",value:providedValue,content_ids:providedContentIds,content_name:providedContentName,num_items:providedNumItems}=data;let fbqData={content_type:\"product\",currency:currency};// If we have variant and product data, calculate from them\nif(variant&&product){const item_id=cleanShopifyId(variant.id);const item_name=product.title||\"\";const price=parseFloat(variant.price?.amount||\"0\");const calculatedValue=price*quantity;const finalCurrency=variant.price?.currencyCode||currency;// Validate required data\nif(!item_id||!item_name||price<=0){console.warn(\"❌ Skipping Facebook Pixel InitiateCheckout: missing required data\",{item_id,item_name,price,calculatedValue});return;}fbqData={content_type:\"product\",content_ids:[item_id],content_name:item_name,content_category:product.productType||\"\",content_brand:product.vendor||\"\",value:parseFloat(calculatedValue.toFixed(2)),currency:finalCurrency,num_items:parseInt(quantity.toString())};}else if(providedContentIds&&providedValue!==undefined){// Ensure providedValue is a valid number\nconst numericValue=typeof providedValue===\"number\"?providedValue:parseFloat(providedValue)||0;fbqData={content_type:\"product\",content_ids:providedContentIds,content_name:providedContentName||\"Checkout\",value:parseFloat(numericValue.toFixed(2)),currency:currency,num_items:parseInt((providedNumItems||1).toString())};}else{console.warn(\"❌ Skipping Facebook Pixel InitiateCheckout: insufficient data\",data);return;}// console.log('[Facebook Pixel] Firing InitiateCheckout', fbqData.content_ids?.[0], fbqData.content_name);\n// console.log('[Facebook Pixel] InitiateCheckout with data:', fbqData);\n// console.log('[Facebook Pixel] InitiateCheckout timestamp:', new Date().toISOString());\n// Use sendBeacon if requested, otherwise use regular tracking\nconst eventOptions={eventID:\"initiatecheckout_\"+Date.now()};if(data.useBeacon){fbq(\"track\",\"InitiateCheckout\",fbqData,{...eventOptions,transport:\"beacon\"});}else{fbq(\"track\",\"InitiateCheckout\",fbqData,eventOptions);}};// Standardized Facebook Pixel RemoveFromCart tracking function\nexport const trackFacebookPixelRemoveFromCart=data=>{if(typeof fbq!==\"function\"){console.warn(\"Facebook Pixel not available\");return;}const{lineItem,currency=\"USD\"}=data;if(!lineItem){console.warn(\"Missing lineItem data for Facebook Pixel RemoveFromCart tracking\");return;}const item_id=cleanShopifyId(lineItem.merchandise.id);const item_name=lineItem.merchandise.product?.title||\"\";const item_variant=lineItem.merchandise.title||\"\";const price=parseFloat(lineItem.cost.subtotalAmount.amount||\"0\");const quantity=lineItem.quantity||1;const value=price*quantity;const finalCurrency=lineItem.cost.subtotalAmount.currencyCode||currency;// Validate required data\nif(!item_id||!item_name||price<=0){console.warn(\"❌ Skipping Facebook Pixel RemoveFromCart: missing required data\",{item_id,item_name,price,value,quantity});return;}const fbqData={content_type:\"product\",content_ids:[item_id],content_name:item_name,content_category:lineItem.merchandise.product?.productType||\"\",content_brand:lineItem.merchandise.product?.vendor||\"\",value:parseFloat(value.toFixed(2)),currency:finalCurrency,contents:[{id:item_id,price:parseFloat(price.toFixed(2)),quantity:parseInt(quantity.toString())}]};// console.log('[Facebook Pixel] Firing RemoveFromCart with data:', fbqData);\nfbq(\"track\",\"RemoveFromCart\",fbqData,{eventID:\"removefromcart_\"+Date.now()});};// Standardized Facebook Pixel ViewContent tracking function\nexport const trackFacebookPixelViewContent=data=>{if(typeof fbq!==\"function\"){console.warn(\"Facebook Pixel not available\");return;}const{variant,product,currency=\"USD\"}=data;if(!product){console.warn(\"Missing product data for Facebook Pixel ViewContent tracking\");return;}const item_id=variant?cleanShopifyId(variant.id):cleanShopifyId(product.id);const item_name=product.title||\"\";const item_variant=variant?.title||\"\";const price=variant?parseFloat(variant.price?.amount||\"0\"):parseFloat(product.priceRange?.minVariantPrice?.amount||\"0\");const finalCurrency=variant?.price?.currencyCode||product.priceRange?.minVariantPrice?.currencyCode||currency;// Validate required data\nif(!item_id||!item_name||price<=0){console.warn(\"❌ Skipping Facebook Pixel ViewContent: missing required data\",{item_id,item_name,price});return;}const fbqData={content_type:\"product\",content_ids:[item_id],content_name:item_name,content_category:product.productType||\"\",content_brand:product.vendor||\"\",value:parseFloat(price.toFixed(2)),currency:finalCurrency};// console.log('[Facebook Pixel] Firing ViewContent with data:', fbqData);\nfbq(\"track\",\"ViewContent\",fbqData,{eventID:\"viewcontent_\"+Date.now()});};export default function initializeFacebookPixel(facebookPixelId){!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?n.callMethod.apply(n,arguments):n.queue.push(arguments);};if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version=\"2.0\";n.queue=[];t=b.createElement(e);t.async=!0;t.src=v;// Add onload and onerror event handlers\nt.onload=()=>{if(typeof fbq!==\"undefined\"){fbq(\"init\",facebookPixelId);fbq(\"track\",\"PageView\");}else{// Handle case where fbq is not defined\n}};t.onerror=()=>{// Handle Facebook Pixel script load failure\n};s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s);}(window,document,\"script\",\"https://connect.facebook.net/en_US/fbevents.js\");}\nexport const __FramerMetadata__ = {\"exports\":{\"trackFacebookPixelRemoveFromCart\":{\"type\":\"variable\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"trackFacebookPixelInitiateCheckout\":{\"type\":\"variable\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"trackFacebookPixelAddToCart\":{\"type\":\"variable\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"trackFacebookPixelViewContent\":{\"type\":\"variable\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"default\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./Fb_pixel.map"],"mappings":"uHAKM,EAAe,GAAK,GAAK,MAAM,GAAG,CAAC,CAAC,IAAI,GAAG,GACpC,EAA4B,GAAM,CAAC,GAAG,OAAO,KAAM,WAAW,CAAC,QAAQ,KAAK,8BAA8B,EAAE,MAAO,CAAC,GAAK,CAAC,UAAQ,UAAQ,WAAS,EAAE,WAAS,OAAO,EAAK,GAAG,CAAC,GAAS,CAAC,EAAQ,CAAC,QAAQ,KAAK,6DAA6D,EAAE,MAAO,CAAC,IAAM,EAAQ,EAAe,EAAQ,EAAE,EAAQ,EAAU,EAAQ,OAAO,GAAsB,EAAQ,MAAU,IAAM,EAAM,WAAW,EAAQ,OAAO,QAAQ,GAAG,EAAQ,EAAM,EAAM,EA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