Script 237: switch strategies
Purpose
The Python script evaluates advertising campaigns and promotes them to a new publisher bidding strategy if they meet specified minimum thresholds for spend and Return on Advertising Spend (ROAS).
To Elaborate
The script is designed to optimize advertising campaigns by switching them to a new publisher bidding strategy when they meet certain performance criteria. Specifically, it checks if the campaigns have achieved a minimum Return on Advertising Spend (ROAS) and spend threshold. If these conditions are met, the campaign’s bidding strategy is updated to a predefined target strategy. This process helps in efficiently allocating budget to campaigns that are performing well, thereby maximizing the return on investment. The script is particularly useful for advertisers who want to automate the process of optimizing their campaign strategies based on performance metrics.
Walking Through the Code
- Configurable Parameters:
- The script begins by defining configurable parameters,
MIN_ROAS
andPUB_STRATEGY_TARGET
, which set the minimum ROAS threshold and the target publisher bidding strategy, respectively. These parameters can be adjusted by the user to fit specific business needs.
- The script begins by defining configurable parameters,
- Data Preparation:
- Temporary columns are created in the input DataFrame to store new values for the publisher strategy and target CPA. These columns are initialized with
NaN
values.
- Temporary columns are created in the input DataFrame to store new values for the publisher strategy and target CPA. These columns are initialized with
- Condition Check:
- The script evaluates each campaign to see if its ROAS meets or exceeds the
MIN_ROAS
threshold. If it does, the campaign’s publisher strategy is updated to thePUB_STRATEGY_TARGET
.
- The script evaluates each campaign to see if its ROAS meets or exceeds the
- Target CPA Assignment:
- The target CPA for campaigns meeting the ROAS threshold is set to their current cost per conversion.
- Identify Changes:
- The script identifies campaigns where the publisher strategy has changed by comparing the original and updated strategy columns.
- Output Preparation:
- If any campaigns have changed strategies, a subset of the DataFrame containing only these campaigns is created. This subset is then renamed to match the bulk upload format for further processing.
- Output Handling:
- If no campaigns meet the criteria for a strategy change, an empty DataFrame is prepared for output.
Vitals
- Script ID : 237
- Client ID / Customer ID: 1306922587 / 2
- Action Type: Bulk Upload (Preview)
- Item Changed: Campaign
- Output Columns: Account, Campaign, Publisher Target CPA, Publisher Bid Strategy
- Linked Datasource: M1 Report
- Reference Datasource: None
- Owner: Byron Porter (bporter@marinsoftware.com)
- Created by Byron Porter on 2023-07-13 11:21
- Last Updated by Byron Porter on 2023-12-07 21:03
> 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
#
# Promote to new Publisher Bidding Strategy if meet minimum:
# - Spend
# - ROAS
#
#
# Author: Byron Porter
# Date: 2023-07-13
#
########### Configurable Params - START ##########
MIN_ROAS = 1
PUB_STRATEGY_TARGET = 'TargetCpa'
########### Configurable Params - END ###########
RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_ACCOUNT = 'Account'
RPT_COL_PUBLISHER_BIDSTRATEGY = 'Publisher Bid Strategy'
RPT_COL_PUBLISHER_TARGETCPA = 'Publisher Target CPA'
RPT_COL_ROAS = 'ROAS'
RPT_COL_CPC = 'Cost/Conv. $'
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_PUBLISHER_BIDSTRATEGY = 'Publisher Bid Strategy'
BULK_COL_PUBLISHER_TARGETCPA = 'Publisher Target CPA'
# temp columns for new values
TMP_PUB_STRATEGY = RPT_COL_PUBLISHER_BIDSTRATEGY + '_'
inputDf[TMP_PUB_STRATEGY] = np.nan
TMP_TARGETCPA = RPT_COL_PUBLISHER_TARGETCPA + '_'
inputDf[TMP_TARGETCPA] = np.nan
# if both Spend and ROAS meet mininum threshold, switch to new pub strategy
inputDf.loc[(inputDf[RPT_COL_ROAS] >= MIN_ROAS), \
TMP_PUB_STRATEGY \
] = PUB_STRATEGY_TARGET
inputDf[TMP_TARGETCPA] = inputDf[RPT_COL_CPC]
# find changed campaigns
changed = (inputDf[TMP_PUB_STRATEGY].notnull()) & (inputDf[RPT_COL_PUBLISHER_BIDSTRATEGY] != inputDf[TMP_PUB_STRATEGY])
if sum(changed) > 0:
print("== Campaigns with Changed Pub Strategy ==", tableize(inputDf.loc[changed]))
# only select changed rows
cols = [RPT_COL_ACCOUNT, RPT_COL_CAMPAIGN, TMP_PUB_STRATEGY, TMP_TARGETCPA]
outputDf = inputDf.loc[ changed, cols ].copy() \
.rename(columns = { \
TMP_PUB_STRATEGY: BULK_COL_PUBLISHER_BIDSTRATEGY, \
TMP_TARGETCPA: BULK_COL_PUBLISHER_TARGETCPA \
})
print("outputDf", tableize(outputDf))
else:
print("Empty outputDf")
outputDf = outputDf.iloc[0:0]
Post generated on 2024-11-27 06:58:46 GMT