Script 143: New Campaigns Switch to tCPA

Purpose

The script updates the bidding strategy of new campaigns to Target CPA if they meet specified spend and ROAS thresholds.

To Elaborate

The Python script is designed to automate the process of switching the bidding strategy for advertising campaigns to a Target CPA (Cost Per Acquisition) model. This change is contingent upon the campaigns meeting certain performance criteria, specifically a minimum Return on Advertising Spend (ROAS) threshold. The script evaluates campaigns that are newly launched and checks if their ROAS exceeds a predefined minimum value. If the criteria are met, the script updates the campaign’s publisher bidding strategy to Target CPA. This ensures that only campaigns demonstrating sufficient performance are transitioned to a more optimized bidding strategy, potentially improving cost efficiency and conversion rates.

Walking Through the Code

  1. Configuration Parameters:
    • The script begins by defining configurable parameters, including MIN_ROAS, which is set to 0.4, and PUB_STRATEGY_TARGET, which is set to ‘TargetCpa’. These parameters determine the minimum ROAS required for a campaign to qualify for a strategy change and the target bidding strategy, respectively.
  2. 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.
  3. Condition Check:
    • The script identifies campaigns that are newly launched and have a ROAS greater than the specified minimum. For these campaigns, it updates the temporary publisher strategy column to the target strategy (‘TargetCpa’).
  4. Cost Per Conversion Update:
    • The temporary target CPA column is updated with the cost per conversion value from the input data.
  5. Identify Changes:
    • The script checks for campaigns where the publisher strategy has changed. If changes are detected, it selects the relevant columns and prepares an output DataFrame with the updated strategies.
  6. Output:
    • If there are campaigns with changed strategies, the script prints the details. 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 2024-11-27 06:58:46 GMT

comments powered by Disqus