Skip to content

programming-with-ia/better-merchant-feed

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Better Merchant Feed

A lightweight, type-safe TypeScript library for generating Google Merchant Center (GMC) XML feeds.

npm version License: MIT

Features

  • 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, and image_link are present.
  • Smart Formatting: Automatic XML escaping and recursive tag generation for nested objects (like shipping and tax).

Installation

npm install better-merchant-feed
# or
pnpm add better-merchant-feed
# or
yarn add better-merchant-feed

Basic Usage

import { 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);

Advanced Usage

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"
  }
];

API Reference

generateGoogleMerchantXml(products, options)

Generates a valid GMC RSS 2.0 feed string.

  • products: Array of GoogleProduct objects.
  • options:
    • title: Channel title.
    • link: Site URL.
    • description: Channel description.

GoogleProduct Type

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_0 to custom_label_4.

License

MIT

About

A lightweight, type-safe TypeScript library for generating Google Merchant Center (GMC) XML feeds.

Topics

Resources

Stars

Watchers

Forks

Contributors