1// // Initialize Google Analytics 2// window.dataLayer = window.dataLayer || []; 3// function gtag() { 4// dataLayer.push(arguments); 5// } 6// gtag('js', new Date()); 7// gtag('config', 'G-M832RWSSXS'); // Replace with your actual Google Analytics Tracking ID 8 9// critical.js 10 11// Load the Google Tag Manager library asynchronously 12// setTimeout(() => { 13// (function () { 14// var gtagScript = document.createElement('script'); 15// gtagScript.src = 'https://www.googletagmanager.com/gtag/js?id=G-M832RWSSXS'; 16// gtagScript.async = true; 17// document.head.appendChild(gtagScript); 18 19// // Load Google Ads tracking as well 20// var gtagAdsScript = document.createElement('script'); 21// gtagAdsScript.src = 'https://www.googletagmanager.com/gtag/js?id=AW-10875698734'; 22// gtagAdsScript.async = true; 23// document.head.appendChild(gtagAdsScript); 24// })(); 25 26 27// // Define the dataLayer and gtag function 28// window.dataLayer = window.dataLayer || []; 29// function gtag() { 30// dataLayer.push(arguments); 31// } 32 33// // Initialize both Google Analytics and Google Ads configurations 34// gtag('js', new Date()); 35// gtag('config', 'G-M832RWSSXS'); // Google Analytics Tracking ID 36// gtag('config', 'AW-10875698734'); // Google Ads Tracking ID 37// }, 10000); 38// 1. IMMEDIATELY initialize data layer and gtag function 39window.dataLayer = window.dataLayer || []; 40function gtag() { dataLayer.push(arguments); } 41 42// 2. Load tracking after 10-second delay 43setTimeout(() => { 44 // Create main tracking script 45 const gtagScript = document.createElement('script'); 46 gtagScript.src = 'https://www.googletagmanager.com/gtag/js?id=G-M832RWSSXS'; 47 gtagScript.async = true; 48 49 // Success handler 50 gtagScript.onload = () => { 51 // Initialize GA4 configuration 52 gtag('js', new Date()); 53 gtag('config', 'G-M832RWSSXS', { 54 groups: 'default', 55 send_page_view: true, 56 debug_mode: false // Set to true for testing 57 }); 58 59 // Initialize Google Ads configuration 60 gtag('config', 'AW-10875698734', { 61 conversion_id: 'AW-10875698734', 62 currency: 'USD' 63 }); 64 65 // console.log('Google Analytics and Ads loaded successfully'); 66 67 // Trigger initial page view 68 gtag('event', 'page_view', { 69 page_title: document.title, 70 page_location: location.href, 71 page_path: location.pathname, 72 send_to: 'G-M832RWSSXS' 73 }); 74 }; 75 76 // Error handler 77 gtagScript.onerror = () => { 78 console.error('Failed to load Google Tag Manager'); 79 // Fallback tracking or retry logic could go here 80 }; 81 82 // Inject script into DOM 83 document.head.appendChild(gtagScript); 84}, 10000); // 10-second delay
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.