Google Indexing API for Laravel

Published 20 March 2020 22:01

Almost all the projects I work on are built on Laravel. For those projects, I needed a simple way to index pages inside Google. Let's make this with Google Indexing API.

When is this useful?

When you make a new page on your website you want it as soon as possible in the index of popular search engines. There are some ways to do this (for example: ping your sitemap, Google Search Console) manually but you don't want this when a user can generate content on your website. For this use case, you can make an integration with the Google Indexing API which you can trigger on certain events.

But, do I still need sitemaps? Yes, you need it. Google is not the only search engine visiting your site, they provide this API but still recommends to use the old-way with sitemaps.

Sometimes I got the question: "How can we request Google to index our site?". This is not a big issue for bigger sites who have a good reputation. Google will visit those sites more often than a new site that's created just a few weeks ago. Of course, you can do this manually by using Search Console, but when you grow it's not desirable.

So let's continue with the installation of the Google Indexing package for Laravel.

Notes about Google Indexing API

Before I go into the details about how to use this package, please take a look at the documentation from Google. Here they documented which type of pages are allowed/valid for the Indexing API, see developers.google.com.

At the moment of writing this blog post, there is a limit in the amount of number you can request for indexing. This is 200 requests per day, it might be changed at the moment you read this. For more details visit developers.google.com about the quota details.

As mentioned by John Mueller, Webmaster Trends Analyst at Google, you can only use the Indexing API for Job posting & live stream structured pages.

Installation

The package we use is called Laravel Google Indexing, a simple package that uses the Google PHP Client for making API requests. With this package, you can communicate with the Google Indexing API and request the indexing status, update or delete an URL from the index.

Install via composer:

composer require famdirksen/laravel-google-indexing

This will install the latest compatible version of the package in your project.

Usage

To request the status from a page you can use the create method. Or use the Facade helper.

Indexing status:

LaravelGoogleIndexing::create()->status('https://www.my-domain.com')
LaravelGoogleIndexing::status('https://www.my-domain.com')

Update URL:

LaravelGoogleIndexing::create()->update('https://www.my-domain.com')
LaravelGoogleIndexing::update('https://www.my-domain.com')

Delete URL:

LaravelGoogleIndexing::create()->delete('https://www.my-domain.com')

LaravelGoogleIndexing::delete('https://www.my-domain.com')

If you're interested in more information about the package you can check this out on GitHub, see: https://github.com/Famdirksen/laravel-google-indexing.

Robin Dirksen

Robin Dirksen

On my blog you can find articles that I've found useful. This is just a simple blog built with Wink.