DEV Community

Ashish kumawat Global Performance Marketer
Ashish kumawat Global Performance Marketer

Posted on • Originally published at ashishkumawat.com on

Next.js Speed Optimization: How I Hit 97+ PageSpeed Score With GA4, GTM, and Meta Pixel

In the modern digital landscape, website speed is no longer just a vanity metric—it is the direct foundation of conversion rates, user experience, and search engine optimization. As search engines transition to AI-driven search overviews and mobile-first indexing, having a lightning-fast site is critical to stay competitive. In this optimization case study, we document the exact step-by-step framework used by Ashish Kumawat—a certified AI Automation Architect and Global Performance Marketing Consultant—to optimize his Next.js corporate portal, achieving an outstanding 97/100 on Desktop and 92/100 on Mobile in Google PageSpeed Insights. What makes this case study unique is that these extreme scores were achieved while keeping heavy third-party marketing scripts (including Google Tag Manager, Google Analytics 4, Meta Pixel, and Microsoft Clarity) fully active.

The Dilemma: Why PageSpeed Scores Drop After Adding Marketing Tags

If you are a web developer or agency owner building high-performance sites in React or Next.js, you have likely encountered this frustration: a clean, newly built site scores 98+ on Lighthouse, but the moment the marketing team adds GTM, GA4, and Facebook Ads tracking pixels, the score drops to 60 or lower. The culprit is Total Blocking Time (TBT). These third-party tracking scripts load synchronous JavaScript files that block the browser's main thread, causing significant latency during page load. For local trade owners in Jaipur's business hubs like Vaishali Nagar, Mansarovar, Malviya Nagar, C-Scheme, and Raja Park, or international enterprise clients in the USA, UK, Canada, Australia, Singapore, and Dubai, this speed drop translates directly to higher bounce rates, lower search rankings, and wasted advertising spend on Meta Ads and Google Ads campaigns.

Step 1: Next.js Image Optimization & Layout Shift Control

To achieve a sub-1-second First Contentful Paint (FCP) and a perfect Cumulative Layout Shift (CLS) score of 0, we leveraged the native Next.js <Image /> component. The profile hero image on the home page was converted to the next-generation .webp format, which reduces file sizes by up to 30% compared to standard PNGs without losing visual quality. More importantly, we applied the priority attribute to the critical above-the-fold hero image. This instructs the browser to download the primary image immediately, eliminating the layout shifts that occur when images load lazily. Controlling image width and height explicitly ensures that the browser reserves space for the image before it downloads, bringing the CLS score to a perfect zero.

Step 2: Deferring Non-Critical Scripts to Free the Main Thread

A major breakthrough in reducing our Total Blocking Time (TBT) from over 1,200ms to a negligible level was the strategic deferral of non-critical client-side components. Many websites load interactive elements (such as welcome modals, email sign-up popups, or chat widgets) immediately on mount, which blocks the CPU during the critical first second of loading. In our Next.js architecture, we wrapped the welcome popups in a state hook and deferred their mount by 60 seconds (60000ms) using a standard setTimeout on mount. This ensures that the primary page content compiles and renders immediately without CPU competition, while the interactive popup mounts silently in the background long after the user has engaged with the page.

Step 3: Server-Side GTM & Google Consent Mode V2

To maintain accurate data attribution without clogging the client's browser, we transitioned to Server-Side Tracking. Instead of loading individual client-side SDKs for GA4, Facebook Pixel, and Microsoft Clarity, we utilize a single Google Tag Manager (sGTM) container endpoint hosted on a first-party subdomain (e.g., tracking.ashishkumawat.com). This server-side container acts as a secure data router. It receives a single event stream from the browser, sanitizes it, and sends it directly to Google Analytics, Meta Conversions API (CAPI), and Microsoft Clarity. Additionally, we configured Google Consent Mode v2 server-side. This ensures absolute compliance with GDPR/CCPA regulations for international markets while recovering up to 30% of lost conversion data through advanced machine learning models.

The Real Result: Speed Meets Conversion

The result of these structural optimizations is a site that feels instantly responsive to human visitors and scores in the elite green zone on Lighthouse:

Desktop Performance: 97/100

Mobile Performance: 92/100

First Contentful Paint (FCP): 0.9s

Largest Contentful Paint (LCP): 1.4s

Cumulative Layout Shift (CLS): 0

Below are the real PageSpeed Insights dashboards captured after the optimization:

Next.js Desktop PageSpeed Score 97

Next.js Mobile PageSpeed Score 92

Build a Fast, High-Converting Website for Your Business

If you are running paid search or social media campaigns, your website's speed is the single most critical factor in determining your ROAS. A fast website lowers your Google Ads CPC, increases your Meta Ads conversion rate, and ranks higher in AI search overviews (Gemini, ChatGPT) and local SEO maps. If you want to optimize your digital infrastructure, implement server-side tracking, or build a high-performance corporate portal in Next.js, I can help. As an expert AI Automation Architect and Performance Marketing Consultant in Jaipur, India, I build systems that drive revenue. Book your free digital audit today and let's scale your business globally.

Top comments (0)