תקציבים גמישים – חשבון יחיד

לוחצים על סמל מפתח הברגים

ב-Google Ads אפשר להגדיר סכום של תקציב יומי לכל קמפיין. עם זאת, לחלק מיוזמות השיווק תהיה עלות קבועה. לדוגמה, "אני רוצה להוציא 20,000 ש"ח לקראת מבצע הסתיו". שיטת הבידינג נותנת לכם שליטה מסוימת על אופן ניצול התקציב היומי, אבל אין לכם שליטה על אופן ניצול התקציב במהלך הקמפיין.

לדוגמה, אם אנחנו רוצים לפרסם את מבצע הסתיו רק 2,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.

    התקנה של תבנית הסקריפט

  • שומרים את הסקריפט ולוחצים על הלחצן תצוגה מקדימה. הסקריפט הזה (כברירת מחדל) מדמה שיטת תקציב עם 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}`);
}