Script 141: New Campaigns Pause Low ROAS
Purpose
Pause new campaigns with low ROAS based on specific criteria.
To Elaborate
The Python script aims to identify and pause new campaigns that have a low Return on Ad Spend (ROAS) based on predefined criteria. The script checks the ROAS of each campaign and compares it to the specified minimum and maximum ROAS values for each campaign round. If a campaign meets the criteria, its status is changed to “Paused”. The script then generates an output with the campaigns that had their status changed.
Walking Through the Code
- Define the campaign pause criteria, which includes the minimum and maximum ROAS values for each campaign round.
- Define the column parameters used in the script.
- Create a temporary column to store the new campaign status and set it to empty.
- Loop through each pause criteria and apply it to the input data frame.
- Find the campaigns that had their status changed.
- If there are changed campaigns, print a table with the campaigns and create an output data frame with the relevant columns.
- If there are no changed campaigns, print a message indicating an empty output data frame.
Vitals
- Script ID : 141
- Client ID / Customer ID: 1306925431 / 60269477
- Action Type: Bulk Upload (Preview)
- Item Changed: Campaign
- Output Columns: Account, Campaign, Status, Script Paused
- Linked Datasource: M1 Report
- Reference Datasource: None
- Owner: Michael Huang (mhuang@marinsoftware.com)
- Created by Michael Huang on 2023-05-25 20:20
- Last Updated by alejandro@rainmakeradventures.com on 2024-01-26 18:55
> 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
#
# Pause Low ROAS New Campaigns
#
#
# Author: Michael S. Huang
# Date: 2023-05-26
#
# define campaign LOW ROAS PAUSE criteria
# note: MIN values are inclusive; MAX values are non-inclusive
campaign_pause_criteria = [
# format:
# (min spend, max spend, min roas, max roas),
('New - Launch', 0, .4),
('New - Round 2', 0, .2999),
('New - Round 3', 0, .5),
('New - Round 4', 0, .5),
('New - Round 5', 0, .5)
]
# define column parameters
RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_ACCOUNT = 'Account'
RPT_COL_STRATEGY = 'Strategy'
RPT_COL_CAMPAIGN_STATUS = 'Campaign Status'
RPT_COL_CAMP_MATURITY = 'Campaign Maturity'
RPT_COL_ROAS = 'CLICKS ROAS'
RPT_COL_PUBLISHER_TARGETCPA = 'Publisher Target CPA'
RPT_COL_DAILY_BUDGET = 'Daily Budget'
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_STATUS = 'Status'
BULK_COL_SCRIPT_PAUSED = 'Script Paused'
VAL_STATUS_PAUSED = 'Paused'
# create temp column to store new status and default to empty
TMP_STATUS = RPT_COL_CAMPAIGN_STATUS + '_'
inputDf[TMP_STATUS] = np.nan
# loop through each PAUSE criteria and apply
for (new_round, min_roas, max_roas) in campaign_pause_criteria:
print(f"Applying pause criteria: new round={new_round}, min roas={min_roas}, max roas={max_roas}")
inputDf.loc[ (inputDf[RPT_COL_CAMP_MATURITY] == new_round) & \
(inputDf[RPT_COL_ROAS] >= min_roas) & \
(inputDf[RPT_COL_ROAS] < max_roas) & \
(inputDf[RPT_COL_ACCOUNT] == 'ExplorAds Google'), \
TMP_STATUS \
] = VAL_STATUS_PAUSED
# find changed campaigns
changed = inputDf[TMP_STATUS].notnull() & (inputDf[RPT_COL_CAMPAIGN_STATUS] != inputDf[TMP_STATUS])
if sum(changed) > 0:
print("== Campaigns with Changed Status ==", tableize(inputDf.loc[changed]))
# only select changed rows
cols = [RPT_COL_ACCOUNT, RPT_COL_CAMPAIGN, TMP_STATUS]
outputDf = inputDf.loc[ changed, cols ].copy() \
.rename(columns = { \
TMP_STATUS: BULK_COL_STATUS \
})
outputDf[BULK_COL_SCRIPT_PAUSED] = datetime.datetime.now(CLIENT_TIMEZONE).date()
print("outputDf", tableize(outputDf))
else:
print("Empty outputDf")
outputDf = pd.DataFrame(columns=[BULK_COL_ACCOUNT, BULK_COL_CAMPAIGN, BULK_COL_STATUS, BULK_COL_SCRIPT_PAUSED])
Post generated on 2024-05-15 07:44:05 GMT