Nota
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare ad accedere o modificare le directory.
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare a modificare le directory.
Le sezioni seguenti mostrano esempi di script che eseguono varie azioni sui budget condivisi.
Aggiungere budget condivisi
Per aggiungere un budget condiviso, è necessario utilizzare l'applicazione Web Microsoft Advertising. Per informazioni dettagliate, vedi Ricerca per categorie condividere un budget tra più campagne?
Associare una campagna a un budget condiviso
Per associare una campagna a un budget condiviso, è necessario utilizzare l'applicazione Web Microsoft Advertising. Per informazioni dettagliate, vedi Ricerca per categorie condividere un budget tra più campagne?
Ottenere tutti i budget condivisi
Per ottenere tutti i budget condivisi in un account, chiamare prima il metodo dell'oggetto budgetsAdsApp per ottenere il selettore. Quindi, chiamare il metodo del get selettore per ottenere un iteratore da usare per scorrere l'elenco dei budget condivisi. Poiché nell'esempio non viene specificato alcun filtro, il selettore restituisce tutti i budget condivisi nell'account. Per determinare il numero di budget condivisi nell'iteratore, chiamare il metodo dell'iteratore totalNumEntities .
Nota
I budget condivisi non includono i budget non condivisi (singole campagne).
function main() {
// Gets all shared budgets in the account.
var iterator = AdsApp.budgets().get();
// Iterates through the list of shared budgets and logs
// each budgets's name and amount.
while (iterator.hasNext()) {
var budget = iterator.next();
}
}
Ottenere un budget condiviso in base al nome
Per ottenere un budget condiviso in base al nome, chiamare prima il metodo dell'oggetto budgetsAdsApp per ottenere il selettore. Il selettore contiene diversi metodi di filtro che consentono di filtrare l'elenco dei budget. Utilizzare il withCondition metodo per filtrare i budget in base al nome. Ad esempio, per filtrare l'elenco in base a un nome specifico, usare: withCondition("BudgetName = '<budgetnamegoeshere>'"). Per filtrare l'elenco in base a un nome parziale, usare: withCondition("BudgetName CONTAINS_IGNORE_CASE '<partialnamegoeshere>'"). Si noti che gli operandi e gli operatori fanno distinzione tra maiuscole e minuscole.
Quindi, chiama il metodo del get selettore per ottenere l'iteratore.
function main() {
// Partial name of the shared budget to get.
var budgetName = 'PARTIAL NAME GOES HERE';
// Get the budgets that contain the partial name.
var iterator = AdsApp.budgets()
.withCondition(`BudgetName CONTAINS_IGNORE_CASE '${budgetName}'`)
.get();
// Iterates through the list of shared budgets and logs
// each budget's name and amount.
while (iterator.hasNext()) {
var budget = iterator.next();
}
}
Ottenere budget condivisi per ID
Se si ha accesso all'ID del budget condiviso, è possibile utilizzarlo. L'uso degli ID per ottenere entità offre prestazioni migliori. Invece di usare il withCondition metodo di filtro, usare il withIds metodo. Ad esempio, withIds(['12345']).
function main() {
var sharedBudgetId = '12345';
var iterator = AdsApp.budgets()
.withIds([sharedBudgetId])
.get();
while (iterator.hasNext()) {
var budget = iterator.next();
}
}
Ottenere tutte le campagne che condividono il budget
Per ottenere tutte le campagne che condividono il budget, chiamare il metodo delle campagne del budget. È possibile chiamare questo metodo solo da un oggetto Budget ottenuto da BudgetSelector; Non è possibile chiamarlo se l'origine del budget è il metodo getBudget della campagna.
function main() {
var sharedBudgetId = '12345';
var budgets = AdsApp.budgets()
.withIds([sharedBudgetId])
.get();
while (budgets.hasNext()) {
var budget = budgets.next();
var campaigns = budget.campaigns().get();
while (campaigns.hasNext()) {
var campaign = campaigns.next();
}
}
}
Ottenere i dati sul rendimento di un budget condiviso
Per ottenere le metriche di rendimento di un budget condiviso, chiamare il metodo getStats del budget. Quando si ottiene l'elenco dei budget di condivisione, è necessario specificare l'intervallo di date dei dati delle metriche desiderati. È possibile specificare l'intervallo di date usando un valore letterale predefinito, ad esempio LAST_MONTH o OGGI, oppure una data di inizio e di fine. Per specificare l'intervallo di date, utilizzare uno dei metodi quando si selezionano i budget (vedere Selettore budgetforDateRange).
Per un elenco delle metriche a cui è possibile accedere, vedi l'oggetto Stats . Le metriche sono l'aggregazione di tutte le campagne che condividono il budget.
function main() {
var sharedBudgetId = '12345';
// Get the shared budget. You need to specify the date range of the
// performance data you want to get.
var budgets = AdsApp.budgets()
.forDateRange('LAST_WEEK')
.withIds([sharedBudgetId])
.get();
// If the budget is found, log some metrics.
while (budgets.hasNext()) {
var budget = budgets.next();
var metrics = budget.getStats(); // Gets the performance metrics.
}
}