I previously discussed how to build a sitemap in Next.js, but I didn't discuss the crucial next step: How to submit your sitemap to Google.
Let me guide your through this process step-by-step:
Google provides a list of different ways you can submit your sitemap to their crawler for indexing.
- In the Search Console
- Programmatically using their Search Console API
- Listing your sitemap in your robots.txt file
- Broadcasting with WebSub in Atom or RSS
I chose to use two of the above methods. When I created my robots.txt file, I did list the sitemap in the file. With this approach, we just wait until Google discovers our site and reads the robots.txt file. No doubt this works, but I wanted to be a little more proactive, too.
Google allows you to choose a verification method to confirm site ownership. Several options are provided. Choosing one may depend on your hosting situation or the tech you are using with your blog.
- HTML file upload
- HTML tag
- Google Analytics tracking code
- Google Tag Manager
- Google Sites, Blogger, or Domains account
- Domain name provider
To provide for verification metadata, Next.js supports a verification object in the metadata type it creates your project's metadata tags from. My discussion of creating a metadata object for my Next.js blog might help you understand the overall approach.
I put the following code in the root
layout.tsx file of my project as part of the larger metadata object Next.js creates.
After adding the new verification metadata to your site and redeploying to the web, you can open DevTools to inspect your site. You should see a meta tag somewhere in the
<head> element of your home page like this:
<meta name="google-site-verification" content="YOUR-VERIFICATION-CODE-PROVIDED-BY-GOOGLE">
Now you can go back to the search console to tell Google to verify your site ownership. Google should be able to verify your site ownership very quickly.
You have now verified the ownership of your site, and you can submit your sitemap in the Google Search Console.
Now the wait begins for your site to be indexed. I know you may be anxious ( just like I was ) to see results, but Google will usually take a few days before it crawls and indexes your site.
Go back to the Search Console in a couple of days to see if Google has visited your site. The Search Console has an Indexing section where it will tell you the last date your sitemap was read by Google, the status, number of discovered pages, and let you dive into reports for single pages, too.