This script will automatically submit all your website URLs to Google Search Console for indexing (or re-indexing).
There are heaps of paid SEO tools available to automatically submit your sites to Google for indexing. They're great, but you can also use this script to do the same thing for free.
This script uses a Google Cloud Service Account to connect to your Google Search Console instance, pull in your sitemap, and submit each page automatically for indexing.
Plus, it's easy to get started.
Setting up this script is easy. You just need to create a (free) Google Cloud service account, authenticate this script using the .json
service account keys, then invite the service account to your Google Search Console account.
-
Clone this script and install packages
Download this script directly, or clone it. Make sure you've got
ruby
installed locally, then runbundle
to install all required packages —git clone git@github.com:theriturajps/GSC-Auto-Index-Script.git cd GSC-Auto-Index-Script bundle
-
Create a service account in Google Cloud
- Visit https://console.cloud.google.com/iam-admin/serviceaccounts and create a new service account (click the big
+ Create Service Account
button). - Click "Actions" > "Manage keys" > "Add key" > "Create new key" > "JSON". A
.json
key file will automatically download — move it into this project directory
- Visit https://console.cloud.google.com/iam-admin/serviceaccounts and create a new service account (click the big
-
Authenticate the script
- Edit
script.rb
and change the line withservice_account_file = "_.json" to be the name of your
.json` key file. - For example,
service_account_file = "main_service_account.json"
- Edit
-
Invite your service account into your Google Search Console
- Open Google Search Console and, in the sidebar, click "Settings" > "Users and Permissions" > "Add User" and enter the email of your service account
- ie: "
example@project-400005.iam.gserviceaccount.com
" - Set the permissions for the account to "Owner"
- ie: "
- Open Google Search Console and, in the sidebar, click "Settings" > "Users and Permissions" > "Add User" and enter the email of your service account
-
Run the script!
- Run
ruby script.rb
to start the script. It will automatically pull in the sites available in your Google Search Console, and let you choose between them. - Once you choose a site, it will parse the sitemap (from the URL within Google Search Console), and submit each page for indexing.
- Run
If this flag is set true
, the script will look for a CSV file called urls.csv
. This file should contain a comma-separated list of URLs to index, like this —
https://www.riturajps.in, https://riturajps.in/p/about-us.html
This can be helpful for sites with a massive number of pages, so you can index a subset rather than all of them.
By default, this flag is set false
.