Getting Your Next.js Site Indexed on Google

4 min read

Getting Your Next.js Site Indexed on Google

You deployed your Next.js site to Vercel. It's live. But when you search for it on Google, nothing shows up. Here's how to fix that.

AI Dev Tip

Debugging with AI

Stuck on indexing issues? Copy this prompt and share it with Claude Code CLI or any AI assistant:

bash
claude "My site isn't showing up in Google. Here's a guide: https://marthakelly.com/blog/getting-your-nextjs-site-indexed-on-google"

The LLM can help diagnose your specific issue using this guide as context.

Add Google Analytics

First, get analytics running so you can track visitors once Google starts sending traffic.

Get your measurement ID from Google Analytics. It looks like G-XXXXXXXXXX. Add it to your environment variables:

bash
# .env.local
NEXT_PUBLIC_GA_MEASUREMENT_ID=G-XXXXXXXXXX

Create an analytics component:

tsx
// components/analytics.tsx
import Script from 'next/script';
 
export function Analytics() {
  const gaId = process.env.NEXT_PUBLIC_GA_MEASUREMENT_ID;
 
  if (!gaId) return null;
 
  return (
    <>
      <Script
        src={`https://www.googletagmanager.com/gtag/js?id=${gaId}`}
        strategy="afterInteractive"
      />
      <Script id="google-analytics" strategy="afterInteractive">
        {`
          window.dataLayer = window.dataLayer || [];
          function gtag(){dataLayer.push(arguments);}
          gtag('js', new Date());
          gtag('config', '${gaId}');
        `}
      </Script>
    </>
  );
}

Add it to your root layout:

tsx
// app/layout.tsx
import { Analytics } from '@/components/analytics';
 
export default function RootLayout({ children }) {
  return (
    <html>
      <body>
        <Analytics />
        {children}
      </body>
    </html>
  );
}

Set Up Google Search Console

Go to Google Search Console and add your domain as a property. Google will give you a TXT record to verify ownership.

Add this TXT record to your DNS settings. If you're using Hover:

  1. Go to your domain's DNS settings
  2. Add a new TXT record
  3. Hostname: @ (represents your root domain)
  4. Content: The verification string from Google (looks like google-site-verification=...)
  5. TTL: Default (15 minutes) is fine

[Screenshot: Hover DNS settings showing the TXT record with @ hostname]

DNS changes take 5-30 minutes to propagate. Once they do, click "Verify" in Search Console.

[Screenshot: Google Search Console verification success page]

Submit Your Sitemap

Your Next.js site should have a sitemap at /sitemap.xml. In Search Console:

  1. Go to Sitemaps in the left menu
  2. Enter the full sitemap URL: https://yourdomain.com/sitemap.xml
  3. Click Submit

[Screenshot: Google Search Console Sitemaps page showing successful submission]

Common Issue: "Couldn't fetch" Error

If your sitemap shows this error, check if your site redirects from non-www to www (or vice versa). Use curl to test:

bash
curl -I https://yourdomain.com/sitemap.xml

If you see a 301 or 307 redirect, the sitemap URL needs to match your canonical domain. For a domain property in Search Console, just submitting sitemap.xml (without the full URL) should work.

Request Indexing

Speed up the process by manually requesting indexing:

  1. Use the URL Inspection tool (top of Search Console)
  2. Enter your homepage URL
  3. Click Request Indexing
  4. Repeat for your most important pages

Timeline

First pages usually appear in Google within 24-48 hours after submitting. Full site indexing takes 1-2 weeks.

Test if you're indexed by searching Google for:

markdown
site:yourdomain.com

Once you see results, you're live.

Have Tips to Share?

Found a trick that helped you get indexed faster? Have a question this guide didn't cover? Reach out - I'd love to hear from you.

References