In today’s competitive e-commerce landscape, optimizing product listings for search engines is more critical than ever. But crafting compelling titles and descriptions that rank high in search results can be time-consuming and challenging.
What if you could automate this process and leverage the power of generative AI? This is where Gemini comes in. Google’s next-generation AI model, Gemini, excels at understanding and generating human-like text, making it perfect for optimizing product titles and descriptions.
Use case (A true story)
A friend of mine has a print-on-demand WooCommerce store with over 1000+ unique apparel items. Almost 99% of his product listings only have standard product descriptions that contain information about the brand, manufacturer, etc. Only the titles of these listings contain some SEO-relevant keywords.
He asked for my help to solve the following challenge: for each product listing in WooCommerce, how can we use Google Gemini to find out the most relevant SEO keywords based on the existing title, then use these keywords to generate optimized/improved product titles and product descriptions in an automated way?
Proof of Concept
On the one hand, WooCommerce has an excellent product API that makes it easy to access listing data programmatically. On the other hand, Gemini excels at generating human-like text, making it perfect for optimizing product titles and descriptions. This is a perfect match!
With the help of Google Code Assist, I developed a PoC of a Python-based tool that harnesses Gemini’s capabilities to improve and optimize WooCommerce product listings. The Gemini-powered optimization significantly improved the product titles and descriptions, making them more engaging and informative.
Below are the main building blocks of this proof of concept.
- Fetch Product Data: The code retrieves product data from our WooCommerce store using its API. For this you will need a WooCommerce API consumer key and secret.
- Extract Relevant Attributes: The WooCommerce API responds by returning the product name/title and description among many other products information. The script extracts the title and product description.
- Prepare our Prompt: We then prepare a prompt that instructs Gemini to determine the most relevant SEO keywords based on the product title. We also instruct Gemini to use these keywords for creating a compelling product title and description.
- Interact with Gemini: the Gemini API (Python SDK) is invoked by providing the prompt prepared in step 3 above. We used gemini-1.5-flash as a model in our case.
- Parse Gemini´s response: Gemini replies with an object containing the optimized product title and description. We extract both of these attributes from the object as we will need them in the following steps.
- Duplicate the product: In order to keep a copy of the original product, we duplicate it (as a draft) in WooCommerce.
- Update Product Listings: We use the WooCommerce API to update the product title and description with new ones.
To streamline the process for large inventories, I developed a user-friendly interface using Streamlit. We have also introduced “batch processing” to allows users to easily choose a product page (10 products maximum) they want to process in each batch. This capability ensures automation and efficient optimization even for stores with extensive catalogs.
Here’s a glimpse of the Streamlit UI:
The UI above provides a simple and intuitive way to manage the optimization workflow. Users can:
- Select a product page and trigger the process by clicking on “Optimize Product Listings”
- Monitor progress: Track the optimization process in real-time in the UI.
Example & Demo
This example shows a product title& description before and after the optimization process.
Before Optimization
After Optimization
As you can notice, both product titles are much structured and engaging after the optimization. Gemini has provided us with a very well written product description that is engaging and incorporates many SEO-relevant keywords.
Demo
Below is a short demo of this tool in action:
Monitoring and Logging
To ensure smooth operation and easy troubleshooting, the script creates three essential files:
- products.json: This file maintains a record of all the product IDs that have been successfully processed and optimized. This helps with tracking progress and avoiding redundant processing.
- pages.json: This file maintains a record of all the product pages IDs that have been successfully processed and optimized. This helps in tracking progress and avoiding redundant processing if the user selects the same page multiple times in the UI.
- logs.json: This file serves as a logbook, capturing any errors or failures encountered during the optimization process. For instance, if a product update fails due to an API issue or if Gemini encounters an error, the relevant product ID and error message are recorded in this file.
How to Get Started
To use this tool, you’ll need:
- A WooCommerce store with product listings
- A WooCommerce API consumer key and secret.
- A Google Gemini API key.
Step 1: Clone the repository to your working machine.
git clone https://github.com/hbougdal/woocommerce-seo-w-gemini.git
cd woocommerce-seo-w-gemini/
Step 2: Configure the necessary parameters in the config.py file.
#Gemini details
GEMINI_API_KEY = "REPLACE_GEMINI_API_KEY" #Replace
GEMINI_MODEL_TYPEs = ["gemini-1.5-flash"]
#WooCommerce Store details
STORE_URL = "e.g. https://mystore.com/" #Replace
CONSUMER_KEY = "WooCommerce_CONSUMER_KEY" #Replace
CONSUMER_SECRET = "WooCommerce_CONSUMER_SECRET" #Replace
# Output files for persistence
PRODUCTS_FILE_NAME = "products.json"
PAGES_FILE_NAME = "pages.json"
LOGS_FILE = "logs.json"
Step 3: Install dependencies.
python3 -m venv gemini-streamlit
source gemini-streamlit/bin/activate
pip install -r requirements.txt
Step 4: Run the script and access the UI.
streamlit run app.py \
--browser.serverAddress=localhost \
--server.enableCORS=false \
--server.enableXsrfProtection=false \
--server.port 8080
Step 5: Access the frontend page and try it out.
Step 6: Check the result in your WooCommerce store by verifying that product titles and descriptions have been updated.
Step 7: Check the output files products.json, pages.json and logs.json.
Step 8: Repeat the process for other product pages (if needed).
That’s all!
Note: the prompt used for this tutorial can be found in the config.py file. Feel free to edit it and adjust the prompt for your needs.
Future Enhancements
- Image optimization: Use Gemini to generate image captions or alt text.
- Category and tag suggestions: Leverage Gemini to suggest relevant categories and tags for products.
- Add support for more Gemini versions.
- Create a dedicated file for the prompt for easy configuration.
- Provide users with possibility to enter their Gemini API Key and/or WooCommerce API key & secret through the UI.
- Remove processed page IDs from the drop-down list.
- etc.
Conclusion
This tool is a proof-of-concept that demonstrates a possible way of using Gemini for enhancing product listing in a WooCommerce store. This will allow e-Commerce shop owners to free time to focus on other aspects of their business.
I hope you will find this helpful. Let me know if you have any comments or suggestions.
Note this post was initially published in my Medium.com blog.