ב-Google Ads אפשר להגדיר סכום תקציב יומי לכל קמפיין. עם זאת, לחלק מהיוזמות השיווקיות תהיה עלות קבועה משויכת. לדוגמה, 'אני רוצה להוציא 5,000 ש"ח לקראת המבצע של סוף השנה'. שיטת הבידינג מעניקה לכם שליטה מסוימת על אופן ניצול התקציב היומי, אבל אין לה השפעה על אופן ניצול התקציב במהלך הקמפיין.
לדוגמה, אם אנחנו רוצים להוציא רק 20,000 ש"ח כדי לפרסם את המבצע של סוף הקיץ, ואנחנו רוצים לפרסם במשך 10 ימים, נוכל להגדיר תקציב יומי של 2,000 ש"ח כדי לנצל את כל התקציב. עם זאת, ההנחה היא שנבצע את ההוצאה המלאה בכל יום וגם שנבצע אותה באופן שווה. אי אפשר להורות ל-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);
לוחצים על Preview ובודקים את הפלט של יומן הרישום. שימו לב ששיטת התקציב הזו מקצה פחות תקציב בתחילת התקופה ויותר תקציב בימים האחרונים.
אתם יכולים להשתמש בשיטת הבדיקה הזו כדי לדמות שינויים בפונקציות של חישוב התקציב ולנסות גישה משלכם לחלוקת התקציב.
הקצאת תקציב
שיטת התקציב 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
.
אתם יכולים לכתוב פונקציה משלכם כל עוד היא מקבלת את הארגומנטים האלה. בעזרת הערכים האלה תוכלו להשוות בין סכום הכסף שהוצאתם עד עכשיו לבין הסכום הכולל שאתם צריכים להוציא, ולבדוק איפה אתם נמצאים כרגע בלוחות הזמנים של התקציב הכולל.
באופן ספציפי, שיטת התקציב הזו מחשבת את הסכום שנותר בתקציב (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.
שומרים את הסקריפט ולוחצים על הלחצן Preview (תצוגה מקדימה). הסקריפט הזה (לפי ברירת המחדל) מדמה שיטת תקציב עם 500 $ב-10 ימים. הפלט של יומן הרישום משקף את היום שמיועד לסימולציה, את התקציב שהוקצה לאותו יום ואת הסכום הכולל שהוצא עד כה.
קוד מקור
// 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}`);
}