A lightweight, type-safe TypeScript library for generating Google Merchant Center (GMC) XML feeds.
- Type-Safe: Built with TypeScript for full IntelliSense support.
- Google Merchant Center Ready: Automatically handles standard RSS and
g:prefixed tags. - Easy Integration: Perfect for Next.js, Vite, or any Node.js environment.
- Robust Validation: Ensures required fields like
id,title,price,link, andimage_linkare present. - Smart Formatting: Automatic XML escaping and recursive tag generation for nested objects (like
shippingandtax).
npm install better-merchant-feed
# or
pnpm add better-merchant-feed
# or
yarn add better-merchant-feedimport { generateGoogleMerchantXml, type GoogleProduct } from 'better-merchant-feed';
const products: GoogleProduct[] = [
{
id: "PROD-123",
title: "Awesome T-Shirt",
description: "The best t-shirt you will ever wear.",
link: "https://example.com/products/awesome-tshirt",
image_link: "https://example.com/images/tshirt.jpg",
availability: "in stock",
price: "25.00 USD",
condition: "new",
brand: "MyBrand",
gtin: "1234567890123"
}
];
const xml = generateGoogleMerchantXml(products, {
title: "My Online Store",
link: "https://example.com",
description: "Official Product Feed"
});
console.log(xml);The library supports complex GMC fields like variants, shipping rules, and custom labels.
const products: GoogleProduct[] = [
{
id: "SHOE-001-RED-8",
item_group_id: "SHOE-001", // For variants
title: "Running Shoes - Red, Size 8",
description: "Breathable mesh running shoes.",
link: "https://example.com/shoes?color=red&size=8",
image_link: "https://example.com/images/shoe-red.jpg",
availability: "in stock",
price: "79.99 USD",
sale_price: "59.99 USD",
condition: "new",
brand: "SpeedStep",
color: "Red",
size: "8",
shipping: [
{ country: "US", service: "Standard", price: "4.99 USD" }
],
custom_label_0: "Summer Sale"
}
];Generates a valid GMC RSS 2.0 feed string.
products: Array ofGoogleProductobjects.options:title: Channel title.link: Site URL.description: Channel description.
A comprehensive interface covering required and optional GMC attributes:
id,title,description,link,image_link,availability,price,condition(Required).brand,gtin,mpn,identifier_exists.google_product_category,product_type.item_group_id,color,size,gender,age_group.shipping,tax.sale_price,sale_price_effective_date.custom_label_0tocustom_label_4.
MIT