Реализация экспорта товаров из сайта в Google Merchant Feed
Google Merchant Center принимает фиды в трёх форматах: XML (Atom 1.0 / RSS 2.0), текстовый TSV и API Content v2.1. Для автоматизации на стороне сайта наиболее предсказуем XML-формат или прямая интеграция через REST API. Ошибки в фиде ведут к дисапруву товаров и отключению торговых кампаний в Google Ads.
Форматы и требования
Google использует стандарт атрибутов, задокументированный в Product data specification. Обязательные атрибуты для большинства стран:
| Атрибут | Описание | Пример |
|---|---|---|
id |
Уникальный идентификатор | SKU-12345 |
title |
Название до 150 символов | Samsung Galaxy S24 256GB Black |
description |
До 5000 символов | Развёрнутое описание |
link |
Полный URL товара | https://example.com/product/123 |
image_link |
Основное изображение | https://cdn.example.com/img.jpg |
availability |
in_stock / out_of_stock / preorder |
in_stock |
price |
С указанием валюты | 29990 RUB |
brand |
Бренд | Samsung |
gtin |
Штрихкод EAN/UPC (если есть) | 4895183805887 |
condition |
new / refurbished / used |
new |
XML-структура фида
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:g="http://base.google.com/ns/1.0">
<channel>
<title>Мой магазин</title>
<link>https://example.com</link>
<description>Product feed</description>
<item>
<g:id>SKU-12345</g:id>
<g:title>Samsung Galaxy S24 256GB Black</g:title>
<g:description>Флагманский смартфон Samsung...</g:description>
<g:link>https://example.com/product/12345</g:link>
<g:image_link>https://cdn.example.com/12345.jpg</g:image_link>
<g:additional_image_link>https://cdn.example.com/12345-2.jpg</g:additional_image_link>
<g:availability>in_stock</g:availability>
<g:price>29990 RUB</g:price>
<g:sale_price>24990 RUB</g:sale_price>
<g:brand>Samsung</g:brand>
<g:gtin>4895183805887</g:gtin>
<g:mpn>SM-S921BZKDSER</g:mpn>
<g:condition>new</g:condition>
<g:product_type>Электроника > Смартфоны</g:product_type>
<g:google_product_category>267</g:google_product_category>
<g:color>Чёрный</g:color>
<g:size>One Size</g:size>
<g:item_group_id>GALAXY-S24</g:item_group_id>
<g:shipping>
<g:country>RU</g:country>
<g:service>Курьерская доставка</g:service>
<g:price>350 RUB</g:price>
</g:shipping>
</item>
</channel>
</rss>
Атрибут item_group_id критичен для товаров с вариациями — он группирует варианты (цвет, размер) в одну карточку в Shopping.
Google Product Category (GPC)
Google требует числовой код из официальной таксономии. Для интернет-магазина необходима таблица маппинга внутренних категорий на GPC-коды:
class GoogleCategoryMapper
{
private array $mapping = [
'smartphones' => 267, // Electronics > Communications > Phones
'laptops' => 328, // Electronics > Computers > Laptops
'headphones' => 232, // Electronics > Audio > Headphones
'shoes-men' => 187, // Apparel > Shoes > Men
'refrigerators' => 4356, // Appliances > Kitchen Appliances > Refrigerators
];
public function map(Category $category): ?int
{
// Поиск по slug категории или её предкам
$slugs = $category->ancestors()->pluck('slug')->push($category->slug);
foreach ($slugs->reverse() as $slug) {
if (isset($this->mapping[$slug])) {
return $this->mapping[$slug];
}
}
return null; // Google допускает отсутствие GPC, но снижает качество фида
}
}
Генератор фида
class GoogleMerchantFeedBuilder
{
public function build(string $outputPath): void
{
$writer = new XMLWriter();
$writer->openUri($outputPath);
$writer->startDocument('1.0', 'UTF-8');
$writer->startElement('rss');
$writer->writeAttribute('version', '2.0');
$writer->writeAttribute('xmlns:g', 'http://base.google.com/ns/1.0');
$writer->startElement('channel');
$this->writeChannelMeta($writer);
Product::with(['category.ancestors', 'brand', 'images', 'variants'])
->active()
->hasPrice()
->chunk(500, function ($products) use ($writer) {
foreach ($products as $product) {
// Если у товара есть варианты — экспортируем каждый
if ($product->variants->isNotEmpty()) {
foreach ($product->variants as $variant) {
$this->writeVariantItem($writer, $product, $variant);
}
} else {
$this->writeItem($writer, $product);
}
}
});
$writer->endElement(); // channel
$writer->endElement(); // rss
$writer->endDocument();
$writer->flush();
}
private function writeItem(XMLWriter $w, Product $p): void
{
$w->startElement('item');
$w->writeElement('g:id', $p->sku);
$w->writeElement('g:title', $this->sanitizeTitle($p->name));
$w->writeElement('g:description', strip_tags($p->description));
$w->writeElement('g:link', route('product.show', $p->slug));
$w->writeElement('g:image_link', $p->mainImage()?->url ?? '');
$w->writeElement('g:availability', $p->in_stock ? 'in_stock' : 'out_of_stock');
$w->writeElement('g:price', number_format($p->price, 2, '.', '') . ' RUB');
if ($p->sale_price) {
$w->writeElement('g:sale_price', number_format($p->sale_price, 2, '.', '') . ' RUB');
}
$w->endElement();
}
private function sanitizeTitle(string $title): string
{
// Google запрещает заглавные буквы в заголовках целиком
// и спецсимволы рекламного характера
$title = preg_replace('/[!]{2,}/', '!', $title);
return mb_substr($title, 0, 150);
}
}
Загрузка через Content API v2.1
Для крупных каталогов и мгновенного обновления цен/остатков предпочтительнее API:
use Google\Service\ShoppingContent;
class GoogleContentApiUploader
{
private ShoppingContent $service;
private string $merchantId;
public function batchUpsert(Collection $products): void
{
$entries = $products->map(fn($p) => [
'batchId' => $p->id,
'merchantId' => $this->merchantId,
'method' => 'insert',
'product' => $this->toApiProduct($p),
])->values()->toArray();
// Максимум 1000 товаров за запрос
foreach (array_chunk($entries, 1000) as $batch) {
$this->service->products->custombatch([
'entries' => $batch,
]);
}
}
}
API-интеграция позволяет обновлять цену и остаток за считанные минуты без ожидания переобхода файла.
Диагностика дисапрувов
Типичные причины отклонения товаров:
-
Missing GTIN — для брендовых товаров Google требует GTIN; решение: заполнить поле или выставить
identifier_exists: false - Promotional overlay on image — изображение с текстом/watermark; нужно чистое фото товара
- Price mismatch — цена в фиде отличается от цены на странице; нужна синхронизация
- Unsupported language — описание не на языке целевой страны
Логируйте itemLevelIssues из ответа API для автоматического выявления проблем:
$response = $this->service->products->get($this->merchantId, "online:ru:RU:{$sku}");
foreach ($response->getItemLevelIssues() as $issue) {
Log::warning('GMC issue', [
'sku' => $sku,
'code' => $issue->getCode(),
'servability' => $issue->getServability(), // 'disapproved' | 'demoted'
'description' => $issue->getDescription(),
]);
}
Сроки реализации
- Генератор XML-фида с базовыми атрибутами: 1 день
- Маппинг GPC + атрибуты вариантов: +1 день
- Интеграция Content API v2.1: +1–2 дня
- Логирование дисапрувов и алерты: +0.5 дня
Типовой проект без API-интеграции: 2 рабочих дня.







