Marketing

IndexNow for GoCommerce

A Go package that tells search engines a page changed, the moment it does. When a product or collection changes, its storefront URL is batched for 30 seconds and submitted to IndexNow, which Bing, Yandex, Seznam and Naver read. Google does not take part.

What it does

In the package’s own words: “IndexNow is a ping and nothing more. One POST carrying the URLs that changed, and Bing, Yandex, Seznam and Naver fetch them rather than waiting to crawl. There is no account, no console and no verification round trip: a key file on the site is the verification.”

The module listens for products created, updated and deleted, and collections updated. It builds each page’s storefront URL from the storefront address and a path pattern, and when a product’s slug changes it submits the old address too — so a search engine looks at the 404 and drops it, rather than keeping a dead URL until it happens to recrawl.

The key file has to answer at the root of the storefront, because IndexNow trusts a key only for URLs in its own folder and below — and in a headless store the storefront is not this server. So the engine keeps the key and the storefront serves it: as a static file, or by proxying GET /x/indexnow/key.

Configuration

One setting is required, the storefront URL, and it lives on the Plugins screen only; Config holds nothing but test and proxy overrides. The plugin starts switched off — enable it there.

IndexNow module settings — 7 settings, 1 required
SettingEnvironment variableRequiredWhat it does
storefront_url
Storefront URL
— Yes Where the pages actually are, and so the host the key file must answer on. Panel only.
key
Key
— No Left empty, one is generated on first use — 32 hex characters. Anything from 8 to 128 letters, digits and dashes.
product_path
Product page path
— No The product page’s path, /products/{slug} by default.
collection_path
Collection page path
— No The collection page’s path, /collections/{slug} by default.
Window — No How long URLs collect before one submission goes: 30 seconds by default. Go only.
Endpoint — No Overrides https://api.indexnow.org/indexnow, for tests. Go only.
HTTP — No Replaces the HTTP client, which otherwise times out after 15 seconds — for tests, or a store behind a proxy. Go only.

The module reads its Config struct, not the environment. The variable names are the ones the package’s own example or the reference binary uses; in your own main() you choose where each value comes from. Where a setting has a panel label, the admin’s settings drawer can hold it too, and a value typed there wins over Config.

Setting it up

  1. Install the modulePass indexnow.New() to gocommerce.New in your own main(), as below. The reference binary has no flag for it; examples/store/main.go installs it.
  2. Switch it onEnable IndexNow on the Plugins screen and set the storefront URL — and the product and collection paths, if yours differ.
  3. Serve the keyPOST /api/admin/x/indexnow/key mints a key and says what to serve: <key>.txt at the storefront’s root, holding the key with no trailing newline — or a route proxying /x/indexnow/key.
  4. Check itGET /api/admin/x/indexnow/check fetches the file from the storefront, compares it byte for byte, and names the problem — a 404, a wrong key, a stray newline — before anything is submitted.

main.go

import (
	"github.com/itswadesh/gocommerce/core"
	"github.com/itswadesh/gocommerce/ext/indexnow"
)

// Nothing to configure here: the storefront URL is a plugin
// setting, and the storefront serves the key file.
app, err := gocommerce.New(cfg, indexnow.New())

The package doc’s own example, with its imports. cfg is your gocommerce.Config; indexnow.New also accepts an optional indexnow.Config. Import path github.com/itswadesh/gocommerce/ext/indexnow.

How it works

What it does not do

Read these before an order depends on it. No store is known to run GoCommerce in production yet, so these come from the code, not from anyone’s experience.

FAQ

Questions about the IndexNow module

Does this tell Google?

No. Google does not take part in IndexNow, and the module says so rather than pretending otherwise. For Google, Search Console and a sitemap are still the route — the sitemaps module serves one.

Where does the key file go?

At the root of the storefront’s host: https://shop.example/<key>.txt, holding the key and nothing else — no trailing newline. The engine cannot serve it there in a headless store, so the storefront does, as a static file or by proxying GET /x/indexnow/key.

What gets submitted?

A product’s page when it is created, updated or deleted — and its old address too, when its slug changed — and a collection’s page when it is updated. Everything that changed in a 30-second window goes in one submission.

Does it need an account with the search engines?

No. IndexNow has no account and no console: the key file on the storefront is the whole of the verification.

Source

Everything on this page is read from ext/indexnow in the GoCommerce repository, MIT licensed. When this page and the code disagree, the code is right and this page is out of date.Bing, Yandex, Seznam and Naver are trademarks of their owners; this module submits URLs to the shared IndexNow endpoint and implies no endorsement by any of them. See trademarks.

Try it against a store of your own

The one-command stack gives you GoCommerce’s API and admin on your own machine in minutes. Add this module to it and try it on test orders before a real one depends on it.

Chat on WhatsApp