facebook.js
1 lines
| 1 | import{maybeConvertAmount}from"../../functions/currency";const isTrackingDisabled=()=>{var n;return!(null===window||void 0===window?void 0:window.fbq)||!1===(null===(n=null===window||void 0===window?void 0:window.scData)||void 0===n?void 0:n.facebook_tracking_enabled)};window.addEventListener("scSearched",(function(n){var i;if(isTrackingDisabled())return;const o=n.detail;window.fbq("track","Search",{search_string:o.searchString,content_ids:o.searchResultIds,...(null===(i=null==o?void 0:o.searchCollections)||void 0===i?void 0:i.length)?{content_category:o.searchCollections.join(",")}:{}})})),window.addEventListener("scProductViewed",(function(n){var i,o,t,e,d,c;if(isTrackingDisabled())return;const l=n.detail;window.fbq("track","ViewContent",{content_ids:[l.id],content_category:null===(o=null===(i=null==l?void 0:l.product_collections)||void 0===i?void 0:i.data)||void 0===o?void 0:o.map((n=>n.name)).join(", "),content_name:(null==l?void 0:l.name)+((null===(t=null==l?void 0:l.variant_options)||void 0===t?void 0:t.length)?` - ${null==l?void 0:l.variant_options.join(" / ")}`:""),content_type:"product",contents:[{id:l.id,quantity:1}],currency:null===(e=null==l?void 0:l.price)||void 0===e?void 0:e.currency,value:maybeConvertAmount((null===(d=l.price)||void 0===d?void 0:d.amount)||0,(null===(c=l.price)||void 0===c?void 0:c.currency)||"USD")})})); |