使用促销活动来展示您在 Google 上销售的商品的特别优惠。 促销活动会展示在各种 Google 产品和服务中,包括 Google 搜索、购物和 Chrome。促销活动必须符合特定条件才能获得批准。如需了解详情,请参阅促销活动条件 。
当您为商品添加促销活动时,买家会看到一个特别优惠链接。 例如,“八五折”或“免运费”。优惠链接可提高商品的吸引力,并鼓励买家购买。所有促销优惠均在结账时或在销售终端应用。
如需了解详情,请参阅促销活动 基础知识。
前提条件
Google 需要您提供有关您的商家和商品的具体信息,然后才会显示您的促销活动。您必须具备以下条件:
- Google Merchant Center 中有有效的 商品 Feed。
- Google Merchant Center 中有有效的 促销活动 Feed。
- 有用于 购物 广告系列的 Google Ads 账号 。
此外,您还必须在促销活动计划中注册您的 Merchant Center 账号。如果您不确定自己是否已注册,请查看 Merchant Center。
如果您尚未注册,请填写申请 表单。当您可以开始使用时,促销活动团队会通知您。
如需了解详情,请参阅参与条件和 政策。
创建数据源
您可以使用
accounts.dataSources.create
方法创建促销活动数据源。如果有现有的促销活动数据源
可用,请使用
accounts.dataSources.list
方法检索所有数据源。然后,您可以使用促销活动数据源的 name 字段
创建促销活动。
以下请求展示了如何创建用于添加促销活动的数据源:
POST https://merchantapi.googleapis.com/datasources/v1/accounts/{ACCOUNT_ID}/dataSources
{
"displayName": "{DISPLAY_NAME}",
"promotionDataSource": {
"contentLanguage": "{CONTENT_LANGUAGE}",
"targetCountry": "{TARGET_COUNTRY}"
}
}
替换以下内容:
- {ACCOUNT_ID}:您的 账号在 Merchant Center 界面中显示的唯一标识符。
- {DISPLAY_NAME}:数据 源的显示名称。
- {CONTENT_LANGUAGE}:数据源中商品的双字母 ISO 639-1 语言代码。
- {TARGET_COUNTRY}:您希望促销活动在其中显示的 投放国家/地区的 CLDR 地区代码。
请求成功运行后,您会看到以下响应,其中包含有关新创建的促销活动数据源的详细信息:
{
"name": "accounts/{ACCOUNT_ID}/dataSources/{DATASOURCE_ID}",
"dataSourceId": "{DATASOURCE_ID}",
"displayName": "{DISPLAY_NAME}",
"promotionDataSource": {
"targetCountry": "{TARGET_COUNTRY}",
"contentLanguage": "{CONTENT_LANGUAGE}"
},
"input": "API"
}
创建促销活动
您可以使用
accounts.promotions.insert
方法创建或更新促销活动。accounts.promotions.insert 方法
会接受
promotions
资源和数据源名称作为输入。如果成功,该方法会返回新的或更新后的促销活动。
创建促销活动需要提供数据 源的名称。 您还必须在请求中为以下字段提供值:
contentLanguageredemptionChannelpromotionIdtargetCountryattributes.offerTypeattributes.genericRedemptionCodeattributes.couponValueTypeattributes.productApplicabilityattributes.promotionEffectiveTimePeriod.endTimeattributes.promotionEffectiveTimePeriod.startTimeattributes.longTitle
Google 会先审核和批准您的促销活动,然后再发布这些促销活动。如需了解更多 信息,请参阅促销活动审批 流程。
我们建议您仔细阅读促销活动 政策,确保您创建的 促销活动能够增加价值并符合购物广告政策。
以下请求演示了如何创建在线促销活动:
HTTP
POST https://merchantapi.googleapis.com/promotions/v1/accounts/{ACCOUNT_ID}/promotions:insert
{
"promotion": {
"name": "{PROMOTION_NAME}",
"promotionId": "{PROMOTION_ID}",
"targetCountry": "{TARGET_COUNTRY}",
"redemptionChannel": [
"ONLINE"
],
"contentLanguage": "{CONTENT_LANGUAGE}",
"attributes": {
"promotionDisplayTimePeriod": {
"endTime": "{PROMOTION_END_TIME}",
"startTime": "{PROMOTION_START_TIME}"
},
"offerType": "{OFFER_TYPE}",
"longTitle": "{LONG_TITLE}"
}
},
"dataSource": "accounts/{ACCOUNT_ID}/dataSources/{DATASOURCE_ID}"
}
cURL
curl --request POST \
'https://merchantapi.googleapis.com/promotions/v1/accounts/{ACCOUNT_ID}/promotions:insert?key=[YOUR_API_KEY]' \
--header 'Authorization: Bearer {ACCESS_TOKEN}' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{"dataSource":"{DATASOURCE_ID}","promotion":{"name":"accounts/{ACCOUNT_ID}/promotions/{PROMOTION_ID}y","promotionId":"abc","contentLanguage":"en","targetCountry":"US","redemptionChannel":["ONLINE"]}}' \
--compressed
如需了解适用于设置促销 ID 的规则,请参阅 促销 ID 属性的最低要求。
对于强制性 offerType 字段,有效值为 NO_CODE 和 GENERIC_CODE。如果您未提供其中一个值,API 请求会失败
,并返回 HTTP 400 响应 [offer_type] validation/missing_required: Invalid or
missing required attribute: offer_type。如果您未提供任何必填字段,系统也会返回类似错误消息。
如果您未为 attributes.genericRedemptionCode 字段提供值,
请求会失败,并返回 HTTP 400 响应 [genericRedemptionCode] No
redemption code provided。
promotion.attributes.promotionDisplayTimePeriod.startTime
和 promotion.attributes.promotionDisplayTimePeriod.endTime 字段的值必须采用
yyyy-mm-ddThh:mm:ssZ 格式。请务必将这些字段的值替换为未来的日期。
如需了解详情,请参阅促销活动数据 规范。
如需了解创建促销活动的最佳实践,请参阅促销活动最佳 实践。
如需查看与促销活动相关的属性列表,请参阅添加结构化数据 属性。
促销活动创建请求成功运行后,可能需要几分钟时间,才能使用 API 检索促销活动或在 Merchant Center 中显示促销活动。
以下是一个示例,可用于异步插入多个促销活动:
Java
import com.google.api.core.ApiFuture;
import com.google.api.core.ApiFutureCallback;
import com.google.api.core.ApiFutures;
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.protobuf.Timestamp;
import com.google.shopping.merchant.promotions.v1.Attributes;
import com.google.shopping.merchant.promotions.v1.CouponValueType;
import com.google.shopping.merchant.promotions.v1.InsertPromotionRequest;
import com.google.shopping.merchant.promotions.v1.OfferType;
import com.google.shopping.merchant.promotions.v1.ProductApplicability;
import com.google.shopping.merchant.promotions.v1.Promotion;
import com.google.shopping.merchant.promotions.v1.PromotionsServiceClient;
import com.google.shopping.merchant.promotions.v1.PromotionsServiceSettings;
import com.google.shopping.merchant.promotions.v1.RedemptionChannel;
import com.google.shopping.type.CustomAttribute;
import com.google.shopping.type.Destination.DestinationEnum;
import com.google.type.Interval;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;
/** This class demonstrates how to insert multiple promotions asynchronously. */
public class InsertPromotionsAsyncSample {
private static String generateRandomString() {
String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
Random random = new Random();
StringBuilder sb = new StringBuilder(8);
for (int i = 0; i < 8; i++) {
sb.append(characters.charAt(random.nextInt(characters.length())));
}
return sb.toString();
}
private static Promotion createPromotion(String accountId) {
String merchantPromotionId = generateRandomString();
Attributes attributes =
Attributes.newBuilder()
.setProductApplicability(ProductApplicability.ALL_PRODUCTS)
.setOfferType(OfferType.GENERIC_CODE)
.setGenericRedemptionCode("ABCD1234")
.setLongTitle("My promotion")
.setCouponValueType(CouponValueType.PERCENT_OFF)
.addPromotionDestinations(DestinationEnum.SHOPPING_ADS)
.setPercentOff(10)
// Note that promotions have a 6-month limit.
// For more information, read here: https://support.google.com/merchants/answer/2906014
// Also note that only promotions valid within the past 365 days are shown in the UI.
.setPromotionEffectiveTimePeriod(
Interval.newBuilder()
.setStartTime(Timestamp.newBuilder().setSeconds(1726842472))
.setEndTime(Timestamp.newBuilder().setSeconds(1726842473))
.build())
.build();
return Promotion.newBuilder()
.setName(String.format("accounts/%s/merchantPromotions/%s", accountId, merchantPromotionId))
.setPromotionId(merchantPromotionId)
.setContentLanguage("fr")
.setTargetCountry("CH")
.addRedemptionChannel(RedemptionChannel.ONLINE)
.setAttributes(attributes)
// Custom attributes allow you to add additional information which is not available in
// Attributes. For example, you might want to pilot experimental functionality.
.addCustomAttributes(
CustomAttribute.newBuilder()
.setName("another example name")
.setValue("another example value")
.build())
.build();
}
public static void asyncInsertPromotions(String accountId, String dataSourceId) throws Exception {
GoogleCredentials credential = new Authenticator().authenticate();
// Creates a channel provider. This provider manages a pool of gRPC channels
// to enhance throughput for bulk operations. Each individual channel in the pool
// can handle up to approximately 100 concurrent requests.
//
// Channel: A single connection pathway to the service.
// Pool: A collection of multiple channels managed by this provider.
// Requests are distributed across the channels in the pool.
//
// We recommend estimating the number of concurrent requests you'll make, divide by 50 (50%
// utilization of channel capacity), and set the pool size to that number.
InstantiatingGrpcChannelProvider channelProvider =
InstantiatingGrpcChannelProvider.newBuilder().setPoolSize(30).build();
PromotionsServiceSettings merchantPromotionsServiceSettings =
PromotionsServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.setTransportChannelProvider(channelProvider)
.build();
try (PromotionsServiceClient merchantPromotionsServiceClient =
PromotionsServiceClient.create(merchantPromotionsServiceSettings)) {
// Arbitrarily creates five merchant promotions with random IDs.
List<InsertPromotionRequest> requests = new ArrayList<>();
for (int i = 0; i < 5; i++) {
InsertPromotionRequest request =
InsertPromotionRequest.newBuilder()
.setParent(String.format("accounts/%s", accountId))
.setPromotion(createPromotion(accountId))
.setDataSource(String.format("accounts/%s/dataSources/%s", accountId, dataSourceId))
.build();
requests.add(request);
}
// Inserts the merchant promotions.
List<ApiFuture<Promotion>> futures =
requests.stream()
.map(
request ->
merchantPromotionsServiceClient.insertPromotionCallable().futureCall(request))
.collect(Collectors.toList());
// Creates callback to handle the responses when all are ready.
ApiFuture<List<Promotion>> responses = ApiFutures.allAsList(futures);
ApiFutures.addCallback(
responses,
new ApiFutureCallback<List<Promotion>>() {
@Override
public void onSuccess(List<Promotion> results) {
System.out.println("Inserted merchant promotions below:");
System.out.println(results);
}
@Override
public void onFailure(Throwable throwable) {
System.out.println(throwable);
}
},
MoreExecutors.directExecutor());
} catch (Exception e) {
System.out.println(e);
}
}
public static void main(String[] args) throws Exception {
Config config = Config.load();
asyncInsertPromotions(config.getAccountId().toString(), "<YOUR_DATA_SOURCE_ID>");
}
}
以下是一些示例促销活动,可供您入门。
适用于所有商品和所有商店的本地促销活动
以下示例请求展示了如何创建适用于 Merchant Center 账号中的所有商品以及关联的 商家资料账号中添加的所有商店的本地促销活动。
POST https://merchantapi.googleapis.com/promotions/v1/accounts/{ACCOUNT_ID}/promotions:insert
{
"promotion": {
"promotionId": "buy_2_get_10_off",
"contentLanguage": "en",
"targetCountry": "US",
"redemptionChannel": [
"IN_STORE"
],
"attributes": {
"longTitle": "Buy 2 and get 10$ OFF purchase",
"productApplicability": "ALL_PRODUCTS",
"offerType": "NO_CODE",
"couponValueType": "BUY_M_GET_MONEY_OFF",
"promotionDisplayTimePeriod": {
"startTime": "2024-2-06T00:47:44Z",
"endTime": "2024-5-06T00:47:44Z"
},
"promotionEffectiveTimePeriod": {
"startTime": "2024-2-06T00:47:44Z",
"endTime": "2024-5-06T00:47:44Z"
},
"moneyOffAmount": {
"amountMicros": "1000000",
"currencyCode": "USD"
},
"minimumPurchaseQuantity": 2,
"storeApplicability": "ALL_STORES",
"promotionUrl": "http://promotionnew4url.com/",
"promotionDestinations": [
"LOCAL_INVENTORY_ADS"
],
}
},
"dataSource": "accounts/{ACCOUNT_ID}/dataSources/{DATASOURCE_ID}"
}
productApplicability 字段是必填字段。它表示促销活动适用于所有商品还是仅适用于特定商品。支持的值为
ALL_PRODUCTS 和 SPECIFIC_PRODUCTS。如需了解详情,请参阅为促销活动选择商品。
couponValueType 字段是必填字段。它表示您要开展的促销活动类型。如需查看支持的值列表,请参阅优惠券值
类型。根据您选择的
优惠券值类型,某些属性是
必需的。
借助 minimumPurchaseQuantity 字段,您可以设置兑换促销优惠所需的最低购买数量的值。如需了解详情,请参阅促销活动的最低购买数量。
同样,您可以使用 minimumPurchaseAmount 字段设置兑换促销优惠所需的最低购买金额。如需了解详情,
请参阅 最低交易额。
如需详细了解创建本地 促销活动时需要提供的值,请参阅本地 促销活动的数据源规范。
适用于选定商品且需要兑换码的在线促销活动
以下示例请求展示了如何创建适用于选定商品且需要兑换码的在线促销活动。
POST https://merchantapi.googleapis.com/promotions/v1/accounts/{ACCOUNT_ID}/promotions:insert
{
"promotion": {
"promotionId": "25_pct_off",
"contentLanguage": "en",
"targetCountry": "US",
"redemptionChannel": [
"ONLINE"
],
"attributes": {
"longTitle": "10% off on selected items",
"productApplicability": "SPECIFIC_PRODUCTS",
"offerType": "GENERIC_CODE",
"genericRedemptionCode": "SPRINGSALE",
"couponValueType": "PERCENT_OFF",
"promotionDisplayTimePeriod": {
"startTime": "2024-2-06T00:47:44Z",
"endTime": "2024-5-06T00:47:44Z"
},
"promotionEffectiveTimePeriod": {
"startTime": "2024-2-06T00:47:44Z",
"endTime": "2024-5-06T00:47:44Z"
},
"percentOff": 25,
"promotionDestinations": [
"FREE_LISTINGS"
],
"itemIdInclusion": [
"1499860100",
"1499860101",
"1499860102",
"1499860103",
"1499860104"
],
}
},
"dataSource": "accounts/{ACCOUNT_ID}/dataSources/1000000573361824"
}
查看促销活动
如需查看促销活动,请使用
accounts.promotions.get。
此 GET 请求是只读的。它需要您的
merchantId 和促销活动的 ID。GET 方法会返回相应的促销活动资源。
例如:
HTTP
GET https://merchantapi.googleapis.com/promotions/v1/accounts/{ACCOUNT_ID}/promotions/{PROMOTION_ID}
cURL
curl \
'https://merchantapi.googleapis.com/promotions/v1/accounts/{ACCOUNT_ID}/promotions/{PROMOTION_ID}?key=[YOUR_API_KEY]' \
--header 'Authorization: Bearer {ACCESS_TOKEN}' \
--header 'Accept: application/json' \
--compressed
替换以下内容:
- {ACCOUNT_ID}:您的 Merchant Center 账号的唯一标识符。
- {PROMOTION_ID}:您要检索的 促销活动的唯一标识符。格式为 {CHANNEL} ~{CONTENT_LANGUAGE}~ {TARGET_COUNTRY}~{PROMOTION_ID} 。
请注意,新创建的促销活动需要几分钟时间才能使用 API 检索。
查看本地促销活动
以下示例请求会检索促销 ID 为 in_store~en~US~buy_2_get_10_off 的本地促销活动。
GET https://merchantapi.googleapis.com/promotions/v1/accounts/{ACCOUNT_ID}/promotions/in_store~en~US~buy_2_get_10_off
请求成功后,您会看到以下响应:
{
"name": "accounts/{ACCOUNT_ID}/promotions/in_store~en~US~buy_2_get_10_off",
"promotionId": "buy_2_get_10_off",
"contentLanguage": "en",
"targetCountry": "US",
"redemptionChannel": [
"IN_STORE"
],
"attributes": {
"longTitle": "Buy 2 and get 10$ OFF purchase",
"productApplicability": "ALL_PRODUCTS",
"offerType": "NO_CODE",
"couponValueType": "BUY_M_GET_MONEY_OFF",
"promotionDisplayTimePeriod": {
"startTime": "2024-2-06T00:47:44Z",
"endTime": "2024-5-06T00:47:44Z"
},
"promotionEffectiveTimePeriod": {
"startTime": "2024-2-06T00:47:44Z",
"endTime": "2024-5-06T00:47:44Z"
},
"moneyOffAmount": {
"amountMicros": "1000000",
"currencyCode": "USD"
},
"minimumPurchaseQuantity": 2,
"storeApplicability": "ALL_STORES",
"promotionUrl": "http://promotionnew4url.com/",
"promotionDestinations": [
"LOCAL_INVENTORY_ADS"
],
}
"dataSource": "accounts/{ACCOUNT_ID}/dataSources/1000000573361824"
}
此示例中的 moneyOffAmount 字段提供了促销活动中提供的折扣。如需了解详情,请参阅促销活动的
货币折扣金额。
此示例中的 promotionUrl 字段提供了商店网站的链接,买家可以在该网站上找到有关促销活动的更多信息。如果您未添加
promotionUrl 字段,本地商品目录广告促销活动会返回错误。
查看在线促销活动
以下示例请求会检索促销 ID 为 online~en~US~25_pct_off 的在线促销活动。
GET https://merchantapi.googleapis.com/promotions/v1/accounts/{ACCOUNT_ID}/promotions/online~en~US~25_pct_off
{
"name": "accounts/{ACCOUNT_ID}/promotions/online~en~US~25_pct_off",
"promotionId": "25_pct_off",
"contentLanguage": "en",
"targetCountry": "US",
"redemptionChannel": [
"ONLINE"
],
"attributes": {
"longTitle": "10% off on selected items",
"productApplicability": "SPECIFIC_PRODUCTS",
"offerType": "GENERIC_CODE",
"genericRedemptionCode": "WINTERGIFT",
"couponValueType": "PERCENT_OFF",
"promotionDisplayTimePeriod": {
"startTime": "2024-2-06T00:47:44Z",
"endTime": "2024-5-06T00:47:44Z"
},
"promotionEffectiveTimePeriod": {
"startTime": "2024-2-06T00:47:44Z",
"endTime": "2024-5-06T00:47:44Z"
},
"percentOff": 25,
"promotionDestinations": [
"FREE_LISTINGS"
],
"itemIdInclusion": [
"1499860100",
"1499860101",
"1499860102",
"1499860103",
"1499860104"
],
}
"dataSource": "accounts/{ACCOUNT_ID}/dataSources/{dataSource}"
}
此示例中使用的 itemIdInclusion 字段提及了符合促销活动条件的商品。如需了解详情,请参阅促销活动的
商品 ID。
列出促销活动
您可以使用
promotions.list
方法查看所有已创建的促销活动。
以下是一个示例请求:
HTTP
GET https://merchantapi.googleapis.com/promotions/v1/{ACCOUNT_ID}/promotions
cURL
curl \
'https://merchantapi.googleapis.com/promotions/v1/accounts/{ACCOUNT_ID}/promotions?key=[YOUR_API_KEY]' \
--header 'Authorization: Bearer {ACCESS_TOKEN}' \
--header 'Accept: application/json' \
--compressed
响应包含您账号中的所有促销活动列表。对于每个促销活动,您都可以看到详细信息,例如 promotionId、redemptionChannel、dataSource、promotionStatus 等。
查看促销活动的状态
如需查看促销活动的状态,请参阅 promotionStatus 属性,该属性由
promotions.get
或
promotions.list
方法返回。
promotionStatus 字段可以具有以下值:
IN_REVIEW:促销活动仍在审核中。REJECTED:促销活动被拒批。LIVE:促销活动已获批准且处于有效状态。STOPPED:促销活动已由账号停止。EXPIRED:促销活动已失效。PENDING:促销活动未停止,所有审核均已获批,但生效日期在未来。STATE_UNSPECIFIED:促销活动状态未知。
如需了解您创建的促销活动的审批流程,请参阅 促销活动审批 流程。
示例促销活动状态
以下示例演示了成功请求和失败请求之间的区别。
缺少商品映射
以下响应正文显示了因缺少商品映射而被拒批的在线促销活动。
"promotionStatus": {
"destinationStatuses": [
{
"reportingContext": "FREE_LISTINGS",
"status": "REJECTED"
}
],
"itemLevelIssues": [
{
"code": "promotion_sku_unmapped",
"severity": "DISAPPROVED",
"resolution": "merchant_action",
"reportingContext": "FREE_LISTINGS",
"description": "Unmapped",
"detail": "This promotion couldn't be tested during review because it doesn't apply to any products that are currently in your Products feed",
"documentation": "https://support.google.com/merchants/answer/2906014",
"applicableCountries": [
"US"
]
},
{
"code": "promotion_sku_additional_requirements",
"severity": "DISAPPROVED",
"resolution": "merchant_action",
"reportingContext": "FREE_LISTINGS",
"description": "Promotion conditions not allowed",
"detail": "This promotion has additional requirements that are not allowed such as requiring customers to verify additional details like phone number or ID before showing the promotion details",
"documentation": "https://support.google.com/merchants/answer/2906014",
"applicableCountries": [
"US"
]
}
]
}
如需排查被拒批的促销活动并了解如何避免将来被拒批,请参阅解决与促销活动被拒批相关的问题。
如果您创建的促销活动未获批准,您会收到一封电子邮件,其中会提及拒批原因以及解决问题的说明。
促销活动正在评估中
以下响应正文显示了仍在评估中的促销活动。
"promotionStatus": {
"destinationStatuses": [
{
"reportingContext": "FREE_LISTINGS",
"status": "PENDING"
},
{
"destination": "SHOPPING_ADS",
"status": "PENDING"
}
],
"itemLevelIssues": []
}
已获批准且处于有效状态的促销活动
以下响应正文显示了买家可见的促销活动。
"promotionStatus": {
"destinationStatuses": [
{
"reportingContext": "FREE_LISTINGS",
"status": "LIVE"
},
{
"destination": "SHOPPING_ADS",
"status": "LIVE"
} ],
"itemLevelIssues": []
}
如需了解详情,请参阅与促销活动状态 有关的常见问题解答。
删除促销活动
无法使用 API 删除促销活动。如需删除促销活动,您需要访问 Merchant Center 界面。如需了解详情,请参阅 修改促销活动或更改促销活动状态。
如需结束现有促销活动,您可以使用
accounts.promotions.insert
方法将 attributes.promotionEffectiveTimePeriod.endTime 字段更新为
过去的时间。
了解详情
- 如需了解详情,请参阅促销活动帮助 中心。
- 如需排查常见问题,请参阅排查与 促销活动子 API相关的问题。
- 如需了解如何从 Content API for Shopping 迁移,请参阅 迁移 促销活动管理。