1"use strict"; 2var fdEvents = (function () { 3 4 var useEventPrefix = Utils.dealerId == 43; 5 var eventPrefix = useEventPrefix ? 'fdn_' : ''; 6 7 const ecomEvents = { 8 view_item: "view_item", 9 view_item_list: "view_item_list", 10 select_item: "select_item", 11 add_to_cart: "add_to_cart", 12 add_to_wishlist: "add_to_wishlist", 13 view_cart: "view_cart", 14 remove_from_cart: "remove_from_cart", 15 begin_checkout: "begin_checkout", 16 add_shipping_info: "add_shipping_info", 17 add_payment_info: "add_payment_info", 18 purchase: "purchase", 19 refund: "refund", 20 view_promotion: "view_promotion", 21 select_promotion: "select_promotion", 22 view_content: "view_content", 23 interact_content: "interact_content" 24 } 25 26 const pastEvents = []; 27 28 const subscriptions = new Map(); 29 30 const subscribe = function (eventName, callback) { 31 32 if (eventName && typeof callback === 'function') { 33 let callbackCollection = subscriptions.get(eventName); 34 if (!callbackCollection) { 35 callbackCollection = []; 36 } 37 38 callbackCollection.push(callback); 39 subscriptions.set(eventName, callbackCollection); 40 41 const toReplay = pastEvents.filter(e => e.eventName === eventName); 42 toReplay.forEach((e) => executeCallback(callback, e.data)); 43 } 44 45 } 46 47 const publish = function (eventName, data) { 48 49 console.log("published event: " + eventName, data); 50 51 if (!eventName) return; 52 53 if (typeof data === 'undefined') data = {}; 54 55 if (typeof data === 'string') { 56 try { 57 data = JSON.parse(data); 58 } 59 catch { 60 console.warn("could not convert event data to an object") 61 return; 62 } 63 } 64 65 if (typeof data !== 'object') { 66 console.warn('event data is not an object'); 67 return; 68 } 69 70 if (dataLayer) { 71 72 var user = CurrentUser.id === 0 ? null : { 73 id: CurrentUser.id, 74 email: CurrentUser.email, 75 phone: CurrentUser.phone, 76 address: { 77 first_name: CurrentUser.firstName, 78 last_name: CurrentUser.lastName, 79 street_address: CurrentUser.streetAddress, 80 city: CurrentUser.city, 81 region: CurrentUser.state, 82 country: CurrentUser.country 83 } 84 }; 85 86 try { 87 var eventNameToPush = eventPrefix + eventName; 88 if (eventName in ecomEvents) { 89 dataLayer.push({ ecommerce: null }); 90 dataLayer.push({ 'event': eventNameToPush, ecommerce: { ...data }, user }); 91 } 92 else { 93 dataLayer.push({ 'event': eventNameToPush, ...data, user }); 94 } 95 96 } 97 catch { 98 console.warn('could not push data to dataLayer'); 99 } 100 } 101 102 if (!('send_to' in data)) 103 data.send_to = 'all'; 104 105 gtag('event', eventName, data); 106 107 var eventCollection = subscriptions.get(eventName); 108 109 if (eventCollection) { 110 for (let i = 0; i < eventCollection.length; i++) { 111 const callback = eventCollection[i]; 112 //console.log('eventcallback', callback.name, eventName); 113 executeCallback(callback, data); 114 } 115 } 116 117 pastEvents.push({ data }); 118 } 119 120 function executeCallback(callback, data) { 121 if (typeof callback === 'function') { 122 try { 123 callback(data); 124 } 125 catch (error) { 126 console.warn(error); 127 } 128 } 129 } 130 131 return { 132 subscribe, 133 publish 134 } 135 136})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.