地點素材資源

與其他素材資源不同,建立素材資源組合後,Google Ads API 會自動建立地點素材資源。首先,建立地點同步素材資源組合,並附加至客戶。接著,如要為廣告活動或廣告群組選取素材資源組合中的地點素材資源子集,請建立地點群組素材資源組合,並附加至廣告活動或廣告群組。

建立地點同步素材資源組合,並附加至客戶

  1. 建立地點同步素材資源組合
  2. 使用 CustomerAssetSetService將其附加至客戶。

建立地點同步素材資源組合

  1. 建立新的 AssetSet
    1. type 設為 LOCATION_SYNC
    2. location_set 設為新的 LocationSet
  2. 在新的「LocationSet」中,
    1. 根據用途設定 location_ownership_type
      • 如果你是商家地點的擁有者,請將其設為 BUSINESS_OWNER
      • 如果你不是商家地點的業主,但會在該處銷售產品,請將這項屬性設為 AFFILIATE
    2. 根據用途設定 source oneof 欄位:
      • 如要與 Google 商家檔案帳戶中的地點同步,請設定 business_profile_location_set
      • 如要與指定連鎖店 ID 中的地點同步,請設定 chain_location_set
      • 如要使用地點 ID 手動新增地點,請設定 maps_location_set

完成這些步驟後,Google Ads API 會產生地點資產,並將其新增至您建立的地點同步資產組合,與您使用 AssetSetAssetService 手動執行此操作時類似。除非要手動將這些素材資源加入靜態位置群組素材資源組合,否則不需要操作。

每個客戶只能有一個有效的地點同步素材資源組合 (status of ENABLED)。如要建立其他類型的地點同步素材資源組合,請先移除現有組合。

將地點同步資產組合附加至客戶

使用 CustomerAssetSetService.MutateCustomerAssetSets 將上一節中設定的地點同步素材資源組合附加至顧客。

(選用) 建立營業地點群組素材資源組合,並附加至廣告活動或廣告群組

只有在需要選取部分地點素材資源時,才需要地區群組素材資源組合。這是因為廣告活動和廣告群組會沿用客戶層級的地點素材資源。

地區群組素材資源組合包含地點同步素材資源組合的部分地點素材資源。您可以運用 Google 商家檔案的部分功能 (例如依標籤篩選),或連鎖店 ID 和連鎖店地點,動態建立地區群組素材資源組合。或者,您也可以靜態建立地點群組素材資源組合。

  1. 建立營業地點群組素材資源集。地區群組素材資源組合可以是動態靜態
  2. 視需求而定,將素材資源組合附加至廣告活動或廣告群組
  3. (選用) 將先前產生的素材資源新增至新建立的靜態位置群組素材資源組合

您可以為特定顧客建立多個動態或靜態地點群組素材資源組合。

建立營業地點群組素材資源組合

建立新的 AssetSet,並將 location_group_parent_asset_set_id 設為先前建立的地點同步素材資源組合 ID。

接著,請根據要建立動態或靜態地區群組素材資源組合,設定部分欄位。

動態素材資源組合

視您LocationSet中設定的欄位而定,請根據下列規則設定欄位:

如果您設定下列欄位 然後將 type 設為 並將這個欄位設為 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_setchain_location_setmaps_location_set),都可以為任何類型的地點同步素材資源組合建立靜態地點群組素材資源組合。

如果是靜態地區群組素材資源組合,您需要手動將產生的地點額外資訊新增至地區群組素材資源組合

將素材資源組合附加至廣告活動或廣告群組

使用 CampaignAssetSetService.MutateCampaignAssetSets地區群組素材資源組合附加至廣告活動。

或者,如要將地區群組素材資源組合附加至廣告群組,請改用 AdGroupAssetSetService.MutateAdGroupAssetSets

(選用) 將地點素材資源新增至靜態地點群組素材資源組合

只有在先前建立靜態地區群組素材資源組合時,才需要執行這個步驟。

  1. 使用 asset_set_asset 報表擷取為先前建立的地點同步素材資源組合自動產生的素材資源名稱。使用篩選功能,只擷取您想要的資產。
  2. 使用 AssetSetAssetService.MutateAssetSetAssets 將這些素材資源加入靜態地區群組素材資源組合

管理商家檔案地點 ID

使用 business_profile_location_set 並篩選從商家檔案網站或 API 擷取的 listing_id_filters 時,可能需要將這些數值從 uint64 類型轉換為 int64。如果將商家檔案位置 ID 新增至 listing_id_filters[] 重複欄位時,程式碼產生執行階段錯誤,指出商家檔案位置 ID 超出範圍,則可能需要使用下列任一範例轉換該 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;
  }
}