1/** 2 * @file 3 * facebook_pixel.js 4 * 5 * Defines the behavior of the facebook pixel module. 6 */ 7 8(function (Drupal, drupalSettings, once) { 9 10 'use strict'; 11 12 function initTracking() { 13 var facebook_pixel_id = drupalSettings.facebook_pixel.facebook_id; 14 15 // Define Drupal.facebook_pixel.fb_disable as a dynamic condition to 16 // disable FB Pixel at runtime. 17 // This is helpful for GDPR compliance module integration 18 // and works even with static caching mechanisms like boost module. 19 Drupal.facebook_pixel = (typeof Drupal.facebook_pixel !== "undefined") ? Drupal.facebook_pixel : {}; 20 Drupal.facebook_pixel.fb_disable = false; 21 22 // Define Opt-out conditions check 23 if (drupalSettings.facebook_pixel.fb_disable_advanced) { 24 // Facebook Pixel Opt-Out Code 25 window.fbOptout = function (reload = 0) { 26 reload = (typeof reload !== 'undefined') ? reload : 0; 27 var optoutWindowDisableKey = 'fb-disable'; 28 document.cookie = optoutWindowDisableKey + '=true; expires=Thu, 31 Dec 2999 23:59:59 UTC; path=/'; 29 window[optoutWindowDisableKey] = true; 30 if (reload) { 31 location.reload(); 32 } 33 }; 34 if (document.cookie.indexOf('fb-disable=true') > -1) { 35 window['fb-disable'] = true; 36 } 37 // End Facebook Pixel Opt-Out Code 38 Drupal.facebook_pixel.fb_disable = Drupal.facebook_pixel.fb_disable || window['fb-disable'] == true; 39 } 40 41 // Define eu_cookie_compliance conditions check (https://www.drupal.org/project/eu_cookie_compliance) 42 if (drupalSettings.facebook_pixel.eu_cookie_compliance) { 43 if (typeof Drupal.eu_cookie_compliance === "undefined") { 44 console.warn("facebook_pixel: facebook_pixel eu_cookie_compliance integration option is enabled, but eu_cookie_compliance javascripts seem to be loaded after facebook_pixel, which may break functionality."); 45 } 46 var eccHasAgreed = (typeof Drupal.eu_cookie_compliance !== "undefined" && Drupal.eu_cookie_compliance.hasAgreed()); 47 Drupal.facebook_pixel.fb_disable = Drupal.facebook_pixel.fb_disable || !eccHasAgreed; 48 } 49 50 // Define Do-not-track conditions check (see https://www.w3.org/TR/tracking-dnt/) 51 if (drupalSettings.facebook_pixel.donottrack) { 52 var DNT = (typeof navigator.doNotTrack !== "undefined" && (navigator.doNotTrack === "yes" || navigator.doNotTrack == 1)) || (typeof navigator.msDoNotTrack !== "undefined" && navigator.msDoNotTrack == 1) || (typeof window.doNotTrack !== "undefined" && window.doNotTrack == 1); 53 // If eccHasAgreed is true, it overrides DNT because eu_cookie_compliance contains a setting for opt-in with DNT: 54 // "Automatic. Respect the DNT (Do not track) setting in the browser, if present. Uses opt-in when DNT is 1 or not set, and consent by default when DNT is 0." 55 Drupal.facebook_pixel.fb_disable = Drupal.facebook_pixel.fb_disable || (DNT && (typeof eccHasAgreed == "undefined" || !eccHasAgreed)); 56 } 57 58 if (!Drupal.facebook_pixel.fb_disable) { 59 let elements = once('facebook_pixel_pageload_tracking', 'body'); 60 elements.forEach(function () { 61 !function (f,b,e,v,n,t,s) { 62 if(f.fbq) { return; 63 }
63n = f.fbq = function () {n.callMethod ? 64 n.callMethod.apply(n,arguments):n.queue.push(arguments)}; 65 if(!f._fbq) { f._fbq = n; 66 }n.push = n;n.loaded = !0;n.version = '2.0'; 67 n.queue = [];t = b.createElement(e);t.async = !0; 68 t.src = v;s = b.getElementsByTagName(e)[0]; 69 s.parentNode.insertBefore(t,s)}(window, document,'script', 70 'https://connect.facebook.net/en_US/fbevents.js'); 71 fbq('init', facebook_pixel_id); 72 fbq('track', 'PageView'); 73 74 drupalSettings.facebook_pixel.events.forEach(function (event) { 75 fbq("track", event['event'], JSON.parse(event['data'])); 76 }); 77 }); 78 } 79 } 80 81 Drupal.behaviors.facebook_pixel = { 82 attach(context) { 83 let elements = once('facebook_pixel_behavior', 'body') 84 elements.forEach(function () { 85 initTracking(); 86 }); 87 88 document.addEventListener('eu_cookie_compliance.changeStatus', function() { 89 initTracking(); 90 }); 91 }, 92 }; 93 94}(Drupal, drupalSettings, once));
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.