Script 409: New Launch Updates Round 2

Purpose

The script updates campaign parameters such as status, daily budget, and target CPA for new launch campaigns based on specified ROAS criteria.

To Elaborate

The Python script is designed to adjust various parameters of new launch advertising campaigns based on their Return on Advertising Spend (ROAS). It applies specific criteria to determine whether a campaign’s status should be changed to ‘PAUSE’ or ‘ACTIVE’, and whether adjustments to the daily budget or target Cost Per Acquisition (tCPA) are necessary. The script processes input data to identify campaigns that meet the defined ROAS thresholds and applies the corresponding adjustments. This ensures that campaigns are optimized for performance by pausing underperforming ones and adjusting budgets and tCPA for those that are performing within acceptable ranges.

Walking Through the Code

  1. Initialization and Setup
    • The script begins by defining constants for column names used in the input data frame.
    • It sets up a list of tuples, newlaunch_adj_criteria, which contains the criteria for adjusting campaigns. Each tuple specifies minimum and maximum ROAS, budget adjustment, tCPA adjustment, and the desired status.
  2. Processing Campaigns
    • Temporary columns are created in the input data frame to store new values for status, budget, and tCPA.
    • The script iterates over each set of criteria in newlaunch_adj_criteria. For each set, it identifies campaigns that fall within the specified ROAS range.
    • For matched campaigns, it calculates the new budget and tCPA based on the adjustment factors and updates the temporary columns with these values and the new status.
  3. Identifying and Outputting Changes
    • The script checks for campaigns where any of the temporary values differ from the original values, indicating a change.
    • It creates an output data frame containing only the campaigns with changes, renaming the temporary columns to match the expected output format.
    • If no changes are detected, an empty data frame is prepared for output.

Vitals

  • Script ID : 409
  • Client ID / Customer ID: 1306925431 / 60269477
  • Action Type: Bulk Upload (Preview)
  • Item Changed: Campaign
  • Output Columns: Account, Campaign, Status, Daily Budget, Publisher Target CPA
  • Linked Datasource: M1 Report
  • Reference Datasource: None
  • Owner: Byron Porter (bporter@marinsoftware.com)
  • Created by Byron Porter on 2023-10-24 21:53
  • Last Updated by simon@rainmakeradventures.com on 2023-12-06 04:01
> 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
104
#
# Update, Status, tCPA, Bid Strategy, and or Campaign Maturity for New Launch Campaigns
#  
#  
#
#
# Author: Byron Porter
# Date: 2023-10-16
#


RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_ACCOUNT = 'Account'
RPT_COL_CAMPAIGN_STATUS = 'Campaign Status'
RPT_COL_DAILY_BUDGET = 'Daily Budget'
RPT_COL_PUBLISHER_BIDSTRATEGY = 'Publisher Bid Strategy'
RPT_COL_PUBLISHER_TARGETCPA = 'Publisher Target CPA'
RPT_COL_PUB_COST = 'Pub. Cost $'
RPT_COL_REVENUE = 'Revenue $'
RPT_COL_ROAS = 'CLICKS ROAS'
RPT_COL_RPC = 'Rev./Click $'
RPT_COL_CLICKS = 'Clicks'
RPT_COL_MATURITY = 'Campaign Maturity'

BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_STATUS = 'Status'
BULK_COL_DAILY_BUDGET = 'Daily Budget'
BULK_COL_PUBLISHER_TARGETCPA = 'Publisher Target CPA'
BULK_COL_PUBLISHER_BIDSTRATEGY = 'Publisher Bid Strategy'
BULK_COL_MATURITY = 'Campaign Maturity'


#set maturity parameter value so that it can be used in tuple
current_maturity = inputDf[RPT_COL_MATURITY]

# Define thesholds/conditions for updating New Launch Campaign values
newlaunch_adj_criteria = [
    # format:
    # (min roas, max roas, budget adj, tCPA adj, status, maturity)
    (.70, .75, 0.0, 0.0, 'PAUSE'),
    (.75, 1, 0.0, .10, 'ACTIVE'),
    (1, 100, .25, 0.0, 'ACTIVE')
]


# temp columns to house new values and make sure all values are cleared out
TMP_STATUS = RPT_COL_CAMPAIGN_STATUS + '_'
inputDf[TMP_STATUS] = np.nan

TMP_BUDGET = RPT_COL_DAILY_BUDGET + '_'
inputDf[TMP_BUDGET] = np.nan

TMP_TARGETCPA = RPT_COL_PUBLISHER_TARGETCPA + '_'
inputDf[TMP_TARGETCPA] = np.nan


# loop through each adj criteria tuple and apply
for (min_roas, max_roas, budget_adj, tcpa_adj, status) in newlaunch_adj_criteria:

    print(f"Applying adj criteria: min roas={min_roas}, max roas={max_roas}, budget adj={budget_adj}, tcpa adj={tcpa_adj}, status ={status}")

    matched_campaigns = (inputDf[RPT_COL_ROAS] >= min_roas) & \
                        (inputDf[RPT_COL_ROAS] < max_roas)
                        

    if sum(matched_campaigns) > 0:
        print("matched campaigns: ", sum(matched_campaigns))

        new_budget = inputDf.loc[matched_campaigns, RPT_COL_DAILY_BUDGET] * (1 + budget_adj)
        inputDf.loc[ matched_campaigns, TMP_BUDGET ] = new_budget

        new_tcpa = inputDf.loc[matched_campaigns, RPT_COL_PUBLISHER_TARGETCPA] * (1 - tcpa_adj)
        inputDf.loc[ matched_campaigns, TMP_TARGETCPA ] = new_tcpa

        inputDf.loc[ matched_campaigns, TMP_STATUS] = status

        print("adj applied", tableize(inputDf.loc[matched_campaigns]))


# find changed campaigns
changed = (inputDf[TMP_BUDGET].notnull() & (inputDf[RPT_COL_DAILY_BUDGET] != inputDf[TMP_BUDGET])) | \
          (inputDf[TMP_TARGETCPA].notnull() & (inputDf[RPT_COL_PUBLISHER_TARGETCPA] != inputDf[TMP_TARGETCPA])) | \
          (inputDf[TMP_STATUS].notnull() & (inputDf[RPT_COL_CAMPAIGN_STATUS] != inputDf[TMP_STATUS])) 

if sum(changed) > 0:

    print("== Campaigns with Changed Adj ==", tableize(inputDf.loc[changed]))

    # only select changed rows
    cols = [RPT_COL_ACCOUNT, RPT_COL_CAMPAIGN, TMP_BUDGET, TMP_TARGETCPA, TMP_STATUS]
    outputDf = inputDf.loc[ changed, cols ].copy() \
                    .rename(columns = { \
                        TMP_BUDGET: BULK_COL_DAILY_BUDGET, \
                        TMP_TARGETCPA: BULK_COL_PUBLISHER_TARGETCPA, \
                        TMP_STATUS: BULK_COL_STATUS \
                    })
else:
    
    print("Empty inputDf")
    outputDf = outputDf.iloc[0:0]

print("outputDf", tableize(outputDf))

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

comments powered by Disqus