Skip to content

prestarocket-agence/n8n-shopify-seo-product-image-optimizer

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Shopify Images Optimizer

A fully automated workflow combining n8n, a Google Cloud Function, and OpenAI to optimize Shopify product images, generate SEO-friendly alt text, update Google Sheets, and replace images in your Shopify store.

πŸš€ Overview

  1. Extract: Fetch all product images from Shopify via an n8n workflow.
  2. Optimize: Send each image to a GCP Cloud Function that uses sharp to convert and compress images to WebP.
  3. Upload: Store optimized images in a Google Cloud Storage (GCS) bucket.
  4. Alt Text: Generate concise alt text using OpenAI for accessibility and SEO.
  5. Google Sheets: Log and track original and optimized image URLs along with generated alt text.
  6. Shopify Update: Replace old product images in Shopify with optimized versions and clean up originals.

πŸ“‚ Project Structure

shopify-images-optimizer/
β”œβ”€β”€ GCPCloudFunction/        # Cloud Function source code
β”‚   β”œβ”€β”€ index.js             # HTTP-triggered image optimizer
β”‚   β”œβ”€β”€ package.json         # dependencies and scripts
β”‚   └── readme.md            # Cloud Function-specific instructions
β”œβ”€β”€ GoogleSheets/            # Google Sheets template file
β”‚   └── n8n-shopify-product-image-optimizer.xlsx
└── n8n/                     # n8n workflow definition
    └── n8n-shopify-image-optimizer.json

βœ… Prerequisites

  • Node.js v22+ and npm
  • Google Cloud project with:
    • Cloud Functions API enabled
    • Cloud Storage bucket for optimized images
    • Service account JSON key with Storage Object Admin role
  • n8n instance (desktop, cloud, or self-hosted)
  • Shopify Admin API access token
  • OpenAI API key
  • Google Sheets OAuth2 credentials

βš™οΈ Setup Guide

1. Deploy the GCP Cloud Function

cd GCPCloudFunction
npm install
# For local testing
export BUCKET_NAME=<your-gcs-bucket>
export GOOGLE_APPLICATION_CREDENTIALS=<path-to-service-account.json>
npm start

To deploy via gcloud:

gcloud functions deploy optimizeImage \
  --runtime nodejs22 \
  --trigger-http \
  --allow-unauthenticated \
  --set-env-vars BUCKET_NAME=<your-gcs-bucket> \
  --service-account <your-service-account>@<project>.iam.gserviceaccount.com

Take note of the function URL (e.g., https://REGION-PROJECT.cloudfunctions.net/optimizeImage).

2. Configure Google Sheets

  1. Make a copy of GoogleSheets/n8n-shopify-product-image-optimizer.xlsx in your Google Drive.
  2. Share it with your n8n Google Sheets OAuth2 service account.
  3. Note the Spreadsheet ID and Sheet GID or just click on the node in n8n to select the sheet.

3. Import & Configure n8n Workflow

  1. Open your n8n editor and Import n8n/n8n-shopify-image-optimizer.json.
  2. Set up the following credentials in n8n:
    • Shopify Access Token
    • OpenAI API Key
    • Google Sheets OAuth2
  3. Under Workflow Settings or the first HTTP Request node, set the following environment variables:
    • CLOUD_FUNCTION_URL – the URL of your deployed optimizeImage function
    • SHOPIFY_STORE_ID – your Shopify store subdomain

πŸƒ Usage

  • Manual Trigger: Run the workflow on-demand via the manual trigger node in n8n.
  • Scheduling: Use n8n’s Cron or schedule node to run periodically.

Upon execution, the workflow will:

  1. Retrieve all products from Shopify.
  2. Loop through each image, check if it’s already optimized in Google Sheets.
  3. Download and optimize via the GCP Function if needed.
  4. Generate alt text with OpenAI.
  5. Upload optimized images to GCS and update Google Sheets.
  6. Replace the original image in Shopify and remove the old one.

πŸ“ˆ Monitoring & Logs

  • n8n Executions: Monitor successful and failed executions in the n8n dashboard.
  • Cloud Function Logs: View logs via Google Cloud Console under Cloud Functions > Logs.
  • Google Sheets: Check the Google Sheets for a log of processed images, alt text, and URLs.

πŸ”§ Customization

  • Adjust sharp settings in GCPCloudFunction/index.js to change quality or output format.
  • Modify alt-text prompts in the OpenAI node within the n8n workflow.
  • Add resizing or watermark steps by extending the n8n image editing nodes.

About

N8N flow with AI to optimize product images from products in Shopify store and create SEO optimized alt tag

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%