Getting Your Next.js Site Indexed on Google
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.
Debugging with AI
Stuck on indexing issues? Copy this prompt and share it with Claude Code CLI or any AI assistant:
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:
# .env.local
NEXT_PUBLIC_GA_MEASUREMENT_ID=G-XXXXXXXXXXCreate an analytics component:
// 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:
// 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:
- Go to your domain's DNS settings
- Add a new TXT record
- Hostname: @(represents your root domain)
- Content: The verification string from Google (looks like google-site-verification=...)
- 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:
- Go to Sitemaps in the left menu
- Enter the full sitemap URL: https://yourdomain.com/sitemap.xml
- 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:
curl -I https://yourdomain.com/sitemap.xmlIf 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:
- Use the URL Inspection tool (top of Search Console)
- Enter your homepage URL
- Click Request Indexing
- 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:
site:yourdomain.comOnce 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
- Google Search Console - Add and verify your site
- Google Analytics - Set up visitor tracking
- Next.js Metadata API - Improve SEO with proper meta tags