Does Google Analytics slow down your website? A better way to load it in Utah

A practical way to delay Google Analytics so it does not drag down website speed before a visitor even interacts with the page.

Google Analytics can slow your website down if it loads immediately on every page view.

If you are trying to improve PageSpeed Insights and Core Web Vitals, one of the easiest ways to reduce that drag is to delay analytics until a visitor actually interacts with the page.

That is what this script does.

It waits until the visitor scrolls, moves the mouse, or touches the screen. If none of that happens, it falls back to loading after 4 seconds.

Why this helps

The Google Analytics script is not free. It adds requests, execution time, and extra work in the browser.

That does not always wreck performance on its own, but on many small-business websites it is one of several scripts that stack up and make the page feel heavier than it needs to.

Delaying analytics can help reduce that early load burden so the page gets to useful content faster.

The tradeoff

The downside is simple.

If someone lands on your site and leaves within a few seconds without interacting, that visit may never be tracked.

I still think that tradeoff is often worth it. A faster page helps more real visitors stay, read, and convert.

Delayed Google Analytics script

Replace the Google Analytics ID with your own.

<script>
(function() {
  const gtagId = 'G-REPLACE_ME';

  function loadGA() {
    if (window.gtagLoaded) return;
    window.gtagLoaded = true;

    const script = document.createElement('script');
    script.async = true;
    script.src = `https://www.googletagmanager.com/gtag/js?id=${gtagId}`;
    document.head.appendChild(script);

    script.onload = () => {
      try {
        window.dataLayer = window.dataLayer || [];
        function gtag(){ dataLayer.push(arguments); }
        gtag('js', new Date());
        gtag('config', gtagId);
        gtag('event', 'page_view', { page_path: window.location.pathname });
      } catch (error) {
        console.error('Error initializing Google Analytics:', error);
      }
    };
  }

  setTimeout(loadGA, 4000);
  document.addEventListener('scroll', loadGA, { once: true });
  document.addEventListener('mousemove', loadGA, { once: true });
  document.addEventListener('touchstart', loadGA, { once: true });
})();
</script>

Final thought

If your site is already slow, analytics is usually not the only problem. It is often part of a bigger stack of scripts, apps, and page-builder bloat.

If you want help improving website speed, SEO, or the performance of your landing pages, see Website Design , read Why your slow Wix, Squarespace, or WordPress site hurts your SEO and Google Ads performance in Utah , or start on the contact page .

Get found. Stop losing leads.

Web design to help you launch. Local SEO to help you rank. Google Ads to help you scale.