Script 1377: Target CPA Cap $1000

Purpose

The script enforces a Target CPA Cap of $1000 for all active strategies or campaigns.

To Elaborate

The Python script is designed to manage and enforce a cap on the Target Cost Per Acquisition (CPA) for active advertising strategies or campaigns. Specifically, it ensures that the Target CPA does not exceed $1000. This is crucial for maintaining budget control and ensuring that advertising costs do not surpass a predefined threshold. The script processes data from a primary data source, identifies campaigns with a Target CPA greater than $1000, and adjusts these values to the cap. This helps in aligning the campaign costs with the budgetary constraints and strategic financial goals of the organization.

Walking Through the Code

  1. Data Initialization
    • The script begins by defining the primary data source and relevant columns needed for processing. These columns include details about the account, campaign, strategy, and current Target CPA values.
    • An output DataFrame is initialized, copying necessary columns from the input data to prepare for further processing.
  2. Applying the Target CPA Cap
    • The script filters the campaigns to identify those with a Target CPA greater than $1000.
    • For these campaigns, the Target CPA is set to $1000, effectively capping the cost per acquisition to the specified limit.
    • The filtered DataFrame, which now contains only the campaigns where changes were made, is prepared for output, ensuring that only relevant adjustments are highlighted.

Vitals

  • Script ID : 1377
  • Client ID / Customer ID: 1306926629 / 60270083
  • Action Type: Bulk Upload
  • Item Changed: Campaign
  • Output Columns: Account, Campaign, Publisher Target CPA, Campaign ID
  • Linked Datasource: M1 Report
  • Reference Datasource: None
  • Owner: dwaidhas@marinsoftware.com (dwaidhas@marinsoftware.com)
  • Created by dwaidhas@marinsoftware.com on 2024-09-06 16:51
  • Last Updated by dwaidhas@marinsoftware.com on 2024-09-12 18:53
> 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
##
## name: TCPA Cap
## description:
##  This script helps us put a Target CPA Cap in place for all active Strategies / campaigns.
##
## author: Dana Waidhas
## created: 2024-09-06
##

today = datetime.datetime.now(CLIENT_TIMEZONE).date()

# primary data source and columns
inputDf = dataSourceDict["1"]
RPT_COL_ACCOUNT = 'Account'
RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_CAMPAIGN_STATUS = 'Campaign Status'
RPT_COL_PUBLISHER = 'Publisher'
RPT_COL_STRATEGY = 'Strategy'
RPT_COL_STRATEGY_TARGET = 'Strategy Target'
RPT_COL_PUBLISHER_BID_STRATEGY = 'Publisher Bid Strategy'
RPT_COL_PUBLISHER_TARGET_CPA = 'Publisher Target CPA'
RPT_COL_CAMPAIGN_ID = 'Campaign ID'
RPT_COL_CLICKS = 'Clicks'

# output columns and initial values
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_PUBLISHER_TARGET_CPA = 'Publisher Target CPA'
BULK_COL_CAMPAIGN_ID = 'Campaign ID'

# Initialize output dataframe with input columns
outputDf = inputDf[[RPT_COL_ACCOUNT, RPT_COL_CAMPAIGN, RPT_COL_CAMPAIGN_ID, RPT_COL_PUBLISHER_TARGET_CPA]].copy()

# Apply TCPA cap logic and filter to show only changed rows
outputDf_filtered = outputDf[outputDf[RPT_COL_PUBLISHER_TARGET_CPA] > 1000].copy()
outputDf_filtered[BULK_COL_PUBLISHER_TARGET_CPA] = 1000

# Show only the campaigns where Target CPA was capped
print(tableize(outputDf_filtered.head()))






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

comments powered by Disqus