PageSourceSearch

https://emprendedores.es/wp-content/themes/mkt228/assets/js/modules/mkt-cookies-load.js?ver=1790153449

js emprendedores.es collected 2026-09-24 08:34:39 UTC 3,555 bytes, 106 lines download raw bytes

1/**
2 * mkt-cookies-load.js
3 *
4 * Puente único entre el banner propio y Google Tag Manager.
5 *
6 * Implementa Consent Mode v2 básico: no se descarga GTM hasta que el usuario
7 * autoriza analítica o marketing. Todos los servicios de medición deben vivir
8 * dentro del contenedor; el tema no carga GA4, píxeles ni tags por separado.
9 */
10
11function initialize_google_consent() {
12  window.dataLayer = window.dataLayer || [];
13  window.gtag = window.gtag || function () {
14    window.dataLayer.push(arguments);
15  };
16
17  if (window.mktGoogleConsentDefaultSet) return;
18
19  window.gtag("consent", "default", {
20    analytics_storage: "denied",
21    ad_storage: "denied",
22    ad_user_data: "denied",
23    ad_personalization: "denied",
24  });
25  window.mktGoogleConsentDefaultSet = true;
26}
27
28function update_google_consent(consentData) {
29  initialize_google_consent();
30
31  const analyticsGranted = !!(consentData && consentData.analytics === true);
32  const marketingGranted = !!(consentData && consentData.marketing === true);
33  const consentSignature = (analyticsGranted ? "1" : "0") +
34    (marketingGranted ? "1" : "0");
35
36  // El bootstrap del head ya comunica la decision de usuarios recurrentes.
37  if (window.mktGoogleConsentSignature === consentSignature) return;
38
39  window.gtag("consent", "update", {
40    analytics_storage: analyticsGranted ? "granted" : "denied",
41    ad_storage: marketingGranted ? "granted" : "denied",
42    ad_user_data: marketingGranted ? "granted" : "denied",
43    ad_personalization: marketingGranted ? "granted" : "denied",
44  });
45  window.mktGoogleConsentSignature = consentSignature;
46}
47
48function push_consent_event_once(eventName) {
49  window.dataLayer = window.dataLayer || [];
50  window.mktConsentEventsSent = window.mktConsentEventsSent || {};
51
52  if (window.mktConsentEventsSent[eventName]) return;
53
54  window.dataLayer.push({ event: eventName });
55  window.mktConsentEventsSent[eventName] = true;
56}
57
58// Fija el estado antes de cualquier posible carga posterior del contenedor.
59// Crear dataLayer no realiza ninguna petición a Google.
60initialize_google_consent();
61
62// COOKIES ANALÍTICAS
63function load_analytics_cookies() {
64  // Notify the first-party article counter even when GTM is not configured.
65  window.dispatchEvent(new Event('mkt:analytics-granted'));
66    const cookieConfig = window.mkt_cookies_obj || {};
67
68  // -- Etiquetas de GTM
69  if (cookieConfig.gtm_id) {
70    // Permite limitar tags analíticas mediante un activador de evento personalizado.
71    push_consent_event_once("mkt_consent_analytics_granted");
72  }
73}
74/*---------*/
75
76// COOKIES DE MARKETING
77function load_marketing_cookies() {
78  const cookieConfig = window.mkt_cookies_obj || {};
79
80  // -- Etiquetas de GTM
81  if (cookieConfig.gtm_id) {
82    // Los píxeles y tags no-Google del contenedor deben usar este permiso.
83    push_consent_event_once("mkt_consent_marketing_granted");
84  }
85}
86/*---------*/
87
88// GOOGLE TAG MANAGER
89function load_gtm_script(gtm_id) {
90  if (!/^GTM-[A-Z0-9]+$/i.test(gtm_id) ||
91      document.querySelector('script[data-mkt-gtm="true"], script[src*="googletagmanager.com/gtm.js"]')) return;
92
93  // -- Definir dataLayer
94  window.dataLayer = window.dataLayer || [];
95  window.dataLayer.push({
96    "gtm.start": new Date().getTime(),
97    event: "gtm.js",
98  });
99  // -- Inyectar GTM manualmente
100  const gtmScript = document.createElement("script");
101  gtmScript.async = true;
102  gtmScript.src = "https://www.googletagmanager.com/gtm.js?id=" + encodeURIComponent(gtm_id);
103  gtmScript.dataset.mktGtm = "true";
104  document.head.appendChild(gtmScript);
105}
106/*---------*/

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.