Migrar o relatório de itens mais vendidos

Este documento ajuda você a migrar da versão mais antiga dos relatórios de mais vendidos para a versão mais recente. A versão mais antiga do relatório que exporta as tabelas BestSellers_TopBrands_, BestSellers_TopProducts_ e BestSellers_TopProducts_Inventory_ será descontinuada em 1º de setembro de 2025.

O novo relatório "Mais vendidos" oferece o seguinte:

Tabelas exportadas por relatórios antigos e novos

A tabela a seguir compara as tabelas exportadas pelos relatórios antigos e novos:

Relatório antigo Novo relatório
BestSellers_TopBrands BestSellersBrandWeekly e BestSellersBrandMonthly
BestSellers_TopProducts BestSellersProductClusterWeekly e BestSellersProductClusterMonthly
BestSellers_TopProducts_Inventory BestSellersEntityProductMapping

O relatório antigo contém uma única agregação de dados de itens mais vendidos em um período não especificado. O novo relatório fornece as agregações semanais e mensais mais recentes desses dados no momento da solicitação.

Comparar BestSellers_TopBrands com BestSellersBrandWeekly e BestSellersBrandMonthly

A tabela a seguir ajuda a identificar campos na tabela BestSellers_TopBrands que têm substituições equivalentes nas tabelas BestSellersBrandWeekly e BestSellersBrandMonthly. As substituições de alguns campos da tabela antiga não estão disponíveis.

BestSellers_TopBrands (antigo) BestSellersBrandWeekly e BestSellersBrandMonthly (novos)
rank_timestamp _PARTITIONDATE e _PARTITIONTIME
brand brand
google_brand_id
ranking_category category_id
ranking_category_path.locale
ranking_category_path.name
ranking_country country_code
rank_id
rank rank
previous_rank previous_rank
relative_demand.bucket relative_demand
relative_demand.min
relative_demand.max
previous_relative_demand.bucket previous_relative_demand
previous_relative_demand.min
previous_relative_demand.max
relative_demand_change

Comparar BestSellers_TopProducts com BestSellersProductClusterWeekly e BestSellersProductClusterMonthly

A tabela a seguir ajuda a identificar campos na tabela BestSellers_TopProducts que têm substituições equivalentes nas tabelas BestSellersProductClusterWeekly e BestSellersProductClusterMonthly. As substituições de alguns campos da tabela antiga não estão disponíveis.

BestSellers_TopProducts (antigo) BestSellersProductClusterWeekly e BestSellersProductClusterMonthly (novos)
rank_timestamp _PARTITIONDATE e _PARTITIONTIME
rank_id entity_id
rank rank
previous_rank previous_rank
ranking_country country_code
ranking_category report_category_id
ranking_category_path.locale
ranking_category_path.name
relative_demand.bucket relative_demand
relative_demand.min
relative_demand.max
previous_relative_demand.bucket previous_relative_demand
previous_relative_demand.min
previous_relative_demand.max
relative_demand_change
product_title.locale
product_title.name title (título único em vez de uma matriz para cada localidade)
gtins variant_gtins
google_brand_id
brand brand
google_product_category
category_l1, category_l2, category_l3, category_l4, category_l5
google_product_category_path.locale
google_product_category_path.name
price_range.min price_range.min_amount_micros
price_range.max price_range.max_amount_micros
price_range.currency price_range.currency_code
product_inventory_status
brand_inventory_status

Mapeamento de inventário dos dados de itens mais vendidos

No relatório "Mais vendidos" antigo, os dados são mapeados para os dados de inventário do comerciante em uma nova tabela gerada, usando a coluna rank_id da tabela TopProducts.

No novo relatório de mais vendidos, a coluna entity_id é exportada nas tabelas BestSellersProductCluster, que são mapeadas para todos os IDs de produtos do inventário do comerciante na tabela BestSellersEntityProductMapping.

BestSellers_TopProductsInventory (antigo) BestSellersEntityProductMapping (novo)
rank_id (encontrado em BestSellers_TopProducts) entity_id (encontrado nas tabelas BestSellersProductClustersWeekly e BestSellersProductClustersMonthly)
product_id product_id
merchant_id
aggregator_id

Exemplo de consultas

Esta seção destaca as mudanças em exemplos de consultas usadas para extrair dados de produtos mais vendidos.

Exemplo 1: extrair os principais produtos de uma determinada categoria e país

As consultas a seguir retornam os principais produtos para uma determinada categoria e país.

Usar a tabela BestSellers_TopProducts (antiga)

SELECT
  rank,
  previous_rank,
  relative_demand.bucket,
  (SELECT name FROM top_products.product_title WHERE locale = 'en-US') AS product_title,
  brand,
  price_range,
  google_product_category
FROM
  `DATASET.BestSellers_TopProducts_MERCHANT_ID` AS top_products
WHERE
  _PARTITIONDATE = 'DATE' AND
  ranking_category = 267 /*Smartphones*/ AND
  ranking_country = 'US'
ORDER BY
  rank;

Use a tabela BestSellersProductClusterWeekly ou BestSellersProductClusterMonthly (nova)

SELECT
  rank,
  previous_rank,
  relative_demand,
  title AS product_title,
  brand,
  price_range,
  category_l1,
  category_l2
FROM
  `DATASET.BestSellersProductClusterWeekly_MERCHANT_ID` AS top_products
WHERE
  _PARTITIONDATE = 'DATE' AND
  report_category_id = 267 /*Smartphones*/ AND
  country_code = 'US'
ORDER BY
  rank;

Exemplo 2: recuperar os principais produtos do seu inventário

As consultas a seguir retornam uma lista dos principais produtos no seu inventário.

Usar a tabela BestSellers_TopProducts (antiga)

WITH latest_top_products AS
(
  SELECT
    *
  FROM
    `DATASET.BestSellers_TopProducts_MERCHANT_ID`
  WHERE
    _PARTITIONDATE = 'DATE'
),
latest_top_products_inventory AS
(
  SELECT
    *
  FROM
    `DATASET.BestSellers_TopProducts_Inventory_MERCHANT_ID`
  WHERE
    _PARTITIONDATE = 'DATE'
)
SELECT
  top_products.rank,
  inventory.product_id,
  (SELECT ANY_VALUE(name) FROM top_products.product_title) AS product_title,
  top_products.brand,
  top_products.gtins
FROM
  latest_top_products AS top_products
INNER JOIN
  latest_top_products_inventory AS inventory
USING (rank_id);

Use a tabela BestSellersProductClusterWeekly ou BestSellersProductClusterMonthly (nova)

WITH latest_top_products AS
(
  SELECT
    *
  FROM
    `DATASET.BestSellersProductClusterWeekly_MERCHANT_ID`
  WHERE
    _PARTITIONDATE = 'DATE'
),
latest_top_products_inventory AS
(
  SELECT
    *
  FROM
    `DATASET.BestSellersEntityProductMapping_MERCHANT_ID`
  WHERE
    _PARTITIONDATE = 'DATE'
)
SELECT
  top_products.rank,
  inventory.product_id,
  top_products.title AS product_title,
  top_products.brand,
  top_products.variant_gtins
FROM
  latest_top_products AS top_products
INNER JOIN
  latest_top_products_inventory AS inventory
USING (entity_id);

Além disso, se você quiser encontrar o número de produtos ou marcas mais vendidos no seu inventário, execute uma consulta nas tabelas BestSellerProductClusterWeekly ou BestSellerProductClusterMonthly usando as colunas product_inventory_status ou brand_inventory_status. Confira o exemplo de consulta a seguir:

SELECT
  *
FROM
  `DATASET.BestSellersProductClusterMonthly_MERCHANT_ID`
WHERE
  _PARTITIONDATE = 'DATE' AND
  product_inventory_status != 'NOT_IN_INVENTORY'
ORDER BY
  rank;

Exemplo 3: extrair as principais marcas de uma determinada categoria e país

As consultas a seguir retornam uma lista das principais marcas para uma determinada categoria e país.

Usar a tabela BestSellers_TopBrands (antiga)

SELECT
  rank,
  previous_rank,
  brand
FROM
  `DATASET.BestSellers_TopBrands_MERCHANT_ID`
WHERE
  _PARTITIONDATE = 'DATE' AND
  ranking_category = 267 /*Smartphones*/ AND
  ranking_country = 'US'
ORDER BY
  rank;

Use a tabela BestSellersTopBrandsWeekly ou BestSellersTopBrandsMonthly (nova)

SELECT
  rank,
  previous_rank,
  brand
FROM
  `DATASET.BestSellersTopBrandsWeekly_MERCHANT_ID`
WHERE
  _PARTITIONDATE = 'DATE' AND
  report_category_id = 267 /*Smartphones*/ AND
  country_code = 'US'
ORDER BY
  rank;

Exemplo 4: recuperar produtos das principais marcas no seu inventário

As consultas a seguir retornam uma lista de produtos das principais marcas no seu inventário.

Usar a tabela BestSellers_TopBrands (antiga)

WITH latest_top_brands AS
  (
    SELECT
      *
    FROM
      `DATASET.BestSellers_TopBrands_MERCHANT_ID`
    WHERE
      _PARTITIONDATE = 'DATE'
  ),
  latest_products AS
  (
    SELECT
      product.*,
      product_category_id
    FROM
      `DATASET.Products_MERCHANT_ID` AS product,
      UNNEST(product.google_product_category_ids) AS product_category_id,
      UNNEST(destinations) AS destination,
      UNNEST(destination.approved_countries) AS approved_country
    WHERE
      _PARTITIONDATE = 'DATE'
  )
SELECT
  top_brands.brand,
  (SELECT name FROM top_brands.ranking_category_path
  WHERE locale = 'en-US') AS ranking_category,
  top_brands.ranking_country,
  top_brands.rank,
  products.product_id,
  products.title
FROM
  latest_top_brands AS top_brands
INNER JOIN
  latest_products AS products
ON top_brands.google_brand_id = products.google_brand_id AND
   top_brands.ranking_category = product_category_id AND
   top_brands.ranking_country = products.approved_country;

Use a tabela BestSellersTopBrandsWeekly ou BestSellersTopBrandsMonthly (nova)

WITH latest_top_brands AS
  (
    SELECT
      *
    FROM
      `DATASET.BestSellersBrandMonthly_MERCHANT_ID`
    WHERE
      _PARTITIONDATE = 'DATE'
  ),
  latest_products AS
  (
    SELECT
      product.*,
      product_category_id
    FROM
      `DATASET.Products_MERCHANT_ID` AS product,
      UNNEST(product.google_product_category_ids) AS product_category_id,
      UNNEST(destinations) AS destination,
      UNNEST(destination.approved_countries) AS approved_country
    WHERE
      _PARTITIONDATE = 'DATE'
  )
SELECT
  top_brands.brand,
  - The full category name is not supported in the new BestSellersTopBrands tables.
  - (SELECT name FROM top_brands.ranking_category_path
  - WHERE locale = 'en-US') AS ranking_category,
  top_brands.category_id,
  top_brands.rank,
  products.product_id,
  products.title
FROM
  latest_top_brands AS top_brands
INNER JOIN
  latest_products AS products
ON top_brands.brand = products.brand AND
   top_brands.category_id = product_category_id AND
   top_brands.country_code = products.approved_country;

Nessas consultas, substitua o seguinte:

  • DATASET: o nome do conjunto de dados
  • MERCHANT_ID: o ID da conta do comerciante
  • DATE: a data no formato YYYY-MM-DD

A seguir