Script 159: Increase Campaign tCPA

Purpose

Python script to increase the bid/TCPA by a certain percentage if the cost per set is less than 1500.

To Elaborate

The Python script aims to automate the process of increasing the bid/TCPA for campaigns if the cost per set is below a certain threshold. The key business rules are as follows:

  • If the cost per set is less than 1500, the bid/TCPA should be increased by a certain percentage.
  • The script should add a value for the date of the change.
  • The bid/TCPA should not be changed if the value is within a certain number of days.

Walking Through the Code

  1. The script defines column constants for various data columns used in the code.
  2. The current date is assigned to the today variable.
  3. The outputDf DataFrame is created as a copy of the inputDf DataFrame.
  4. A temporary column called percentage_diff is created to store the percentage difference between the cost per set and 1500.
  5. The new bid/TCPA values are calculated by multiplying the original bid/TCPA with (1 + percentage_diff).
  6. The Publisher Target CPA column in the outputDf DataFrame is updated with the new bid/TCPA values.
  7. The tableize function is called to print the outputDf DataFrame in a tabular format.

Vitals

  • Script ID : 159
  • Client ID / Customer ID: 1306924501 / 60269325
  • Action Type: Bulk Upload (Preview)
  • Item Changed: Campaign
  • Output Columns: Account, Campaign, Publisher Target CPA, Last Updated - tCPA
  • Linked Datasource: M1 Report
  • Reference Datasource: None
  • Owner: Byron Porter (bporter@marinsoftware.com)
  • Created by Byron Porter on 2023-06-02 21:37
  • Last Updated by lneels@marinsoftware.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
#
# Increase Campaign tCPA
#
# Byron Porter
# 2023-06-03
#
RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_ACCOUNT = 'Account'
RPT_COL_CAMPAIGN_STATUS = 'Campaign Status'
RPT_COL_SET_COST_PER_CONV = 'Set Lead (Set30) Cost/Conv.'
RPT_COL_PUB_TCPA = 'Publisher Target CPA'
RPT_COL_LAST_UPDATEDTCPA = 'Last Updated - tCPA'
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_DAILY_BUDGET = 'Daily Budget'
BULK_COL_LAST_UPDATEDDAILYBUDGET = 'Last Updated - Daily Budget'


# Assign current date to a parameter
today = datetime.datetime.now() #.date()


outputDf = inputDf.copy()

# create temp column to store new values and default to empty
percentage_diff = 1 - (inputDf['Set Lead (Set30) Cost/Conv.'] / 1500)

newcpa = inputDf['Publisher Target CPA'] * (1 + percentage_diff)

outputDf['Publisher Target CPA'] = newcpa

print(tableize(outputDf))

Post generated on 2024-05-15 07:44:05 GMT

comments powered by Disqus