Google Analytics Tracking Event FP_FCP

Google Analytics Guide
Post Reply
User avatar
SEO_Forum
Forum Admin
Posts: 11
Joined: 15 May 2020, 22:56
Location: Sweden
Contact:

Google Analytics Tracking Event FP_FCP

Post by SEO_Forum »

With this code you can tracking FP_FCP ” first contentful paint”.

Code: Select all

 <head>
  <!-- Add the async Google Analytics snippet first. -->
  <script>
  window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
  ga('create', 'UA-XXXXX-Y', 'auto');
  ga('send', 'pageview');
  </script>
  <script async src='https://www.google-analytics.com/analytics.js'></script>

  <!-- Register the PerformanceObserver to track paint timing. -->
  <script>
  const observer = new PerformanceObserver((list) => {
    for (const entry of list.getEntries()) {
      // `name` will be either 'first-paint' or 'first-contentful-paint'.
      const metricName = entry.name;
      const time = Math.round(entry.startTime + entry.duration);

      ga('send', 'event', {
        eventCategory: 'Performance Metrics',
        eventAction: metricName,
        eventValue: time,
        nonInteraction: true,
      });
    }
  });
  observer.observe({entryTypes: ['paint']});
  </script> 

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests