A differenza di altri asset, gli asset posizione vengono creati automaticamente dall'API Google Ads dopo la creazione di un insieme di asset. Innanzitutto, crea un insieme di asset di sincronizzazione della posizione e collegalo al cliente. Poi, se devi selezionare un sottoinsieme degli asset posizione nell'insieme di asset per una campagna o un gruppo di annunci, crea un insieme di asset del gruppo di località e collegalo alla campagna o al gruppo di annunci.
Crea un insieme di asset di sincronizzazione della posizione e collegalo al cliente
- Crea un insieme di asset di sincronizzazione della posizione.
- Collegalo a un cliente utilizzando
CustomerAssetSetService.
Crea un insieme di asset di sincronizzazione della posizione
- Crea un nuovo
AssetSet.- Imposta
typesuLOCATION_SYNC. - Imposta
location_setsu un nuovoLocationSet.
- Imposta
Nella nuova
LocationSet,- Imposta
location_ownership_typein base al tuo caso d'uso:- Impostalo su
BUSINESS_OWNERse sei il proprietario della sede dell'attività. - Impostalo su
AFFILIATEse non possiedi la sede dell'attività, ma vendi i tuoi prodotti lì.
- Impostalo su
Imposta il campo oneof
sourcein base al tuo caso d'uso:Imposta
business_profile_location_setse vuoi eseguire la sincronizzazione con le tue sedi nell'account Profilo dell'attività su Google.Quando crei un
BusinessProfileLocationSetper collegare Google Ads a un account Profilo dell'attività su Google, devi fornire un token di accesso OAuth 2.0 nel campohttp_authorization_token. Questo token funge da prova che stai autorizzando Google Ads ad accedere ai dati sulla posizione dal Profilo dell'attività su Google specificato.Il token deve soddisfare i seguenti requisiti:
- Deve essere generato per l'Account Google (utente o service account) il cui indirizzo email è fornito nel campo
email_addressdiBusinessProfileLocationSet. - Questo account deve disporre di autorizzazioni sufficienti per leggere le sedi dell'attività all'interno di Profilo dell'attività su Google.
- Il token OAuth 2.0 deve essere ottenuto con l'ambito
https://www.googleapis.com/auth/business.manage.
Per istruzioni dettagliate su come generare un token di accesso OAuth 2.0, consulta Utilizzare OAuth 2.0 per accedere alle API di Google.
- Deve essere generato per l'Account Google (utente o service account) il cui indirizzo email è fornito nel campo
Imposta
chain_location_setse vuoi eseguire la sincronizzazione con le località negli ID catena specificati.Imposta
maps_location_setse vuoi aggiungere manualmente le località utilizzando gli ID luogo.
- Imposta
Dopo aver completato questi passaggi, l'API Google Ads genera gli asset posizione e li aggiunge all'insieme di asset di sincronizzazione delle sedi creato, in modo simile a quando esegui questa operazione manualmente utilizzando AssetSetAssetService. Non è necessario manipolarli, a meno che tu non voglia aggiungerli manualmente a un insieme di asset di gruppi di località statici.
Per un cliente può esistere un solo insieme di asset di sincronizzazione della posizione attivo con status impostato su ENABLED. Se devi creare un tipo diverso di gruppo di asset di sincronizzazione della sede, rimuovi prima quello esistente.
Collega l'insieme di asset di sincronizzazione della posizione a un cliente
Utilizza
CustomerAssetSetService.MutateCustomerAssetSets
per collegare al cliente l'insieme di asset di sincronizzazione della posizione impostato nella sezione precedente.
(Facoltativo) Crea un insieme di asset del gruppo di località e collegalo a una campagna o a un gruppo di annunci
Un insieme di asset gruppo di località è necessario solo se devi selezionare un sottoinsieme di asset posizione. Questo perché le campagne e i gruppi di annunci ereditano gli asset posizione dal livello cliente.
I gruppi di asset per i gruppi di località contengono un sottoinsieme di asset posizione dell'insieme di asset di sincronizzazione delle località. Puoi creare dinamicamente un insieme di asset del gruppo di località sfruttando alcune funzionalità di Profilo dell'attività su Google (come il filtro per etichette) o gli ID e le sedi delle catene. In alternativa, puoi creare staticamente un insieme di asset del gruppo di località.
- Crea un insieme di asset del gruppo di località. L'insieme di asset del gruppo di località può essere dinamico o statico.
- Collega l'insieme di asset a una campagna o a un gruppo di annunci, a seconda delle tue esigenze.
- (Facoltativo) Aggiungi gli asset generati in precedenza all'insieme di asset del gruppo di località statiche appena creato.
Per un determinato cliente, puoi creare più insiemi di asset di gruppi di località dinamici o statici.
Crea un insieme di asset del gruppo di località
Crea un nuovo AssetSet e imposta
location_group_parent_asset_set_id sull'ID dell'insieme di asset di sincronizzazione della posizione
creato in precedenza.
Poi, imposta alcuni campi in base al fatto che tu voglia creare un insieme di asset del gruppo di località dinamico o statico.
Gruppi di asset dinamici
A seconda del campo impostato in LocationSet, imposta i campi in base alla seguente regola:
| Se imposti il seguente campo | Poi imposta type su | Imposta questo campo come campo oneof asset_set_source |
|---|---|---|
business_profile_location_set |
BUSINESS_PROFILE_DYNAMIC_LOCATION_GROUP |
business_profile_location_group |
chain_location_set |
CHAIN_DYNAMIC_LOCATION_GROUP |
chain_location_group |
Se imposti maps_location_set quando crei l'insieme di asset di sincronizzazione della posizione, non potrai creare un insieme di asset del gruppo di località dinamiche. Questo perché hai aggiunto manualmente le località in base agli ID luogo e non esistono funzionalità di filtro che puoi utilizzare per questo tipo di località.
Insiemi di asset statici
Imposta type su
STATIC_LOCATION_GROUP.
Puoi creare insiemi di asset di gruppi di località statici per qualsiasi tipo di insieme di asset di sincronizzazione delle località, indipendentemente dai campi (business_profile_location_set, chain_location_set o maps_location_set) impostati in LocationSet.
Per gli insiemi di asset dei gruppi di località statici, devi aggiungere manualmente gli asset posizione generati agli insiemi di asset dei gruppi di località.
Collega l'insieme di asset a una campagna o a un gruppo di annunci
Utilizza
CampaignAssetSetService.MutateCampaignAssetSets
per collegare l'insieme di asset dei gruppi di località alla tua
campagna.
In alternativa, utilizza AdGroupAssetSetService.MutateAdGroupAssetSets se vuoi collegare l'insieme di asset dei gruppi di località a un gruppo di annunci.
(Facoltativo) Aggiungi gli asset posizione all'insieme di asset del gruppo di località statico.
Questo passaggio è obbligatorio solo se hai creato un insieme di asset del gruppo di località statiche in precedenza.
- Utilizza il report
asset_set_assetper recuperare i nomi delle risorse degli asset generati automaticamente per l'insieme di asset di sincronizzazione della posizione creato in precedenza. Utilizza i filtri per recuperare solo gli asset che ti interessano. - Aggiungili all'insieme di asset del gruppo di località statico utilizzando
AssetSetAssetService.MutateAssetSetAssets.
Gestisci gli ID località di Profilo dell'attività
Quando utilizzi un business_profile_location_set e filtri in base a listing_id_filters recuperati dal sito web o dall'API di Profilo dell'attività, potrebbe essere necessario convertire questi valori numerici dal tipo uint64 a int64. Se il codice genera un errore di runtime che indica che l'ID località del profilo dell'attività non rientra nell'intervallo quando lo aggiungi al campo ripetuto listing_id_filters[], probabilmente devi convertirlo utilizzando uno dei seguenti esempi:
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 < 0 or 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 < 0 || 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.
elsif 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 < 0 || $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.
} elsif ($business_profile_location_id >= 2**63) {
return -1 * (2**64 - $business_profile_location_id);
} else {
return $business_profile_location_id;
}
}