1/* 2* 3* Dynamic Ads + Pixel 4* 5* @author BusinessTech.fr - https://www.businesstech.fr 6* @copyright Business Tech - https://www.businesstech.fr 7* @license Commercial 8* 9* ____ _______ 10* | _ \ |__ __| 11* | |_) | | | 12* | _ < | | 13* | |_) | | | 14* |____/ |_| 15* 16*/ 17 18document.addEventListener('DOMContentLoaded', function () { 19 20 if (btPixel.pixel_id != "" && btPixel.activate_pixel == 1) { 21 // Init the pixel code 22 !(function (f, b, e, v, n, t, s) { 23 if (f.fbq) return; 24 n = f.fbq = function () { 25 n.callMethod ? n.callMethod.apply(n, arguments) : n.queue.push(arguments); 26 }; 27 if (!f._fbq) f._fbq = n; 28 n.push = n; 29 n.loaded = !0; 30 n.version = "2.0"; 31 n.queue = []; 32 t = b.createElement(e); 33 t.async = !0; 34 t.src = v; 35 s = b.getElementsByTagName(e)[0]; 36 s.parentNode.insertBefore(t, s); 37 })(window, document, "script", "https://connect.facebook.net/en_US/fbevents.js"); 38 39 fbq('set', 'autoConfig', false, btPixel.pixel_id); 40 41 if (btPixel.bUseConsent == true) { 42 if (btPixel.bUseAxeption == 1) { 43 void 0 === window._axcb && (window._axcb = []); 44 window._axcb.push(function (axeptio) { 45 axeptio.on("cookies:complete", function (choices) { 46 if (choices.facebook_pixel) { 47 $.ajax({ 48 type: "POST", 49 url: btPixel.ajaxUrl, 50 dataType: "json", 51 data: { 52 ajax: 1, 53 action: "updateConsent", 54 token: btPixel.token, 55 }, 56 success: function (jsonData, textStatus, jqXHR) { 57 fbq("init", btPixel.pixel_id); 58 fbq("track", "PageView", {}, { 'eventID': btPixel.eventId }); 59 fbq("consent", "grant"); 60 }, 61 }); 62 } 63 }); 64 }); 65 66 } else if (btPixel.bUseAxeption == 0) { 67 if (btPixel.bConsentHtmlElement != "") { 68 $(btPixel.bConsentHtmlElement).on("click", function (event) { 69 $.ajax({ 70 type: "POST", 71 url: btPixel.ajaxUrl, 72 dataType: "json", 73 data: { 74 ajax: 1, 75 action: "updateConsent", 76 token: btPixel.token, 77 }, 78 success: function (jsonData, textStatus, jqXHR) { 79 fbq("init", btPixel.pixel_id); 80 fbq("track", "PageView", {}, { 'eventID': btPixel.eventId }); 81 fbq("consent", "grant"); 82 }, 83 }); 84 }); 85 86 if (btPixel.bConsentHtmlElementSecond != "") { 87 $(btPixel.bConsentHtmlElementSecond).on("click", function (event) { 88 $.ajax({ 89 type: "POST", 90 url: btPixel.ajaxUrl, 91 dataType: "json", 92 data: { 93 ajax: 1, 94 action: "updateConsent", 95 token: btPixel.token, 96 }, 97 success: function (jsonData, textStatus, jqXHR) { 98 fbq("init", btPixel.pixel_id); 99 fbq("track", "PageView", {}, { 'eventID': btPixel.eventId }); 100 fbq("consent", "grant"); 101 }, 102 }); 103 }); 104 } 105 } 106 } 107 108 // Use the consent level from ACB 109 if (btPixel.iConsentConsentLvl == 0) { 110 fbq("consent", "revoke"); 111 } else if (btPixel.iConsentConsentLvl == 1) { 112 fbq("consent", "revoke"); 113 } else if (btPixel.iConsentConsentLvl == 2 || btPixel.iConsentConsentLvl == 3) { 114 if (btPixel.advancedMatchingData == false || btPixel.useAdvancedMatching == false) { 115 fbq("init", btPixel.pixel_id, { 116 external_id: btPixel.external_id, 117 }); 118 fbq("consent", "grant"); 119 } else { 120 fbq("init", btPixel.pixel_id, { 121 external_id: btPixel.external_id, 122 em: btPixel.advancedMatchingData.em, 123 fn: btPixel.advancedMatchingData.fn, 124 ln: btPixel.advancedMatchingData.ln, 125 }); 126 fbq("consent", "grant"); 127 } 128 129 fbq("track", "PageView", {}, { 'eventID': btPixel.eventId }); 130 fbq("consent", "grant"); 131 } 132 133 } else { 134 if (btPixel.advancedMatchingData == false || btPixel.useAdvancedMatching == false) { 135 fbq("init", btPixel.pixel_id, { 136 external_id: btPixel.external_id, 137 }); 138 } else { 139 fbq("init", btPixel.pixel_id, { 140 external_id: btPixel.external_id, 141 em: btPixel.advancedMatchingData.em, 142 fn: btPixel.advancedMatchingData.fn, 143 ln: btPixel.advancedMatchingData.ln, 144 }); 145 } 146 147 fbq("track", "PageView", {}, { 'eventID': btPixel.eventId }); 148 149 // Allow third-party modules to disable Pixel 150 doNotConsentToPixel = false;
151 fbq('consent', !!window.doNotConsentToPixel ? 'revoke' : 'grant'); 152 } 153 154 // Use Ajax call to send API event to make better TTFB 155 if (btPixel.useConversionApi == 1) { 156 $.ajax({ 157 type: "POST", 158 url: btPixel.ajaxUrl, 159 dataType: "json", 160 data: { 161 ajax: 1, 162 action: "sendApiData", 163 token: btPixel.token, 164 tagContent: btPixel.tagContentApi, 165 tagContentCheck: btPixel.tagContentApiCheck, 166 useApiForPageView: btPixel.useApiForPageView, 167 apiToken: btPixel.ApiToken, 168 pagetype: btPixel.currentPage, 169 id_order: btPixel.id_order, 170 } 171 }); 172 } 173 174 175 // Check if necessary data is available 176 if (btPixel.tagContent && (btPixel.tagContent.aTrackingType || btPixel.tagContent.aDynTags.content_name || btPixel.tagContent.aDynTags.content_ids)) { 177 178 const trackingType = btPixel.tagContent.aTrackingType?.value; 179 const dynTags = btPixel.tagContent.aDynTags; 180 181 // Function to track events 182 const trackEvent = (eventName, params) => { 183 fbq(eventName === "ViewCategory" || eventName === "ViewContentHomepage" ? "trackCustom" : "track", 184 eventName, 185 params, 186 { 'eventID': btPixel.eventId } 187 ); 188 }; 189 190 // Common parameters for events 191 const commonParams = { 192 content_name: dynTags.content_name?.value, 193 content_category: dynTags.content_category?.value, 194 content_type: dynTags.content_type?.value, 195 }; 196 197 // Handle different event types 198 switch (trackingType) { 199 case "ViewContent": 200 trackEvent("ViewContent", { 201 ...commonParams, 202 content_ids: dynTags.content_ids?.value, 203 value: dynTags.value?.value, 204 currency: dynTags.currency?.value, 205 }); 206 break; 207 208 case "ViewCategory": 209 if (dynTags.content_ids) { 210 trackEvent("ViewCategory", { 211 ...commonParams, 212 content_ids: dynTags.content_ids.value, 213 }); 214 } else if (dynTags.content_name) { 215 trackEvent("ViewCategory", commonParams); 216 } 217 break; 218 219 case "ViewContentHomepage": 220 trackEvent("ViewContentHomepage", dynTags.content_ids?.value 221 ? { ...commonParams, content_ids: dynTags.content_ids.value } 222 : commonParams 223 ); 224 break; 225 226 case "AddToCart": 227 case "Purchase": 228 trackEvent(trackingType, { 229 content_ids: dynTags.content_ids?.value, 230 content_type: dynTags.content_type?.value, 231 value: dynTags.value?.value, 232 currency: dynTags.currency?.value, 233 }); 234 break; 235 236 case "Contact": 237 trackEvent("Contact", {}); 238 break; 239 240 case "Search": 241 trackEvent("Search", { 242 content_ids: dynTags.content_ids?.value, 243 content_type: dynTags.content_type?.value, 244 query: dynTags.search_string?.value, 245 }); 246 break; 247 248 case "InitiateCheckout": 249 trackEvent("InitiateCheckout", {}); 250 break; 251 } 252 253 // Add to Wishlist event 254 $(btPixel.btnAddToWishlist).on("click", function () {
255 trackEvent("AddToWishlist", { content_type: 'product' }); 256 }); 257 258 // Add Payment Info event 259 $('.ps-shown-by-js').on("click", function () { 260 trackEvent("AddPaymentInfo", {}); 261 262 // Send API event if Conversion API is enabled 263 if (btPixel.useConversionApi == 1) { 264 $.ajax({ 265 type: "POST", 266 url: btPixel.ajaxUrl, 267 dataType: "json", 268 data: { 269 ajax: 1, 270 action: "sendPaymentInfoToApi", 271 token: btPixel.token, 272 eventId: btPixel.eventId, 273 } 274 }); 275 } 276 }); 277 } 278 279 if (typeof prestashop !== 'undefined') { 280 prestashop.on( 281 'updateCart', 282 function (event) { 283 if (event && event.reason && event.reason.linkAction == "add-to-cart") { 284 //Check the variable for ipa and ip 285 var idProduct = 0; 286 var idProductAttribute = 0; 287 288 if (typeof event.reason.idProductAttribute !== "undefined") { 289 idProductAttribute = event.reason.idProductAttribute; 290 } else if (typeof event.resp.id_product_attribute !== "undefined") { 291 idProductAttribute = event.resp.id_product_attribute; 292 } 293 294 if (typeof event.reason.idProduct !== "undefined") { 295 idProduct = event.reason.idProduct; 296 } else if (typeof event.resp.id_product !== "undefined") { 297 idProduct = event.resp.id_product; 298 } 299 300 $.ajax({ 301 type: "POST", 302 url: btPixel.ajaxUrl, 303 dataType: "json", 304 data: { 305 ajax: 1, 306 action: "addToCart", 307 id_product_attribute: idProductAttribute, 308 id_product: idProduct, 309 token: btPixel.token, 310 }, 311 success: function (jsonData, textStatus, jqXHR) { 312 fbq('set', 'autoConfig', false, btPixel.pixel_id); 313 fbq("track", "AddToCart", { 314 content_ids: jsonData.content_ids, 315 content_type: 'product', 316 value: jsonData.value, 317 currency: jsonData.currency, 318 }, 319 { 'eventID': btPixel.eventId }); 320 }, 321 }); 322 } 323 } 324 ); 325 326 // Handle case for combination update 327 prestashop.on( 328 'updatedProduct', 329 function (event) { 330 if (event) { 331 $.ajax({ 332 type: "POST", 333 url: btPixel.ajaxUrl, 334 dataType: "json", 335 data: { 336 ajax: 1, 337 action: "updateCombination", 338 id_product_attribute: event.id_product_attribute, 339 id_product: $('input[name="id_product"').val(), 340 token: btPixel.token, 341 }, 342 success: function (jsonData, textStatus, jqXHR) { 343 fbq('set', 'autoConfig', false, btPixel.pixel_id); 344 fbq("track", "ViewContent", { 345 content_name: jsonData.content_name, 346 content_category: jsonData.content_category, 347 content_ids: jsonData.content_id, 348 content_type: 'product', 349 value: jsonData.value, 350 currency: jsonData.currency, 351 }); 352 }, 353 }); 354 } 355 } 356 ); 357 } 358 } 359});
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.