Script 1705: Script Campaign level Suggested Strategies

Purpose:

The Python script categorizes marketing campaigns into different strategies based on their Return on Advertising Spend (ROAS) performance.

To Elaborate

The script is designed to optimize marketing campaign strategies by evaluating their performance through the Return on Advertising Spend (ROAS) metric. It assesses each campaign’s ROAS over the past 14 days and assigns it to one of three predefined strategies: Generic High ROAS, Generic Medium ROAS, or Generic Low ROAS. The decision criteria are straightforward: if a campaign’s ROAS exceeds 40, it is categorized under “Generic High ROAS”; if it falls between 35 and 40, it is assigned to “Generic Medium ROAS”; otherwise, it is placed in “Generic Low ROAS”. This structured approach allows for dynamic reallocation of campaigns to strategies that better align with their current performance, thereby potentially enhancing overall marketing efficiency.

Walking Through the Code

  1. Initialization and Setup
    • The script begins by setting up the current date and time zone, which is used for time-related operations.
    • It defines the primary data source and specifies the relevant columns needed for processing, such as campaign details and ROAS metrics.
  2. Function Definition
    • A function map_strategy_to_roas is defined to determine the suggested strategy based on the ROAS value. This function uses conditional logic to categorize the ROAS into one of the three strategies.
  3. Data Processing
    • The script applies the map_strategy_to_roas function to the ROAS column of the input data frame, thereby populating the “Suggested Strategy” column with the appropriate strategy for each campaign.
  4. Output Preparation
    • It prepares the output data frame by selecting only the necessary columns: Account, Campaign, and Suggested Strategy, ensuring the output is concise and relevant.
  5. Verification
    • Finally, the script prints the first few rows of the output data frame for verification purposes, allowing users to quickly check the results of the strategy mapping.

Vitals

  • Script ID : 1705
  • Client ID / Customer ID: 1306914662 / 3614566
  • Action Type: Bulk Upload (Preview)
  • Item Changed: Campaign
  • Output Columns: Account, Campaign, Suggested Strategy
  • Linked Datasource: M1 Report
  • Reference Datasource: None
  • Owner: Grégory Pantaine (gpantaine@marinsoftware.com)
  • Created by Grégory Pantaine on 2025-02-07 13:36
  • Last Updated by Grégory Pantaine on 2025-02-19 15:23
> 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
##
## name: Script: Campaign level: Suggested Strategies
## description: Use the ROAS column to define in which strategy should a campaign be mapped to.
## for example if "campaign A" is in stratregy "Generic 35 ROAS" but for the last 14 days has a ROAS of 10, then move it to Strategy "Generic 15 ROAS".
## there are 3 strategies in which we can move the campaigns between:
## Generic Medium ROAS
## Generic Low ROAS
## Generic High ROAS
## the criteria would be:
## If campaign ROAS > 40 set "Suggested Strategy" to "Generic High ROAS"
## If campaign ROAS > 35 but < 40 set "Suggested Strategy" to "Generic Medium ROAS"
## else set to "Generic Low ROAS"
## author: Greg Pantaine and ChatGPT
## created: 2025-02-07
## 

today = datetime.datetime.now(CLIENT_TIMEZONE).date()
# Define current date
CLIENT_TIMEZONE = datetime.timezone.utc  # Modify as needed
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_CAMPAIGN_STATUS = 'Campaign Status'
RPT_COL_STRATEGY = 'Strategy'
RPT_COL_PUB_COST = 'Pub. Cost €'
RPT_COL_PURCHASE_CONV = 'Purchase Conv.'
RPT_COL_PURCHASE_REVENUE = 'Purchase Revenue'
RPT_COL_PURCHASE_ROAS = 'Purchase ROAS'
RPT_COL_SUGGESTEDSTRATEGY = 'Suggested Strategy'

# Output columns
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_SUGGESTED_STRATEGY = 'Suggested Strategy'

# Function to determine the suggested strategy based on ROAS
def map_strategy_to_roas(roas_value):
    if roas_value > 40:
        return "Generic High ROAS"
    elif 35 < roas_value <= 40:
        return "Generic Medium ROAS"
    else:
        return "Generic Low ROAS"

# Ensure ROAS is correctly used from RPT_COL_PURCHASE_ROAS
inputDf[RPT_COL_SUGGESTEDSTRATEGY] = inputDf[RPT_COL_PURCHASE_ROAS].apply(map_strategy_to_roas)

# Prepare the output dataframe
outputDf = inputDf[[RPT_COL_ACCOUNT, RPT_COL_CAMPAIGN, RPT_COL_SUGGESTEDSTRATEGY]].copy()

# Print the first few rows for verification
print(tableize(outputDf.head()))

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

comments powered by Disqus