PageSourceSearch

https://bitwip.ai/js/analytics-bootstrap.js

js bitwip.ai collected 2026-10-05 13:29:29 UTC 2,685 bytes, 69 lines download raw bytes

1/**
2 * Bootstrap analytics Bitwip IA - site public
3 *
4 * Rôle :
5 *   1. Initialiser dataLayer
6 *   2. Charger GTM container (le tag Sirdata CMP gère Consent Mode v2,
7 *      le tag Google Tag gère GA4 + linker cross-domain)
8 *   3. Exposer les helpers globaux bwTrack() et bwOpenCookieSettings()
9 *
10 * IMPORTANT : on ne touche PAS à gtag('consent', 'default', ...) ici — c'est
11 * le tag "ABconsent (Sirdata CMP)" dans GTM qui s'en charge via le trigger
12 * "Consent Initialization - All Pages". Appeler setDefaultConsentState deux
13 * fois provoque un échec du tag Sirdata.
14 *
15 * Ce fichier est inliné via <script src="/js/analytics-bootstrap.js"> dans le <head>,
16 * AVANT tout autre script. Jamais en defer.
17 *
18 * Source de vérité : doc/interne/analytics/plan-taggage.md
19 */
20(function () {
21  'use strict';
22
23  var config = window.BW_ANALYTICS_CONFIG;
24  if (!config) {
25    console.warn('[bw-analytics] BW_ANALYTICS_CONFIG manquant, analytics désactivé');
26    return;
27  }
28
29  // 1. dataLayer
30  window.dataLayer = window.dataLayer || [];
31  function gtag() { window.dataLayer.push(arguments); }
32  window.gtag = gtag;
33
34  // 2. Charger GTM container (GTM gère Sirdata CMP + GA4 + pixels via l'UI)
35  (function (w, d, s, l, i) {
36    w[l] = w[l] || [];
37    w[l].push({ 'gtm.start': new Date().getTime(), event: 'gtm.js' });
38    var f = d.getElementsByTagName(s)[0];
39    var j = d.createElement(s);
40    var dl = l !== 'dataLayer' ? '&l=' + l : '';
41    j.async = true;
42    j.src = 'https://www.googletagmanager.com/gtm.js?id=' + i + dl;
43    f.parentNode.insertBefore(j, f);
44  })(window, document, 'script', 'dataLayer', config.gtmContainerId);
45
46  // 3. Debug mode si ?gtm_debug=1
47  if (config.debug) {
48    console.log('[bw-analytics] Debug mode ON, GTM ID:', config.gtmContainerId);
49  }
50
51  // 4. API helper globale : bwTrack('event_name', { ... })
52  //    Push auto du bw_source pour séparer site (bitwip.ai) vs portail (portail.bitwip.ai)
53  //    dans les reports GA4 (même property, 2 streams).
54  window.bwTrack = function (eventName, params) {
55    if (!eventName) return;
56    var payload = Object.assign({ event: eventName, bw_source: 'site' }, params || {});
57    window.dataLayer.push(payload);
58    if (config.debug) console.log('[bw-analytics] track', eventName, payload);
59  };
60
61  // 5. Ouvre la modale Sirdata (lien "Gérer mes cookies" footer)
62  window.bwOpenCookieSettings = function () {
63    if (typeof window.__tcfapi === 'function') {
64      window.__tcfapi('displayConsentUi', 2, function () {});
65    } else if (window.Sddan && typeof window.Sddan.cmp === 'object' && typeof window.Sddan.cmp.displayUi === 'function') {
66      window.Sddan.cmp.displayUi();
67    }
68  };
69})();

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.