How to add support for Yandex IndexNow technology to MODX sites
On October 18 Yandex officially launched IndexNow project. The project offers a new way for sites to interact with search engines. The important advantage of IndexNow is the ability to automatically inform search engines of changes to the site, including the appearance of new pages, updating or deleting the current ones.
More information on using the API can be found at indexnow.org and in Yandex Help.
Website owners and engine developers can make use of the protocol. For more details on how to do that, see the manual.
In this article we will consider how to use this technology from Yandex on MODX sites.
There are two ways to inform Yandex about changes in pages.
- By means of GET requests. This way you can send one page to the index. This method is suitable for small projects.
- Using POST requests. Several pages can be sent to the index using this method. This makes sense for large information resources or stores with a large number of products.
Instructions on how to submit pages for indexing to Yandex using IndexNow technology
With GET requests.
When editing a page, you or your content manager can save the page many times to see how it will appear on the site. Since the IndexNow technology is new, and it is not yet clear how it will react to sending the index to the same page ten times in one day, we decided to proceed as follows:
- We create TV parameter, which will be responsible for sending pages for indexing.
- When you save the page, we check whether it is published and whether the indexing flag is set.
- If the check passed, send pages to the index and reset the flag of indexing.
Create TV parameter in the form of a checkbox, which will be responsible for sending pages to IndexNow.
Enter the name and description
Specify output parameters
Allow tv parameter for templates
Now, when you edit the page in the Additional Fields section, you should have the appropriate checkbox.
Getting the key from Yandex
To do this, you must confirm the rights to manage the site via Yandex Webmaster. After confirming the rights you will receive a key of the form "75350874d660fb78". Then this key we will use when generating GET request.
Create plugin to send pages to the index.
When creating a plugin, you should go to tab "System Events" and check events "OnDocFormSave" (will be responsible for sending information when creating or editing pages) and "OnResourceDelete" (sends information about deleting pages).
In the plugin itself we will perform a series of checks, and then send the page to the service IndexNow for indexing. If success is returned, we reset the TV parameter and after that write the page address and the Yandex response code into the log.
if ($resource->get('published') && $resource->getTVValue('IndexNow'))
{
$answer = file_get_contents("https://yandex.com/indexnow?url=".$modx->makeUrl($id, '', '', 'full')."&key=72d58e01fbd9628a");
$answerDecode = json_decode($answer, true);
if ($answerDecode['success'])
{
$modx->log(MODX_LOG_LEVEL_ERROR, 'Page '.$modx->makeUrl($id, '', '', 'full')." sent to the index. Server response code: '.$answer);
$resource->setTVValue('IndexNow', '');
$resource->save();
}
else
$modx->log(MODX_LOG_LEVEL_ERROR, 'An error occurred when sending the page '.$modx->makeUrl($id, '', '', 'full')." for indexing. Server response code: '.$answer);
}
This article was sent for indexing using this method.