Script 521: Budget Boosts for Bing Campaigns

Purpose

The Python script adjusts the daily budget of Bing campaigns by 5% if their ROAS performance exceeds 3.5% and they have a lost impression share due to budget of at least 0.5% over the past 30 days.

To Elaborate

The script is designed to optimize the budget allocation for Bing advertising campaigns by analyzing their performance over a 30-day period. It specifically targets campaigns that have a high Return on Advertising Spend (ROAS) and are losing impression share due to budget constraints. If a campaign’s ROAS is 3.5% or higher and it has lost at least 0.5% of its impression share due to budget limitations, the script increases its daily budget by 5%. This approach aims to enhance the visibility and effectiveness of well-performing campaigns by ensuring they have sufficient budget to capture more impressions, potentially leading to increased conversions and revenue.

Walking Through the Code

  1. Initialization and Parameters
    • The script begins by defining key parameters: IS_LOST_TO_BUDGET_THRESHOLD (0.5%), ROAS_THRESHOLD (3.5%), and BUDGET_INCREASE (5%). These parameters are user-changeable and dictate the conditions under which a campaign’s budget will be increased.
  2. Data Preparation
    • The script retrieves the primary data source into inputDf and initializes a new column AUTOMATION - Budget Boost to track budget changes.
  3. Data Aggregation
    • It groups the data by ‘Publisher’, ‘Account’, and ‘Campaign’, then calculates the total revenue, total cost, and the last recorded ‘Lost Impression Share (Budget)’ for each campaign.
  4. ROAS Calculation
    • The script computes the ROAS for each campaign by dividing the total revenue by the total cost.
  5. Criteria Evaluation
    • It evaluates which campaigns meet the criteria for budget increase: ROAS greater than or equal to 3.5% and lost impression share due to budget greater than or equal to 0.5%.
  6. Budget Adjustment
    • For campaigns that meet the criteria, the script increases their daily budget by 5% and records this change in the AUTOMATION - Budget Boost column.
  7. Output Preparation
    • Finally, the script prepares the output data frame, outputDf, which includes only the campaigns with changed budgets, and prints the results.

Vitals

  • Script ID : 521
  • Client ID / Customer ID: 314475863 / 63970
  • Action Type: Bulk Upload
  • Item Changed: Campaign
  • Output Columns: Account, Campaign, Daily Budget, AUTOMATION - Budget Boost
  • Linked Datasource: M1 Report
  • Reference Datasource: None
  • Owner: dwaidhas@marinsoftware.com (dwaidhas@marinsoftware.com)
  • Created by dwaidhas@marinsoftware.com on 2023-11-13 17:23
  • Last Updated by dwaidhas@marinsoftware.com on 2024-04-24 14:48
> See it in Action

Python Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#
## name: Budget Boosts for Bing Campaigns
## author: Dana W.
## created: 2023-11-13
## 

####################### Params ################
# Define your performance threshold and budget increase
IS_LOST_TO_BUDGET_THRESHOLD = 0.005  # 0.5%
ROAS_THRESHOLD = 3.5
BUDGET_INCREASE = 0.05  # 5%
###############################################

today = datetime.datetime.now(CLIENT_TIMEZONE).date()

# primary data source and columns
inputDf = dataSourceDict["1"]

# output columns and initial values
RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_DATE = 'Date'
RPT_COL_ACCOUNT = 'Account'
RPT_COL_PUBLISHER = 'Publisher'
RPT_COL_CAMPAIGN_ID = 'Campaign ID'
RPT_COL_CAMPAIGN_TYPE = 'Campaign Type'
RPT_COL_CAMPAIGN_STATUS = 'Campaign Status'
RPT_COL_DAILY_BUDGET = 'Daily Budget'
RPT_COL_PUB_COST = 'Pub. Cost $'
RPT_COL_COST_PER_CONV = 'Cost/Conv. $'
RPT_COL_ROAS = 'ROAS'
RPT_COL_AVG_CPC = 'Avg. CPC $'
RPT_COL_CONV_RATE = 'Conv. Rate %'
RPT_COL_CTR = 'CTR %'
RPT_COL_CONV = 'Conv.'
RPT_COL_REVENUE = 'Revenue $'
RPT_COL_LOST_IMPRSHAREBUDGET = 'Lost Impr. Share (Budget) %'
RPT_COL_AVG_BID = 'Avg. Bid $'
RPT_COL_HIST_QS = 'Hist. QS'
RPT_COL_IMPR = 'Impr.'
RPT_COL_CLICKS = 'Clicks'
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_DAILY_BUDGET = 'Daily Budget'
BULK_COL_AUTOMATION_BUDGETBOOST = 'AUTOMATION - Budget Boost'

### user code starts here

print("inputDf.shape", inputDf.shape)
print("inputDf.head", tableize(inputDf.head()))

# add new column for output
inputDf[BULK_COL_AUTOMATION_BUDGETBOOST] = np.nan

# Group by Publisher, Account, Campaign
grouped = inputDf.groupby(['Publisher', 'Account', 'Campaign'])

# Calculate new ROAS and get the last 'Lost Impression Share'
campaigns_df = grouped.agg({
    BULK_COL_DAILY_BUDGET:'last',
    RPT_COL_REVENUE:'sum',
    RPT_COL_PUB_COST:'sum',
    RPT_COL_LOST_IMPRSHAREBUDGET:'last',
    }
).reset_index()

campaigns_df[RPT_COL_ROAS] = campaigns_df[RPT_COL_REVENUE] / campaigns_df[RPT_COL_PUB_COST]


print("campaigns_df", tableize(campaigns_df.head()))

# make copy for comparison later
original_df = campaigns_df.copy()

# define business criteria
flag_impression_share = campaigns_df[RPT_COL_LOST_IMPRSHAREBUDGET] >= IS_LOST_TO_BUDGET_THRESHOLD
flag_roas = campaigns_df[RPT_COL_ROAS] >= ROAS_THRESHOLD

# Increase daily budget for campaigns that meet the criteria
qualified = flag_roas & flag_impression_share

print(f"qualified count: {sum(qualified)}")

campaigns_df.loc[qualified, RPT_COL_DAILY_BUDGET] = (1 + BUDGET_INCREASE) * \
                        campaigns_df.loc[qualified, RPT_COL_DAILY_BUDGET]

# Keep track of budget increase
campaigns_df.loc[qualified, BULK_COL_AUTOMATION_BUDGETBOOST] = BUDGET_INCREASE

# tag for debugging
campaigns_df['qualified'] = qualified

outputDf, debugDf = select_changed(campaigns_df, 
                                    original_df,
                                    diff_cols=[RPT_COL_DAILY_BUDGET],
                                    select_cols=[RPT_COL_ACCOUNT, RPT_COL_CAMPAIGN, RPT_COL_DAILY_BUDGET, BULK_COL_AUTOMATION_BUDGETBOOST],
                                    merged_cols=[RPT_COL_ACCOUNT, RPT_COL_CAMPAIGN]
                                    )

print("outputDf.shape", outputDf.shape)
print("outputDf.head")
print(tableize(outputDf.head()))


Post generated on 2024-11-27 06:58:46 GMT

comments powered by Disqus