DEV Community

Muhammad Huzaifa
Muhammad Huzaifa

Posted on

5 SEO Lessons From 3M Google Impressions (With Next.js Code)

 Most developers treat SEO as something the marketing team handles later. In my experience, that's where a lot of traffic gets lost.

I'm a full stack developer, and I've also spent the last few years doing SEO on real projects: client sites, organization websites, tool sites, and my own apps. Across 10 websites, that work added up to more than 3 million Google impressions.

Here are five lessons that made the biggest difference, with code where it helps.

1. Metadata is code, so treat it like code

Titles and descriptions are the first thing users see in search results. In Next.js (App Router), set them per page instead of relying on one global default.

// app/blog/[slug]/page.tsx
import type { Metadata } from "next";

export async function generateMetadata(
  { params }: { params: { slug: string } }
): Promise<Metadata> {
  const post = await getPost(params.slug);

  return {
    title: post.title,
    description: post.excerpt,
    alternates: {
      canonical: `https://example.com/blog/${params.slug}`,
    },
    openGraph: {
      title: post.title,
      description: post.excerpt,
      type: "article",
    },
  };
}
Enter fullscreen mode Exit fullscreen mode

A unique title and description per page is one of the cheapest wins in SEO, and it's surprisingly often missing on developer-built sites.

2. Always set a canonical URL

If the same content is reachable at more than one URL (query params, trailing slashes, www vs non-www), Google has to guess which one to rank. The alternates.canonical field above removes the guessing.

This also matters when you cross-post. This article, for example, points its canonical back to my own blog.

3. Generate your sitemap and robots.txt from code

Hand-written sitemaps go stale. Next.js lets you generate both from your data:

// app/sitemap.ts
import type { MetadataRoute } from "next";

export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
  const posts = await getAllPosts();

  return [
    { url: "https://example.com", lastModified: new Date() },
    ...posts.map((post) => ({
      url: `https://example.com/blog/${post.slug}`,
      lastModified: post.updatedAt,
    })),
  ];
}
Enter fullscreen mode Exit fullscreen mode
// app/robots.ts
import type { MetadataRoute } from "next";

export default function robots(): MetadataRoute.Robots {
  return {
    rules: { userAgent: "*", allow: "/" },
    sitemap: "https://example.com/sitemap.xml",
  };
}
Enter fullscreen mode Exit fullscreen mode

Then submit the sitemap in Google Search Console once, and it stays up to date on every deploy.

4. "Published" doesn't mean "indexed"

One of the most common problems I see: pages that are live but never indexed. Before assuming your content is the problem, open URL Inspection in Search Console and check whether Google has actually indexed the page.

Common causes I've run into:

  • A leftover noindex from a staging environment
  • Pages blocked in robots.txt
  • Content that only renders client-side and loads slowly
  • Thin or near-duplicate pages Google decides to skip

5. Domain migrations need a plan, not just a DNS change

Moving a site to a new domain without planning can wipe out years of rankings. The basics:

  • Map every old URL to its new URL with 301 redirects (one-to-one, not everything to the homepage)
  • Keep the old domain and redirects live long-term
  • Verify both domains in Search Console and use the Change of Address tool
  • Submit the new sitemap and watch indexing closely for the first few weeks

The fix that convinced me SEO is a developer skill

One project stays with me. A well-known organization's official website was ranking below scam sites for its own name. People searching for the real organization were landing on fake pages.

After about two weeks of focused technical and on-page fixes, the official site was back on top. It went on to reach 2.98M impressions and 1.29M clicks. None of it was magic, just fundamentals done carefully and in the right order.

I put all of this into an ebook

After enough projects, I organized everything I'd learned into a 72-page PDF: SEO Ebook, Beginner to Advanced Guide With Real Case Studies and Checklists.

It covers 15 chapters, including keyword research, technical SEO and Core Web Vitals, white-hat link building, programmatic SEO, deindexing recovery, domain migrations, AI search, Next.js SEO code, and a 90-day action plan. Every chapter ends with a "Try This Now" task and a checklist, and every number comes from real Search Console data.

If that sounds useful, it's available here: SEO Ebook PDF on Etsy.

I also post free SEO tips on my SEO Tips & Guides Pinterest board.


I'm Muhammad Huzaifa, a full stack developer (MERN/Next.js) and SEO specialist. More of my writing is at muhammadhuzaifa.com.

What's the SEO issue you've struggled with most on your own projects? Let me know in the comments.

Top comments (0)