PageSourceSearch

https://masonnatural.pe/wp-content/cache/wpfc-minified/e6es9f19/4bfgw.js

js masonnatural.pe collected 2026-09-25 11:50:13 UTC 11,186 bytes, 392 lines download raw bytes

1// source --> https://masonnatural.pe/wp-content/plugins/official-facebook-pixel/core/../js/facebook_signal.js 
2window.FacebookSignal = window.FacebookSignal || {
3  _held: false,
4  _releasing: false,
5  _pixelInitialized: false,
6  _pixelId: null,
7  _pixelUserInfo: {},
8  _pixelOptions: {},
9  _pendingPixelEvents: [],
10  _queue: [],
11  _config: {},
12  _seenEventIds: {},
13  _fbclid: (function () {
14    try {
15      var match = window.location.search.match(/[?&]fbclid=([^&]*)/);
16      return match ? decodeURIComponent(match[1]) : null;
17    } catch (e) {
18      return null;
19    }
20  })(),
21
22  _readCookie: function (name) {
23    try {
24      var pairs = (document.cookie || '').split(';');
25      for (var i = 0; i < pairs.length; i++) {
26        var pair = pairs[i].replace(/^\s+/, '');
27        if (pair.indexOf(name + '=') === 0) {
28          return decodeURIComponent(pair.substring(name.length + 1));
29        }
30      }
31    } catch (e) {}
32    return null;
33  },
34
35  init: function (config) {
36    this._config = config || {};
37    this._attribution = this._config.attribution || {};
38
39    // Read cookie directly so cached pages resolve the correct held/active
40    // state even when PHP rendered held: false.
41    var cookieState = this._readCookie('wc_facebook_signals_state');
42    this._held = cookieState ? cookieState === 'held' : !!this._config.held;
43
44    // Sync consent immediately so fbevents.js obeys the current state.
45    if (typeof fbq === 'function') {
46      fbq('consent', this._held ? 'revoke' : 'grant');
47    }
48
49    try {
50      var raw = window.sessionStorage.getItem('fbpix_seen_event_ids');
51      this._seenEventIds = raw ? JSON.parse(raw) : {};
52    } catch (e) {
53      this._seenEventIds = this._seenEventIds || {};
54    }
55  },
56
57  initPixel: function (pixelId, userInfo, options) {
58    this._pixelId = pixelId;
59    this._pixelUserInfo =
60      userInfo && typeof userInfo === 'object' && !Array.isArray(userInfo)
61        ? userInfo
62        : {};
63    this._pixelOptions = options || {};
64    if (!this._held) {
65      this._runPixelInit();
66    }
67  },
68
69  _runPixelInit: function () {
70    if (this._pixelInitialized || !this._pixelId || typeof fbq !== 'function') {
71      return;
72    }
73    if (this._pixelOptions && this._pixelOptions.includeCapiIntegration) {
74      var url = window.location.origin + '?ob=open-bridge';
75      fbq('set', 'openbridge', this._pixelId, url);
76    }
77
78    if (this._config.capig === '1') {
79      fbq('optinMetaEnabledCapi', this._pixelId);
80    }
81
82    fbq('init', this._pixelId, this._pixelUserInfo, this._pixelOptions);
83
84    this._pixelInitialized = true;
85    this._flushPendingPixelEvents();
86  },
87
88  _flushPendingPixelEvents: function () {
89    var pending = this._pendingPixelEvents;
90    this._pendingPixelEvents = [];
91    for (var i = 0; i < pending.length; i++) {
92      var ev = pending[i];
93      this._firePixelEvent(ev.name, ev.params, ev.method, ev.eventId);
94    }
95  },
96
97  _fireOrQueuePixelEvent: function (name, params, method, eventId) {
98    if (!this._pixelInitialized) {
99      this._pendingPixelEvents.push({
100        name: name,
101        params: params || {},
102        method: method || 'track',
103        eventId: eventId || null,
104      });
105      return;
106    }
107    this._firePixelEvent(name, params || {}, method || 'track', eventId || null);
108  },
109
110  _firePixelEvent: function (name, params, method, eventId) {
111    method = method || 'track';
112    if (eventId) {
113      fbq(method, name, params || {}, { eventID: eventId });
114    } else {
115      fbq(method, name, params || {});
116    }
117  },
118
119  _syncCookie: function (name, serverValue, domain) {
120    if (!serverValue) {
121      return;
122    }
123    var encoded = encodeURIComponent(serverValue);
124    var match = document.cookie.match(
125      new RegExp('(?:^|;\\s*)' + name + '=([^;]*)'),
126    );
127    var current = match ? match[1] : null;
128    if (current && current !== encoded) {
129      var cookie =
130        name + '=' + encoded + ';path=/;max-age=7776000;SameSite=Lax';
131      if (domain) {
132        cookie += ';domain=' + domain;
133      }
134      document.cookie = cookie;
135    }
136  },
137
138  queueEvent: function (eventData) {
139    if (!eventData || !eventData.event_name) {
140      return;
141    }
142
143    if (eventData.event_id && this._seenEventIds[eventData.event_id]) {
144      return;
145    }
146
147    eventData.event_time =
148      eventData.event_time || Math.floor(Date.now() / 1000);
149    eventData.event_source_url =
150      eventData.event_source_url || window.location.href;
151    this._queue.push(eventData);
152
153    if (eventData.event_id) {
154      this._seenEventIds[eventData.event_id] = 1;
155      try {
156        window.sessionStorage.setItem(
157          'fbpix_seen_event_ids',
158          JSON.stringify(this._seenEventIds),
159        );
160      } catch (e) {}
161    }
162  },
163
164  trackEvent: function (name, params, userData, method, eventId) {
165    method = method || 'track';
166    eventId = eventId || (params && params.eventID) || null;
167
168    if (this._held) {
169      this.queueEvent({
170        event_name: name,
171        custom_data: params || {},
172        event_id: eventId,
173        event_time: Math.floor(Date.now() / 1000),
174        method: method,
175      });
176    } else {
177      this._fireOrQueuePixelEvent(name, params || {}, method, eventId);
178    }
179  },
180
181  hold: function () {
182    this._held = true;
183    fbq('consent', 'revoke');
184  },
185
186  release: function () {
187    var self = this;
188
189    if (!self._held || self._releasing || !self._config.ajaxUrl) {
190      return Promise.resolve({ success: true, data: { sent_count: 0 } });
191    }
192
193    self._releasing = true;
194
195    return new Promise(function (resolve, reject) {
196      var xhr = new XMLHttpRequest();
197      var url =
198        self._config.ajaxUrl +
199        (self._config.ajaxUrl.indexOf('?') === -1 ? '?' : '&') +
200        'action=' +
201        encodeURIComponent(self._config.releaseAction);
202
203      xhr.open('POST', url, true);
204      xhr.setRequestHeader('Content-Type', 'application/json');
205      xhr.onload = function () {
206        if (xhr.status < 200 || xhr.status >= 300) {
207          self._releasing = false;
208          reject(new Error('Release AJAX failed: ' + xhr.status));
209          return;
210        }
211
212        try {
213          var response = JSON.parse(xhr.responseText);
214          self._handleReleaseResponse(response.data || {});
215          self._releasing = false;
216          resolve(response);
217        } catch (error) {
218          self._releasing = false;
219          reject(error);
220        }
221      };
222      xhr.onerror = function () {
223        self._releasing = false;
224        reject(new Error('Network error'));
225      };
226      var attribution = self._config.attribution || {};
227      xhr.send(
228        JSON.stringify({
229          events: self._queue,
230          fbclid: self._fbclid,
231          fbp: self._readCookie('_fbp') || attribution.fbp || null,
232          fbc: self._readCookie('_fbc') || attribution.fbc || null,
233        }),
234      );
235    });
236  },
237
238  _handleReleaseResponse: function (data) {
239    var attr = this._config.attribution || {};
240    var fbpValue = data.fbp || attr.fbp;
241    var fbcValue = data.fbc || attr.fbc;
242
243    if (fbpValue) {
244      var fbpCookie =
245        '_fbp=' + encodeURIComponent(fbpValue) + ';path=/;max-age=7776000;SameSite=Lax';
246      if (attr.fbpDomain) {
247        fbpCookie += ';domain=' + attr.fbpDomain;
248      }
249      document.cookie = fbpCookie;
250    }
251
252    if (fbcValue) {
253      var fbcCookie =
254        '_fbc=' + encodeURIComponent(fbcValue) + ';path=/;max-age=7776000;SameSite=Lax';
255      if (attr.fbcDomain) {
256        fbcCookie += ';domain=' + attr.fbcDomain;
257      }
258      document.cookie = fbcCookie;
259    }
260
261    // Update user_info with fresh AAM data from the release response, then
262    // run (or re-run) fbq('init') so the pixel has correct user_info.
263    if (
264      data.user_info &&
265      typeof data.user_info === 'object' &&
266      !Array.isArray(data.user_info)
267    ) {
268      this._pixelUserInfo = data.user_info;
269    }
270    this._pixelInitialized = false;
271    this._runPixelInit();
272
273    fbq('consent', 'grant');
274
275    for (var i = 0; i < this._queue.length; i++) {
276      var queuedEvent = this._queue[i];
277      var customData = queuedEvent.custom_data || {};
278      var trackMethod = queuedEvent.method || (queuedEvent.is_custom ? 'trackCustom' : 'track');
279      if (queuedEvent.event_id) {
280        fbq(trackMethod, queuedEvent.event_name, customData, {
281          eventID: queuedEvent.event_id,
282        });
283      } else {
284        fbq(trackMethod, queuedEvent.event_name, customData);
285      }
286    }
287
288    this._queue = [];
289    this._held = false;
290    this._releasing = false;
291  },
292};
293
294window.fbwcsignal = window.fbwcsignal || {};
295(function (api) {
296  var signalConfig = window.facebookSignalConfig || {};
297  var cookieName = signalConfig.cookieName || '';
298  var ajaxUrl = signalConfig.ajaxUrl || '';
299  var signalsAction = signalConfig.signalsAction || '';
300  var signalsNonce = signalConfig.signalsNonce || '';
301
302  function setCookie(value) {
303    var expires = new Date();
304    expires.setTime(expires.getTime() + 365 * 24 * 60 * 60 * 1000);
305    document.cookie =
306      cookieName +
307      '=' +
308      encodeURIComponent(value) +
309      ';expires=' +
310      expires.toUTCString() +
311      ';path=/;SameSite=Lax';
312  }
313
314  function getCookie() {
315    var match = document.cookie.match(
316      new RegExp('(?:^|;\\s*)' + cookieName + '=([^;]*)'),
317    );
318    return match ? decodeURIComponent(match[1]) : null;
319  }
320
321  function updateState(state) {
322    var normalizedState = state === 'active' ? 'active' : 'held';
323    setCookie(normalizedState);
324
325    return new Promise(function (resolve, reject) {
326      var xhr = new XMLHttpRequest();
327      xhr.open('POST', ajaxUrl, true);
328      xhr.setRequestHeader(
329        'Content-Type',
330        'application/x-www-form-urlencoded; charset=UTF-8',
331      );
332      xhr.onload = function () {
333        if (xhr.status < 200 || xhr.status >= 300) {
334          reject(new Error('Signals AJAX failed: ' + xhr.status));
335          return;
336        }
337
338        try {
339          var response = JSON.parse(xhr.responseText);
340          if (normalizedState === 'held') {
341            window.FacebookSignal.hold();
342            resolve(response);
343            return;
344          }
345
346          if (window.FacebookSignal && window.FacebookSignal._held) {
347            window.FacebookSignal.release().then(
348              function () {
349                resolve(response);
350              },
351              function (error) {
352                reject(error);
353              },
354            );
355            return;
356          }
357
358          resolve(response);
359        } catch (error) {
360          reject(error);
361        }
362      };
363      xhr.onerror = function () {
364        reject(new Error('Network error'));
365      };
366      xhr.send(
367        'action=' +
368          encodeURIComponent(signalsAction) +
369          '&security=' +
370          encodeURIComponent(signalsNonce) +
371          '&state=' +
372          encodeURIComponent(normalizedState),
373      );
374    });
375  }
376
377  api.hold = function () {
378    return updateState('held');
379  };
380
381  api.release = function () {
382    return updateState('active');
383  };
384
385  api.getState = function () {
386    var value = getCookie();
387    if (value === 'active' || value === 'held') {
388      return value;
389    }
390    return null;
391  };
392})(window.fbwcsignal);

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.