Script 921: Bidding Strategy Assignment

Purpose

The script automates the assignment of advertising campaigns to different bidding strategies based on their creation date.

To Elaborate

The Python script is designed to automate the assignment of advertising campaigns to specific bidding strategies based on how long the campaigns have been active. Specifically, it assigns campaigns to an “Impression Share Strategy” called ‘Data Gathering’ if they have been created within the last 7 days. After the initial 7-day period, the campaigns are transitioned to a “CPA strategy” called ‘Performance Bidding’. This transition is marked by updating the ‘Folder Check’ column to “YES” for campaigns older than 7 days. The script processes a DataFrame containing campaign data, checks each campaign’s creation date, and updates the strategy and folder check status accordingly. This automation helps streamline the management of advertising campaigns by ensuring they are using the appropriate bidding strategy based on their age.

Walking Through the Code

  1. Data Preparation
    • The script begins by copying the input DataFrame to avoid modifying the original data.
    • It converts the ‘Campaign Creation Date’ column into datetime objects to facilitate date comparisons.
  2. Strategy Assignment Logic
    • The script iterates over each row in the DataFrame.
    • For each campaign, it calculates the number of days since its creation.
    • If the campaign is within 7 days of its creation date, it assigns the ‘Data Gathering’ strategy and leaves the ‘Folder Check’ column blank.
    • If the campaign is older than 7 days, it assigns the ‘Performance Bidding’ strategy and sets the ‘Folder Check’ column to “YES”.
  3. Output
    • The script prints the changes made to the DataFrame for debugging purposes.
    • Finally, it returns the modified DataFrame with updated strategies and folder check statuses.

Vitals

  • Script ID : 921
  • Client ID / Customer ID: 1306919473 / 69058
  • Action Type: Bulk Upload
  • Item Changed: Campaign
  • Output Columns: Account, Campaign, Strategy, Folder Check
  • Linked Datasource: M1 Report
  • Reference Datasource: None
  • Owner: Jeremy Brown (jbrown@marinsoftware.com)
  • Created by Jeremy Brown on 2024-04-11 09:09
  • Last Updated by Jeremy Brown on 2024-04-11 09:09
> 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
##
## name: Bidding Strategy Assignment
## description:
##
## The Script automatically assigns a campaign to an Impression Share Strategy called 'Data Gathering' for the first 7 days after being created. Then after the campaign has been live for 7 days it is moved to a CPA strategy called 'Performance Bidding'. The logic is as follows;
## When a campaign's creation date is within 7 days of today's date, it is assigned to "Data Gathering" with a blank Folder Check column (""). Otherwise, it's assigned to "Performance Bidding" with a "YES" in the Folder Check column.
## 
## author: Jeremy Brown
## created: 2024-04-11
## 

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

# primary data source and columns
inputDf = dataSourceDict["1"]
RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_ACCOUNT = 'Account'
RPT_COL_PUBLISHER = 'Publisher'
RPT_COL_STRATEGY = 'Strategy'
RPT_COL_CAMPAIGN_CREATION_DATE = 'Campaign Creation Date'
RPT_COL_FOLDER_CHECK = 'Folder Check'
RPT_COL_IMPR = 'Impr.'

def process(inputDf):
    # Make a copy of the input DataFrame
    outputDf = inputDf.copy()
    
    # Get today's date in the specified timezone
    today_date = datetime.datetime.now(CLIENT_TIMEZONE).date()
    
    # Convert 'Campaign Creation Date' column to datetime objects (assuming format dd/mm/yyyy)
    outputDf['Campaign Creation Date'] = pd.to_datetime(outputDf['Campaign Creation Date'], format='%d/%m/%Y')
    
    # Determine the strategy and folder check based on the campaign creation date
    for index, row in outputDf.iterrows():
        creation_date = row['Campaign Creation Date'].date()
        if (today_date - creation_date).days <= 7:
            # Within 7 days of today's date
            outputDf.at[index, 'Strategy'] = "Data Gathering"
            outputDf.at[index, 'Folder Check'] = ""  # Leave Folder Check blank
        else:
            # More than 7 days old
            outputDf.at[index, 'Strategy'] = "Performance Bidding"
            outputDf.at[index, 'Folder Check'] = "YES"
    
    # Debugging: Print changes made to outputDf
    print("Data Changed:")
    print(outputDf[['Account', 'Campaign', 'Strategy', 'Folder Check']])
    
    return outputDf

# Example usage:
# Assuming inputDf is your actual DataFrame with the appropriate columns
# inputDf = ...

# Process the DataFrame
outputDf = process(inputDf)

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

comments powered by Disqus