Komponenty z lokalizacją

W przeciwieństwie do innych komponentów komponenty z lokalizacją są tworzone automatycznie przez interfejs Google Ads API po utworzeniu przez Ciebie grupy plików. Najpierw utwórz zestaw komponentów synchronizacji lokalizacji i dołącz go do klienta. Jeśli w przypadku kampanii lub grupy reklam musisz wybrać podzbiór komponentów z lokalizacją w zbiorze komponentów, utwórz zbiór komponentów z grupą lokalizacji i dołącz go do kampanii lub grupy reklam.

Utwórz zestaw komponentów synchronizacji lokalizacji i dołącz go do klienta.

  1. Utwórz zestaw komponentów synchronizacji lokalizacji.
  2. Dołącz go do klienta za pomocą CustomerAssetSetService.

Tworzenie zestawu komponentów synchronizacji lokalizacji

  1. Utwórz nowy AssetSet.
    1. Ustaw type na LOCATION_SYNC.
    2. Ustaw location_set na nowy LocationSet.
  2. W nowym LocationSet,
    1. Ustaw wartość location_ownership_type na podstawie przypadku użycia:
      • Ustaw wartość BUSINESS_OWNER, jeśli jesteś właścicielem danej placówki stacjonarnej.
      • Ustaw wartość AFFILIATE, jeśli nie jesteś właścicielem lokalizacji firmy, ale sprzedajesz w niej swoje produkty.
    2. Ustaw pole source oneof na podstawie przypadku użycia:
      • Ustaw business_profile_location_set, jeśli chcesz synchronizować lokalizacje na koncie Profil Firmy w Google.
      • Ustaw chain_location_set, jeśli chcesz synchronizować dane z lokalizacjami w określonych identyfikatorach sieci.
      • Ustaw maps_location_set, jeśli chcesz ręcznie dodawać lokalizacje za pomocą identyfikatorów miejsc.

Po wykonaniu tych czynności interfejs Google Ads API wygeneruje komponenty lokalizacji i doda je do utworzonego zestawu komponentów synchronizacji lokalizacji, podobnie jak w przypadku ręcznego dodawania komponentów za pomocą AssetSetAssetService. Nie musisz ich modyfikować, chyba że chcesz ręcznie dodać je do statycznych zestawów zasobów w grupie lokalizacji.

Klient może mieć tylko 1 aktywny zestaw komponentów do synchronizacji lokalizacji z status ENABLED. Jeśli chcesz utworzyć komponent do synchronizacji lokalizacji innego typu, najpierw usuń dotychczasowy.

Dołączanie do klienta zestawu komponentów synchronizacji lokalizacji

Użyj CustomerAssetSetService.MutateCustomerAssetSets aby dołączyć do klienta zestaw komponentów synchronizacji lokalizacji skonfigurowany w poprzedniej sekcji.

(Opcjonalnie) Utwórz zestaw komponentów z grupą lokalizacji i dołącz go do kampanii lub grupy reklam.

Zestaw komponentów grupa lokalizacji jest potrzebny tylko wtedy, gdy chcesz wybrać podzbiór komponentów z lokalizacją. Wynika to z faktu, że kampanie i grupy reklam dziedziczą komponenty z lokalizacją z poziomu klienta.

Zestawy komponentów z grupą lokalizacji zawierają podzbiór komponentów z lokalizacją z zestawu komponentów synchronizacja lokalizacji. Możesz dynamicznie tworzyć zestaw komponentów grupy lokalizacji, korzystając z niektórych funkcji Profilu Firmy w Google (np. filtrowania według etykiet) lub identyfikatorów sieci i lokalizacji sieci. Możesz też statycznie utworzyć zestaw komponentów grupy lokalizacji.

  1. Utwórz zestaw plików grupy lokalizacji. Komponent z grupą lokalizacji może być dynamiczny lub statyczny.
  2. Dołącz zestaw komponentów do kampanii lub grupy reklam, w zależności od potrzeb.
  3. (Opcjonalnie) Dodaj wcześniej wygenerowane komponenty do nowo utworzonego statycznego zestawu komponentów grupy lokalizacji.

W przypadku danego klienta możesz utworzyć wiele dynamicznych lub statycznych zestawów komponentów grupy lokalizacji.

Tworzenie zestawu komponentów grupy lokalizacji

Utwórz nowy obiekt AssetSet i ustaw location_group_parent_asset_set_id na identyfikator wcześniej utworzonego zestawu komponentów z synchronizacją lokalizacji.

Następnie ustaw niektóre pola w zależności od tego, czy chcesz utworzyć dynamiczny czy statyczny zestaw komponentów grupy lokalizacji.

Dynamiczne zestawy komponentów

W zależności od pola ustawionego w LocationSet ustaw pola zgodnie z tą regułą:

Jeśli ustawisz to pole: Następnie ustaw type na i ustaw to pole jako pole 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

Jeśli podczas maps_location_settworzenia komponentu synchronizacji lokalizacjiustawisz, nie będziesz mieć możliwości utworzenia dynamicznego zestawu komponentów grupy lokalizacji. Dzieje się tak, ponieważ lokalizacje zostały dodane ręcznie za pomocą identyfikatorów miejsc i nie ma funkcji filtrowania, których można użyć w przypadku tego typu lokalizacji.

Statyczne zestawy plików

Ustaw type na STATIC_LOCATION_GROUP. Możesz tworzyć statyczne zestawy plików grupy lokalizacji dla dowolnych typów zestawów plików synchronizacji lokalizacji, niezależnie od tego, jakie pola (business_profile_location_set, chain_location_set lub maps_location_set) ustawisz w LocationSet.

W przypadku statycznych zestawów komponentów grupy lokalizacji musisz ręcznie dodać wygenerowane komponenty z lokalizacją do zestawów komponentów grupy lokalizacji.

Dołączanie grupy plików do kampanii lub grupy reklam

Użyj CampaignAssetSetService.MutateCampaignAssetSets aby dołączyć do kampanii zestaw komponentów grupy lokalizacji.

Możesz też użyć znaku AdGroupAssetSetService.MutateAdGroupAssetSets jeśli chcesz dołączyć zestaw komponentów grupy lokalizacji do grupy reklam.

(Opcjonalnie) Dodaj komponenty z lokalizacją do zestawu komponentów grupy lokalizacji statycznej.

Ten krok jest wymagany tylko wtedy, gdy wcześniej utworzysz statyczny zestaw komponentów grupy lokalizacji.

  1. Użyj raportu asset_set_asset, aby pobrać nazwy zasobów komponentów wygenerowanych automatycznie na potrzeby utworzonego wcześniej zestawu komponentów do synchronizacji lokalizacji. Użyj filtrowania, aby pobrać tylko te zasoby, które Cię interesują.
  2. Dodaj je do statycznego zestawu komponentów grupy lokalizacji za pomocą AssetSetAssetService.MutateAssetSetAssets.

Zarządzanie identyfikatorami lokalizacji w Profilu Firmy

Gdy używasz business_profile_location_set i filtrujesz dane listing_id_filters pobrane z witryny lub interfejsu API Profilu Firmy, może być konieczne przekonwertowanie tych wartości liczbowych z typu uint64 na int64. Jeśli Twój kod generuje błąd czasu wykonania, że identyfikator lokalizacji Profilu Firmy jest poza zakresem podczas dodawania go do powtarzanego pola listing_id_filters[], prawdopodobnie musisz go przekonwertować, korzystając z jednego z tych przykładów:

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;
  }
}