Script 743: Golden Hippo Pause Ads CPA

Purpose

Pauses ads that have a CPA of $150+ over the previous 7 days

To Elaborate

The Python script is designed to identify and pause ads that have a Cost Per Acquisition (CPA) of $150 or more over the previous 7 days. It aims to optimize ad performance by preventing further spending on ads that are not generating the desired results. By pausing these ads, the script helps to allocate the budget more effectively and improve overall campaign performance.

Walking Through the Code

  1. The script starts by importing the necessary libraries and defining the user-defined parameters.
  2. It retrieves the current date and time in the client’s timezone.
  3. The script then defines the primary data source and the columns to be used.
  4. It also defines the output columns and their initial values.
  5. Next, a temporary column is created to store the new status of the ads, which is initially set to “PAUSE”.
  6. The input data frame is printed using the tableize() function.
  7. The script filters the ads based on the condition that the CPA is greater than or equal to $150.
  8. The filtered ads are printed using the tableize() function.
  9. The necessary columns are selected from the filtered ads and copied to a new data frame.
  10. The temporary status column is renamed to the output column name.
  11. The final output data frame is printed using the tableize() function.

Vitals

  • Script ID : 743
  • Client ID / Customer ID: 1306925431 / 60269477
  • Action Type: Bulk Upload (Preview)
  • Item Changed: Ad
  • Output Columns: Account, Campaign, Group, Creative ID, Status
  • Linked Datasource: M1 Report
  • Reference Datasource: None
  • Owner: Byron Porter (bporter@marinsoftware.com)
  • Created by Byron Porter on 2024-03-06 19:21
  • Last Updated by Byron Porter on 2024-03-06 19:58
> 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
##
## name: Golden Hippo - Pause Ads - CPA
## description:
##  Pauses ads that have a CPA of $150+ over the previous 7 days
## 
## author: Byron Porter
## created: 2024-03-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_GROUP = 'Group'
RPT_COL_CREATIVE_ID = 'Creative ID'
RPT_COL_STATUS = 'Status'
RPT_COL_TABOOLA_COST_PER_CONV = 'Taboola Cost/Conv $'

# output columns and initial values
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_GROUP = 'Group'
BULK_COL_CREATIVE_ID = 'Creative ID'
BULK_COL_STATUS = 'Status'


# user code start here
# create temp column to store new status and default to empty
TMP_STATUS = RPT_COL_STATUS + '_'
inputDf[TMP_STATUS] = 'PAUSE'

print(tableize(inputDf))

matched_ads = (inputDf[RPT_COL_TABOOLA_COST_PER_CONV] >= 150)

print("Filtered Ads for Pausing: ", tableize(inputDf.loc[matched_ads]))

cols = [RPT_COL_ACCOUNT, RPT_COL_CAMPAIGN, RPT_COL_GROUP, RPT_COL_CREATIVE_ID, TMP_STATUS]
outputDf = inputDf.loc[ matched_ads, cols ].copy() \
                    .rename(columns = { \
                        TMP_STATUS: BULK_COL_STATUS \
                    })

print(tableize(outputDf))

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

comments powered by Disqus