Script 163: Mature Campaigns Pause Low ROAS
Purpose
The script identifies and pauses mature advertising campaigns with low Return on Ad Spend (ROAS) over the past 14 days.
To Elaborate
The Python script is designed to manage advertising campaigns by pausing those that are considered mature but have a low Return on Ad Spend (ROAS) over the previous 14 days. The script uses predefined criteria to determine which campaigns should be paused, focusing on campaigns that have reached a certain level of maturity but are not performing well in terms of ROAS. This helps in optimizing the advertising budget by ensuring that funds are not wasted on underperforming campaigns. The script evaluates each campaign against the criteria and updates their status to ‘Paused’ if they meet the conditions, thereby allowing for more efficient allocation of resources.
Walking Through the Code
- Define Pause Criteria
- The script begins by defining the criteria for pausing campaigns. This includes specifying the maturity level and ROAS range. For example, campaigns labeled as ‘Mature’ with a ROAS between 0 and 0.25 are targeted for pausing.
- Initialize Temporary Status Column
- A temporary column is created in the input DataFrame to store the new status of campaigns. This column is initially set to empty.
- Apply Pause Criteria
- The script iterates over each set of pause criteria. For each campaign, it checks if the maturity and ROAS fall within the specified range. If they do, the campaign’s status is updated to ‘Paused’ in the temporary column.
- Identify and Process Changed Campaigns
- The script identifies campaigns whose status has changed to ‘Paused’. If there are any changes, it creates a new DataFrame with the relevant details and adds a timestamp indicating when the script paused the campaigns. If no changes are detected, an empty DataFrame is prepared.
Vitals
- Script ID : 163
- Client ID / Customer ID: 1306925431 / 60269477
- Action Type: Bulk Upload (Preview)
- Item Changed: Campaign
- Output Columns: Account, Campaign, Script Paused, Status
- Linked Datasource: M1 Report
- Reference Datasource: None
- Owner: Byron Porter (bporter@marinsoftware.com)
- Created by Byron Porter on 2023-06-06 22:04
- 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
#
# Pause Low ROAS Mature Campaigns
#
#
# Author: Byron Porter
# Date: 2023-06-06
#
# define campaign LOW ROAS PAUSE criteria
# note: MIN values are inclusive; MAX values are non-inclusive
campaign_pause_criteria = [
# format:
# (mature, min roas, max roas),
('Mature', 0, .25)
#('Mature II', 0, 1.2)
]
# 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'
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 (mature, min_roas, max_roas) in campaign_pause_criteria:
print(f"Applying pause criteria: maturity={mature}, min roas={min_roas}, max roas={max_roas}")
inputDf.loc[ (inputDf[RPT_COL_CAMP_MATURITY] == mature) & \
(inputDf[RPT_COL_ROAS] >= min_roas) & \
(inputDf[RPT_COL_ROAS] < max_roas), \
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['Script Paused'] = datetime.datetime.now().date()
print("outputDf", tableize(outputDf))
else:
print("Empty outputDf")
outputDf = pd.DataFrame(columns=[RPT_COL_ACCOUNT, RPT_COL_CAMPAIGN, BULK_COL_STATUS, 'Script Paused'])
Post generated on 2024-11-27 06:58:46 GMT