Script 1687: pause low performing groups

Purpose:

The Python script pauses ad groups with over 100 clicks that have not generated any Prime Starts/Conversions in the past 30 days, ensuring they have been active for at least 30 days.

To Elaborate

The script is designed to manage advertising campaigns by identifying and pausing ad groups that are underperforming. Specifically, it targets ad groups that have accumulated more than 100 clicks but have not resulted in any Prime Starts or Conversions over the last 30 days. Additionally, these ad groups must have been active for at least 30 days to be considered for pausing. This approach helps optimize budget allocation by focusing resources on more effective ad groups, thereby improving overall campaign performance. The script processes data from a primary data source, adjusts the header row for accurate data manipulation, and checks for necessary columns before creating an output DataFrame that marks the status of these groups as “PAUSED.”

Walking Through the Code

  1. Data Preparation
    • The script begins by accessing the current date based on the client’s timezone.
    • It retrieves data from a specified data source and prepares it for processing by adjusting the header row to ensure the correct columns are used.
  2. Column Verification and Output Creation
    • The script verifies the presence of essential columns (Account, Campaign, Group) in the adjusted DataFrame.
    • If the columns are present, it constructs an output DataFrame that includes these columns and sets the status of the ad groups to “PAUSED.”
    • If the necessary columns are not found, it raises an error to alert the user.
  3. User Changeable Parameters
    • The script allows for the adjustment of the data source and the criteria for pausing ad groups, such as the number of clicks and the duration of activity.

Vitals

  • Script ID : 1687
  • Client ID / Customer ID: 1306917411 / 69058
  • Action Type: Bulk Upload
  • Item Changed: AdGroup
  • Output Columns: Account, Campaign, Group, Status, Group Status
  • Linked Datasource: FTP/Email Feed
  • Reference Datasource: None
  • Owner: Chris Jetton (cjetton@marinsoftware.com)
  • Created by Chris Jetton on 2025-02-06 17:38
  • Last Updated by Chris Jetton on 2025-02-07 17:59
> 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
##
## name: pause_low_performing_groups
## description:
##  Pause ad groups with 100+ clicks who have not driven any Prime Starts/Conv in the past 30 days (must have been live for 30 days)
## 
## author: 
## created: 2025-02-06
## 

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


RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_GROUP = 'Group'
RPT_COL_ACCOUNT = 'Account'

# primary data source and columns
inputDf = dataSourceDict["1"]
    
# Shift the header row to the correct position

#if len(inputDf) > 5:  # Ensure there are at least 6 rows
    #inputDf.columns = inputDf.iloc[5]  # Set the 6th row as headers
    #inputDf = inputDf[6:].reset_index(drop=True)  # Drop previous rows and reset index
#else:
    #raise ValueError("Input CSV file does not have enough rows to shift headers correctly.")


print("Headers after shifting:", inputDf.columns)

# output columns and initial values
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_GROUP = 'Group'
BULK_COL_STATUS = 'Status'
BULK_COL_GROUOP_STATUS = 'Group Status'
#outputDf[BULK_COL_STATUS] = "<<YOUR VALUE>>"

# user code start here
print(tableize(inputDf.head()))


# Check if the necessary columns exist after the adjustment
if all(col in inputDf.columns for col in [RPT_COL_ACCOUNT, RPT_COL_CAMPAIGN, RPT_COL_GROUP]):
    # Output DataFrame
    outputDf = pd.DataFrame({
        'Account': inputDf[RPT_COL_ACCOUNT],
        'Campaign': inputDf[RPT_COL_CAMPAIGN],
        'Group': inputDf[RPT_COL_GROUP],
        'Status': "PAUSED",
        'Group Status': "PAUSED",
    })
    print(outputDf)
else:
    raise ValueError("The expected columns are not found in the adjusted DataFrame.")

Post generated on 2025-03-11 01:25:51 GMT

comments powered by Disqus