Here is a great way to load analytics via an external js file: (I created a function, but you can also run it directly)
1 2 3 4 5 6 7 8 9 10 |
function loadAnalytics(){ var import = document.createElement('script'); import.src='https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXX-1'; document.head.appendChild(import); window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'UA-XXXXXXX-1'); } |