Search engine optimization (SEO) analysis is important to audit a website and identify the opportunities to improve the website score and its positive impact on search engine results. As Sitecore CMS manages the site content, the SEO analysis can be applied to Sitecore text fields before publishing it to the live site. Integrating the product SEO Review Tools can be interesting to evaluate how well the content is optimized for search engines.
The API documentation provided by SEO Review Tools is included in this link https://api.seoreviewtools.com/documentation/seo-content-analysis-api/content/. In this blog, the Rest API is integrated within the CMS with a new custom button called SEO. The idea is to analyze the SEO score on a field of the Sitecore item selected in the CMS.
This solution has been tested in Sitecore XP 10.3.1 and PowerShell Extensions 6.4. A prerequisite is to get a trial license to use the SEO Content Optimization API.
This blog is divided into the following sections:
- Module Description. That is a functional description of this module.
- Data analysis and SEO improvements. Example for CMS editors how to use this module and improve the SEO of the content.
- Implementation details. Technical explanation of the implementation of this module.
- Sitecore module package. Sitecore items created for this module and example.
- Last considerations. Final comments on this module.
1. Module Description
The new “SEO” button has been added to the Review tab inside the CMS.
When the button is clicked, a popup window is displayed to select the item field in which content will be sent to the API to evaluate its SEO.
The API URL is https://api.seoreviewtools.com/v5/seo-content-optimization/?content=1 with the following query strings according to the documentation.
An example of the SEO Content Optimization API response is this one.
There are different sections retrieved from the API:
- Overall SEO score
- Summary of errors, warnings, and optimized content.
- Title and meta-analysis.
- Page headings analysis.
- Internal and external links analysis.
- Image analysis.
The response retrieved from the service will be displayed in a popup window.
2. Data analysis and SEO improvements
The editorial team might take the suggestions for the API response and improve its SEO score.
For example, the response indicated below has an Overall SEO score of 8 and one recommendation is “Your title tag is too short, a minimum of 30 characters is recommended”
Once the title length is fixed in the CMS and the right value is sent again to the API, the response will show the improvement.
A similar example is below with the recommendation for meta-description information.
The meta description value should be updated on the CMS item field
Once the value is resent to the API, the Overall SEO score will be improved.
3. Implementation details
Bellow the sequence of the custom PowerShell scripts created for this functionally.
The PowerShell scripts created for this implementation are located at /sitecore/system/Modules/PowerShell/Script Library/SEO
Bellow the description of the scripts:
- SEO is the entry point and calls the ShowSEOFeature function. This entry point represents the button option displayed in the CMS.
- ShowSEOFeature gets the item fields with the datatype “Text” and displays them in a popup window. Based on the field selected by the user, its value is retrieved. Additional field values (meta, title) are also retrieved. At the end, it invokes the InvokeSEOAPI function.
- InvokeSEOAPI gets the requested data required for the SEO Content Analysis API. For example, the endpoint and API key from a setting Sitecore item. It is needed to convert the Body parameter with the JSON format required by the API. The data obtained from the API is returned to the previous function to display it in a popup window.
The configuration item is located on this path /sitecore/system/Modules/PowerShell/Settings/SEO/SEO Settings
Finally, the Sitecore item taken for this blog is indicated below.
4. Sitecore module package
Here is the Sitecore Integration package indicated in this blog. Bellow the content of that package:
- Home(/sitecore/content/Home) Item used for testing this module. The field sent to the API is named Text.
- SEO PowerShell scripts (/sitecore/system/Modules/PowerShell/Script Library/SEO). It contains the custom logic of the module indicated in this blog.
- SEO PowerShell settings (/sitecore/system/Modules/PowerShell/Settings/SEO/SEO Settings). It contains two settings required to connect to the SEPO Content Analysis API: URL and API key.
- SEO setting template (/sitecore/templates/SEO/SEO Settings). It contains the fields required for the setting item.
- Home template (/sitecore/templates/Sample/Sample Item). This is the sample template provided by Sitecore and it was added the Meta Title field. That new field and another that is Title are sent to the API service.
5. Last considerations
This module has been developed based on this one https://github.com/Sitecore-Hackathon/2019-The-A-team-defenders-of-GOTO/tree/master. Thanks to the authors of that module for their amazing contribution.
An important consideration is when there are changes in custom PowerShell scripts under /sitecore/system/Modules/PowerShell/Script Library, a “Rebuild All” action is required. Go to PowerShell ISE, Tab Settings, RebuildAll action. Bellow the screens.
There are some improvements to be done in this module such as:
- Display nicely the results from the API in the popup window.
- The APIUrlSEO setting that is located at /sitecore/system/Modules/PowerShell/Settings/SEO/SEO Settings contains in the value the hard-coded word “SEO Tools” in the keyword query string. That should be replaced with a new field inside of the CMS.
I am very happy to share with you this module implemented with PowerShell and a third party REST API to evaluate the SEO for unpublished content. I hope that could be interesting and useful for you too. Thanks for reading.