Google Ads 可任您設定每個廣告活動的每日預算金額。不過, 行銷計劃會有固定的費用;例如 「我願意花 $5,000 美元參與秋季促銷活動。」出價策略會帶來 只有您可以掌控每日預算的使用方式,但無法控制 廣告活動預算用完。
假設我們只想花 5, 000 美元放送秋季銷售廣告 可以將每日預算設為 $500 美元,這樣 整筆預算但這個假設前提是我們會用 而且希望每天平均使用廣告Google Ads 就無法告訴 Google Ads 您想要在最近幾天將大部分的預算用完。
運用自訂指令碼,以動態方式調整每日廣告活動預算 預算分配計畫。
運作方式
測試預算策略
指令碼包含一些測試程式碼,可模擬 好幾天。這樣您就能更瞭解執行指令碼時可能發生的情況 排定在一段時間內每天執行
根據預設,此指令碼會模擬平均支出 $500 美元的預算分配方式 超過 10 天。
function main() {
testBudgetStrategy(calculateBudgetEvenly, 10, 500);
// setNewBudget(calculateBudgetEvenly, CAMPAIGN_NAME, TOTAL_BUDGET, START_DATE, END_DATE);
}
setNewBudget
函式呼叫會加上註解,表示只會執行
測試程式碼以下是範例的輸出結果:
Day 1.0 of 10.0, new budget 50.0, cost so far 0.0
Day 2.0 of 10.0, new budget 50.0, cost so far 50.0
Day 3.0 of 10.0, new budget 50.0, cost so far 100.0
Day 4.0 of 10.0, new budget 50.0, cost so far 150.0
Day 5.0 of 10.0, new budget 50.0, cost so far 200.0
Day 6.0 of 10.0, new budget 50.0, cost so far 250.0
Day 7.0 of 10.0, new budget 50.0, cost so far 300.0
Day 8.0 of 10.0, new budget 50.0, cost so far 350.0
Day 9.0 of 10.0, new budget 50.0, cost so far 400.0
Day 10.0 of 10.0, new budget 50.0, cost so far 450.0
Day 11.0 of 10.0, new budget 0.0, cost so far 500.0
指令碼每天會計算出新的預算,確保預算支出達到: 平均分配達到分配的預算上限後,系統就會設定預算 暫時停止支出
只要變更要使用的功能,即可變更所用預算策略。
並修改函式本身它提供兩種預建策略:
《calculateBudgetEvenly
》和《calculateBudgetWeighted
》。如何設定加權測試
預算策略,請依照下列方式變更testBudgetStrategy
:
testBudgetStrategy(calculateBudgetWeighted, 10, 500);
按一下 [預覽] 並檢查記錄工具輸出。請注意,這項預算策略 在實驗期間初期分配的預算較少,而在過去幾天分配到的預算較多。
您可以利用這個測試方法模擬對預算計算所做的變更 ,試著使用自己的方法分配預算。
分配預算
「calculateBudgetWeighted
」預算策略的執行方式如下:
函式:
function calculateBudgetWeighted(costSoFar, totalBudget, daysSoFar, totalDays) {
const daysRemaining = totalDays - daysSoFar;
const budgetRemaining = totalBudget - costSoFar;
if (daysRemaining <= 0) {
return budgetRemaining;
} else {
return budgetRemaining / (2 * daysRemaining - 1) ;
}
}
此函式使用以下引數:
costSoFar
- 廣告活動從
START_DATE
到今天累積的費用。 totalBudget
- 已將支出從
START_DATE
分配給END_DATE
。 daysSoFar
- 從
START_DATE
到今天的經過天數。 totalDays
START_DATE
到END_DATE
之間的總天數。
You can write your own function as long as it takes these arguments. 您可以加入這些引數,自行撰寫函式。使用 您就能比較目前已花費多少金額 且需投入多少心力,並判斷你目前在時間軸的哪個位置 不分預算
具體來說,這種預算策略會計算剩餘的預算金額
(totalBudget - costSoFar
),然後除以天數的兩倍
。也就是在接近尾聲時分配預算分配比例
廣告活動。使用自 START_DATE
以來的費用,也會考量「速度緩慢」
天」「預算設定」中。
根據實際狀況調配預算
決定預算策略後,您需要做些調整 ,然後再排定每天執行這個指令碼。
首先,請更新檔案上方的常數:
START_DATE
:將此項目設為預算策略的開頭。這應該是 目前的日期或前一天的資料。END_DATE
:請設為您要使用這筆預算放送廣告的最後一天。TOTAL_BUDGET
:您預計支出的總金額。這個值位於 帳戶貨幣,且視指令碼執行時間而定,有可能超過設定值 排定執行時間CAMPAIGN_NAME
:要套用預算策略的廣告活動名稱。
接著,請停用測試並啟用邏輯,實際變更預算:
function main() {
// testBudgetStrategy(calculateBudgetEvenly, 10, 500);
setNewBudget(calculateBudgetWeighted, CAMPAIGN_NAME, TOTAL_BUDGET, START_DATE, END_DATE);
}
排程
排定執行這個指令碼的時間,安排在每天午夜左右執行
時區,盡可能調節次日預算。注意:
但請注意,擷取到費用等報表資料時,可能會延遲約 3 秒
小時,因此 costSoFar
參數可能會參照昨天的總計
排定在午夜後執行的指令碼
設定
請點選下方按鈕,在 Google Ads 帳戶中建立指令碼。
儲存指令碼,然後按一下 [預覽] 按鈕。這段指令碼 (編寫者: 預設) 模擬出在 10 天內支出 $500 美元的預算策略。記錄器輸出 反映模擬當天、當天的分配預算,以及 到目前為止支出的總金額
原始碼
// Copyright 2015, Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/**
* @name Flexible Budgets
*
* @overview The Flexible budgets script dynamically adjusts campaign budget for
* an advertiser account with a custom budget distribution scheme on a daily
* basis. See
* https://developers.google.com/google-ads/scripts/docs/solutions/flexible-budgets
* for more details.
*
* @author Google Ads Scripts Team [adwords-scripts@googlegroups.com]
*
* @version 2.1
*
* @changelog
* - version 2.1
* - Split into info, config, and code.
* - version 2.0
* - Updated to use new Google Ads scripts features.
* - version 1.0.3
* - Add support for video and shopping campaigns.
* - version 1.0.2
* - Use setAmount on the budget instead of campaign.setBudget.
* - version 1.0.1
* - Improvements to time zone handling.
* - version 1.0
* - Released initial version.
*/
/**
* Configuration to be used for the Flexible Budgets script.
*/
CONFIG = {
'total_budget': 500,
'campaign_name': 'Special Promotion',
'start_date': 'November 1, 2021 0:00:00 -0500',
'end_date': 'December 1, 2021 0:00:00 -0500'
};
const TOTAL_BUDGET = CONFIG.total_budget;
const CAMPAIGN_NAME = CONFIG.campaign_name;
const START_DATE = new Date(CONFIG.start_date);
const END_DATE = new Date(CONFIG.end_date);
function main() {
testBudgetStrategy(calculateBudgetEvenly, 10, 500);
// setNewBudget(calculateBudgetEvenly, CAMPAIGN_NAME, TOTAL_BUDGET,
// START_DATE, END_DATE);
}
function setNewBudget(budgetFunction, campaignName, totalBudget, start, end) {
const today = new Date();
if (today < start) {
console.log('Not ready to set budget yet');
return;
}
const campaign = getCampaign(campaignName);
const costSoFar = campaign.getStatsFor(
getDateStringInTimeZone('yyyyMMdd', start),
getDateStringInTimeZone('yyyyMMdd', end)).getCost();
const daysSoFar = datediff(start, today);
const totalDays = datediff(start, end);
const newBudget = budgetFunction(costSoFar, totalBudget, daysSoFar,
totalDays);
campaign.getBudget().setAmount(newBudget);
}
function calculateBudgetEvenly(costSoFar, totalBudget, daysSoFar, totalDays) {
const daysRemaining = totalDays - daysSoFar;
const budgetRemaining = totalBudget - costSoFar;
if (daysRemaining <= 0) {
return budgetRemaining;
} else {
return budgetRemaining / daysRemaining;
}
}
function calculateBudgetWeighted(costSoFar, totalBudget, daysSoFar,
totalDays) {
const daysRemaining = totalDays - daysSoFar;
const budgetRemaining = totalBudget - costSoFar;
if (daysRemaining <= 0) {
return budgetRemaining;
} else {
return budgetRemaining / (2 * daysRemaining - 1);
}
}
function testBudgetStrategy(budgetFunc, totalDays, totalBudget) {
let daysSoFar = 0;
let costSoFar = 0;
while (daysSoFar <= totalDays + 2) {
const newBudget = budgetFunc(costSoFar, totalBudget, daysSoFar, totalDays);
console.log(`Day ${daysSoFar + 1} of ${totalDays}, new budget ` +
`${newBudget}, cost so far ${costSoFar}`);
costSoFar += newBudget;
daysSoFar += 1;
}
}
/**
* Returns number of days between two dates, rounded up to nearest whole day.
*/
function datediff(from, to) {
const millisPerDay = 1000 * 60 * 60 * 24;
return Math.ceil((to - from) / millisPerDay);
}
function getDateStringInTimeZone(format, date, timeZone) {
date = date || new Date();
timeZone = timeZone || AdsApp.currentAccount().getTimeZone();
return Utilities.formatDate(date, timeZone, format);
}
/**
* Finds a campaign by name, whether it is a regular, video, or shopping
* campaign, by trying all in sequence until it finds one.
*
* @param {string} campaignName The campaign name to find.
* @return {Object} The campaign found, or null if none was found.
*/
function getCampaign(campaignName) {
const selectors = [AdsApp.campaigns(), AdsApp.videoCampaigns(),
AdsApp.shoppingCampaigns()];
for (const selector of selectors) {
const campaignIter = selector
.withCondition(`CampaignName = "${campaignName}"`)
.get();
if (campaignIter.hasNext()) {
return campaignIter.next();
}
}
throw new Error(`Could not find specified campaign: ${campaignName}`);
}