Script 143: New Campaigns Switch to tCPA
Purpose:
The Python script automates the process of switching campaign publisher bidding strategies to Target CPA based on minimum spend and ROAS criteria.
To Elaborate
The Python script is designed to optimize advertising campaigns by automatically switching their publisher bidding strategy to Target CPA (tCPA) when certain conditions are met. Specifically, it evaluates campaigns that are newly launched and checks if their Return on Advertising Spend (ROAS) exceeds a predefined minimum threshold. If the ROAS criterion is satisfied, the script updates the campaign’s bidding strategy to Target CPA, which is intended to improve cost efficiency and conversion rates. This automation helps advertisers manage their campaigns more effectively by ensuring that only campaigns with promising performance metrics are promoted to a more strategic bidding approach.
Walking Through the Code
- Initialization of Configurable Parameters:
- The script begins by defining configurable parameters such as
MIN_ROAS
, which sets the minimum ROAS threshold, andPUB_STRATEGY_TARGET
, which specifies the target bidding strategy as ‘TargetCpa’.
- The script begins by defining configurable parameters such as
- Data Preparation:
- Temporary columns are created in the input DataFrame to store new values for publisher strategy and target CPA. These columns are initialized with
np.nan
.
- Temporary columns are created in the input DataFrame to store new values for publisher strategy and target CPA. These columns are initialized with
- Condition Evaluation:
- The script checks if campaigns are newly launched and if their ROAS exceeds the
MIN_ROAS
. If both conditions are met, the publisher strategy is updated to ‘TargetCpa’.
- The script checks if campaigns are newly launched and if their ROAS exceeds the
- Target CPA Assignment:
- The target CPA value is assigned based on the cost per conversion metric from the input data.
- Identifying Changed Campaigns:
- The script identifies campaigns where the publisher strategy has changed and prepares a subset of the data containing only these campaigns.
- Output Preparation:
- If there are changed campaigns, the script renames columns for output and prints the results. If no changes are detected, it outputs an empty DataFrame.
Vitals
- Script ID : 143
- Client ID / Customer ID: 1306925431 / 60269477
- Action Type: Bulk Upload (Preview)
- Item Changed: Campaign
- Output Columns: Account, Campaign, Publisher Bid Strategy, Publisher Target CPA
- Linked Datasource: M1 Report
- Reference Datasource: None
- Owner: Michael Huang (mhuang@marinsoftware.com)
- Created by Michael Huang on 2023-05-25 23:04
- Last Updated by alejandro@rainmakeradventures.com on 2024-01-26 18:54
> 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
#
# Promote to new Publisher Bidding Strategy if meet minimum:
# - Spend
# - ROAS
#
#
# Author: Michael S. Huang
# Date: 2023-05-26
#
########### Configurable Params - START ##########
MIN_ROAS = .4
PUB_STRATEGY_TARGET = 'TargetCpa'
########### Configurable Params - END ###########
RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_ACCOUNT = 'Account'
RPT_COL_STRATEGY = 'Strategy'
RPT_COL_CAMP_MATURITY = 'Campaign Maturity'
RPT_COL_PUBLISHER_BIDSTRATEGY = 'Publisher Bid Strategy'
RPT_COL_PUBLISHER_TARGETCPA = 'Publisher Target CPA'
RPT_COL_COST_PER_CONV = 'CLICKS Cost/Conv.'
RPT_COL_ROAS = 'CLICKS ROAS'
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_CAMP_MATURITY] == 'New - Launch') & \
(inputDf[RPT_COL_ROAS] > MIN_ROAS), \
TMP_PUB_STRATEGY \
] = PUB_STRATEGY_TARGET
inputDf[TMP_TARGETCPA] = inputDf[RPT_COL_COST_PER_CONV]
# 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 2025-03-11 01:25:51 GMT