与其他素材资源不同,在您创建素材资源集后,Google Ads API 会自动创建地址素材资源。首先,创建一个地址同步素材资源集并将其附加到客户。然后,如果您需要为某个广告系列或广告组选择素材资源集中部分地址素材资源,请创建地址组素材资源集,并将其附加到相应广告系列或广告组。
创建地址同步素材资源集并将其附加到客户
创建营业地点同步素材资源集
- 创建新的
AssetSet
。- 将
type
设置为LOCATION_SYNC
。 - 将
location_set
设置为新的LocationSet
。
- 将
- 在新的
LocationSet
中,- 根据您的使用情形设置
location_ownership_type
:- 如果您拥有相应营业地点,请将其设置为
BUSINESS_OWNER
。 - 如果您不拥有商家营业地点,但会在该地点销售商品,请将此属性设置为
AFFILIATE
。
- 如果您拥有相应营业地点,请将其设置为
- 根据您的使用情形设置
source
oneof 字段:- 如果您想与 Google 商家资料账号中的营业地点同步,请设置为
business_profile_location_set
。 - 如果您想与指定连锁店 ID 中的营业地点同步,请设置
chain_location_set
。 - 如果您想使用地点 ID 手动添加营业地点,请将此属性设置为
maps_location_set
。
- 如果您想与 Google 商家资料账号中的营业地点同步,请设置为
- 根据您的使用情形设置
完成这些步骤后,Google Ads API 会生成地址素材资源,并将其添加到为您创建的地址同步素材资源集中,这与您使用 AssetSetAssetService
手动执行此操作类似。除非您想手动将它们添加到静态位置组素材资源集中,否则无需进行任何操作。
对于一个客户,只能存在一个具有(status
的 ENABLED
)的有效位置同步素材资源集。如果您需要创建其他类型的地址同步素材资源组,请先移除现有的素材资源组。
将位置同步素材资源组附加到客户
使用 CustomerAssetSetService.MutateCustomerAssetSets
将上一部分中设置的营业地点同步素材资源集附加到客户。
(可选)创建营业地点组素材资源集并将其附加到广告系列或广告组
只有在需要选择一部分地址素材资源时,才需要使用营业地点组素材资源集。这是因为广告系列和广告组会沿用客户级地址素材资源。
营业地点组素材资源集包含营业地点同步素材资源集中的一部分营业地点素材资源。您可以利用 Google 商家资料的某些功能(例如按标签或连锁店 ID 和连锁店位置进行过滤)动态创建营业地点组素材资源集。或者,您也可以静态创建位置组素材资源集。
- 创建营业地点组素材资源集。营业地点组素材资源集的类型可以是动态或静态。
- 根据需要,将素材资源组附加到广告系列或广告组。
- (可选)将之前生成的素材资源添加到新创建的静态位置组素材资源集中。
对于给定的客户,您可以创建多个动态或静态营业地点组素材资源集。
创建营业地点组素材资源集
创建一个新的 AssetSet
,并将 location_group_parent_asset_set_id
设置为之前创建的地址同步素材资源集的 ID。
然后,根据您要创建动态还是静态营业地点组素材资源集,设置一些字段。
动态素材资源组
根据您在 LocationSet
中设置的字段,按照以下规则设置字段:
如果您设置了以下字段 | 然后将类型设置为 | 并将此字段设置为 asset_set_source oneof 字段 |
---|---|---|
business_profile_location_set |
BUSINESS_PROFILE_DYNAMIC_LOCATION_GROUP |
business_profile_location_group |
chain_location_set |
CHAIN_DYNAMIC_LOCATION_GROUP |
chain_location_group |
如果在创建位置同步素材资源集时设置了 maps_location_set
,您将无法创建动态位置群组素材资源集。这是因为您已通过地点 ID 手动添加了地点,而您无法使用任何过滤功能来过滤此类地点。
静态素材资源组
将 type
设置为 STATIC_LOCATION_GROUP
。您可以为任何类型的位置同步素材资源组创建静态位置组素材资源集,无论您在 LocationSet
中设置了哪些字段(business_profile_location_set
、chain_location_set
或 maps_location_set
)。
对于静态营业地点组素材资源集,您需要手动将生成的地址素材资源添加到营业地点组素材资源集。
将素材资源组附加到广告系列或广告组
使用 CampaignAssetSetService.MutateCampaignAssetSets
将地理位置组素材资源集附加到您的广告系列。
或者,如果您想将营业地点组素材资源集附加到广告组,请使用 AdGroupAssetSetService.MutateAdGroupAssetSets
。
(可选)将地址素材资源添加到静态地址素材资源组素材资源集中
仅当您之前创建了静态营业地点组素材资源集时,才需要执行此步骤。
- 使用
asset_set_asset
报告可提取之前创建的位置同步素材资源组的自动生成的素材资源的资源名称。使用过滤功能可仅检索所需的资产。 - 使用
AssetSetAssetService.MutateAssetSetAssets
将它们添加到静态营业地点组素材资源集。
管理商家资料的营业地点 ID
当您使用 business_profile_location_set
并根据从商家资料网站或 API 检索到的 listing_id_filters
进行过滤时,可能需要将这些数值从 uint64
类型转换为 int64
类型。如果您的代码在添加到 listing_id_filters[] 重复字段时生成运行时错误,指出您的商家资料营业地点 ID 超出范围,那么您可能需要使用以下任一示例对其进行转换:
Java
/**
* Converts the business profile location ID to the format expected by the
* DynamicBusinessProfileLocationGroupFilter.listing_id_filters[] repeated field.
* The business profile location ID is an unsigned 64-bit integer, while the
* listing_id_filters[] field expects signed 64-bit integers. This means that
* for business profile location IDs that are out of range, we must perform the
* two's complement to convert it into a signed int.
*
* @param businessProfileLocationId The ID of a Business Profile location ID.
* @return a Business Profile location ID as a signed 64-bit integer (long).
*/
public static long convertBusinessProfileLocationId(String businessProfileLocationId) {
return Long.parseUnsignedLong(businessProfileLocationId);
}
C#
/// <summary>
/// Converts the business profile location ID to the format expected by the
/// DynamicBusinessProfileLocationGroupFilter.listing_id_filters[] repeated field.
/// The business profile location ID is an unsigned 64-bit integer, while the
/// listing_id_filters[] field expects signed 64-bit integers. This means that
/// for business profile location IDs that are out of range, we must perform the
/// two's complement to convert it into a signed int.
/// </summary>
/// <param name="businessProfileLocationId">The ID of a Business Profile location.</param>
/// <returns>The converted business location ID in signed 64 bit.</returns>
public long ConvertBusinessProfileLocationId(ulong businessProfileLocationId)
{
return unchecked((long)businessProfileLocationId);
}
PHP
/**
* Converts a business profile location ID to a signed 64 bit integer.
*
* Converts the business profile location ID to the format expected by the
* DynamicBusinessProfileLocationGroupFilter.listing_id_filters[] repeated field.
* The business profile location ID is an unsigned 64-bit integer, while the
* listing_id_filters[] field expects signed 64-bit integers. This means that
* for business profile location IDs that are out of range, we must perform the
* two's complement to convert it into a signed int.
*
* @param string $businessProfileLocationId the ID of a Business Profile location
* @return int the converted business location ID in signed 64 bit
*/
public static function convertBusinessProfileLocationId(string $businessProfileLocationId): int
{
$unsignedMax = '18446744073709551615'; // 2^64 - 1
$signedMax = '9223372036854775807'; // 2^63 - 1
// Check if the business profile location ID is within 64 bit range.
// If not, throw an error.
if (bccomp($businessProfileLocationId, '0') < 0 || bccomp($businessProfileLocationId, $unsignedMax) > 0) {
throw new InvalidArgumentException(
'The given business profile location id is outside of the range for a 64 bit integer.'
);
}
// Check if the business profile location ID is in signed 64 bit range.
// If it's not, convert it to its two's complement.
if (bccomp($businessProfileLocationId, $signedMax) > 0) {
// Two's complement: ID - 2^64
return (int) bcsub($businessProfileLocationId, '18446744073709551616');
}
return (int) $businessProfileLocationId;
}
Python
import ctypes
def convert_business_profile_location_id(business_profile_location_id):
"""Converts a business profile location ID to a signed 64 bit integer.
Converts the business profile location ID to the format expected by the
DynamicBusinessProfileLocationGroupFilter.listing_id_filters[] repeated field.
The business profile location ID is an unsigned 64-bit integer, while the
listing_id_filters[] field expects signed 64-bit integers. This means that
for business profile location IDs that are out of range, we must perform the
two's complement to convert it into a signed int.
Args:
business_profile_location_id: the ID of a Business Profile location ID.
Returns:
a Business Profile location ID as a signed 64 bit integer.
"""
# Check if the business profile location ID is within 64 bit range.
# If not, throw an error.
if business_profile_location_id >= 2 ** 64:
raise ValueError(
"The given business profile location id is outside of the range for a 64 bit integer."
)
# Check if the business profile location ID is in signed 64 bit range.
# If it's not, convert it to its two's complement.
elif business_profile_location_id >= 2 ** 63:
return ctypes.c_int64(business_profile_location_id).value
else:
return business_profile_location_id
Ruby
# Converts the business profile location ID to the format expected by the
# DynamicBusinessProfileLocationGroupFilter.listing_id_filters[] repeated field.
# The business profile location ID is an unsigned 64-bit integer, while the
# listing_id_filters[] field expects signed 64-bit integers. This means that
# for business profile location IDs that are out of range, we must perform the
# two's complement to convert it into a signed int.
# Since Ruby supports arbitrary precision numbers, we have to calculate it
# manually.
LONG_MAX = 2 ** 63
ULONG_MAX = LONG_MAX * 2
def convert_business_profile_location_id(business_profile_location_id)
# Check if the business profile location ID is within 64 bit range.
# If not, throw an error.
if business_profile_location_id >= 2 ** 64
raise "The given business profile location id is outside of the range for a 64 bit integer."
# Check if the business profile location ID is in signed 64 bit range.
# If it's not, convert it to its two's complement.
elseif business_profile_location_id >= 2**63
-1 * (ULONG_MAX - business_profile_location_id)
else
business_profile_location_id
end
end
Perl
use bigint;
# Converts the business profile location ID to the format expected by the
# DynamicBusinessProfileLocationGroupFilter.listing_id_filters[] repeated field.
# The business profile location ID is an unsigned 64-bit integer, while the
# listing_id_filters[] field expects signed 64-bit integers. This means that
# for business profile location IDs that are out of range, we must perform the
# two's complement to convert it into a signed int.
sub convert_business_profile_location_id {
my ($business_profile_location_id) = @_;
# Check if the business profile location ID is within 64 bit range.
# If not, throw an error.
if ($business_profile_location_id >= 2**64) {
die "The given business profile location id is outside of the range for a 64 bit integer";
# Check if the business profile location ID is in signed 64 bit range.
# If it's not, convert it to its two's complement.
} elseif ($business_profile_location_id >= 2**63) {
return -1 * (2**64 - $business_profile_location_id);
} else {
return $business_profile_location_id;
}
}