Script 143: New Campaigns Switch to tCPA

Purpose

Switch campaign publisher bidding strategy to tCPA based on spend and ROAS.

To Elaborate

The Python script solves the problem of automatically switching the publisher bidding strategy for campaigns to tCPA (Target Cost Per Acquisition) if they meet certain criteria for spend and ROAS (Return on Ad Spend). The key business rules are:

  • The minimum ROAS threshold is set to 0.4.
  • The target publisher bidding strategy is set to ‘TargetCpa’.
  • The script identifies campaigns that are in the ‘New - Launch’ maturity stage and have a ROAS greater than the minimum threshold.
  • If a campaign meets these criteria, its publisher bidding strategy is updated to ‘TargetCpa’ and its target CPA is set to the cost per conversion value.
  • The script then identifies the campaigns that have had their publisher bidding strategy changed.
  • If there are any campaigns with changed publisher bidding strategies, the script outputs a DataFrame containing the account, campaign, new publisher bidding strategy, and new target CPA.
  • If there are no campaigns with changed publisher bidding strategies, the script outputs an empty DataFrame.

Walking Through the Code

  1. The configurable parameters are set at the beginning of the script:
    • MIN_ROAS: The minimum ROAS threshold (0.4 in this case).
    • PUB_STRATEGY_TARGET: The target publisher bidding strategy (‘TargetCpa’ in this case).
  2. Temporary columns are created in the input DataFrame to store the new values for publisher bidding strategy and target CPA.
  3. The script checks if a campaign is in the ‘New - Launch’ maturity stage and has a ROAS greater than the minimum threshold. If so, it updates the temporary publisher bidding strategy column with the target bidding strategy and the temporary target CPA column with the cost per conversion value.
  4. The script identifies campaigns that have had their publisher bidding strategy changed by comparing the temporary publisher bidding strategy column with the original publisher bidding strategy column.
  5. If there are campaigns with changed publisher bidding strategies, the script outputs a DataFrame containing the account, campaign, new publisher bidding strategy, and new target CPA.
  6. If there are no campaigns with changed publisher bidding strategies, the script 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-05-15 07:44:05 GMT

comments powered by Disqus