Created
July 6, 2026 14:41
-
-
Save spirinvladimir/46b62226330a66795800026044f8a85e to your computer and use it in GitHub Desktop.
Keep Google Analytics 4 at CacheStorage and loading with priority low
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const GA = 'https://www.googletagmanager.com/gtag/js?id=GT-TQL9TSPB' | |
| caches.open('ga') | |
| .then(c => | |
| c.match(GA) | |
| .then(r => | |
| r || fetch(GA, {priority: 'low'}) | |
| .then(r => | |
| r.ok && c.put(GA, r.clone()).then(_ => r) | |
| ) | |
| ) | |
| ) | |
| .then(r => r.text()) | |
| .then(code => { | |
| const script = document.createElement('script') | |
| script.textContent = code | |
| document.head.appendChild(script) | |
| window.dataLayer = window.dataLayer || [] | |
| window.gtag = function gtag(){dataLayer.push(arguments)} | |
| gtag('js', new Date()) | |
| gtag('config', 'GT-TQL9TSPB') | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment