Script 1111: Campaign Benchmarks General

Purpose

The Python script evaluates campaign performance by comparing key metrics against benchmarks and assigns performance tags accordingly.

To Elaborate

The Python script is designed to assess the performance of marketing campaigns by comparing specific metrics against predefined benchmark values. It processes input data containing metrics such as conversion rate, cost per conversion, click-through rate, and average cost per click. The script’s primary function is to determine how each campaign’s performance measures up to these benchmarks and to assign a performance tag—either “Over Target,” “Under Target,” or “On Target”—based on this comparison. Additionally, it calculates the performance ratio of each metric relative to its benchmark, providing a quantitative measure of performance. This analysis helps in identifying campaigns that are performing well, those that need improvement, and those that are meeting expectations.

Walking Through the Code

  1. Data Preparation
    • The script begins by defining the primary data source and relevant columns from the input data, which include campaign details and performance metrics.
    • It sets up an output DataFrame to store the results, specifically the account, campaign, and performance tag.
  2. Benchmark Definition and Performance Tagging
    • A benchmark value for the cost per conversion is defined as 90.0.
    • A function tag_performance is created to assign performance tags based on the comparison of a metric to its benchmark. It returns “On Target” if the metric equals the benchmark, “Over Target” if it exceeds, and “Under Target” if it is below.
  3. Performance Calculation and Output
    • The script calculates the performance ratio for the cost per conversion by dividing the actual cost by the benchmark.
    • It applies the tag_performance function to determine the performance tag for each campaign based on the cost per conversion.
    • The performance tag is then assigned to the output DataFrame, which is printed for verification.

Vitals

  • Script ID : 1111
  • Client ID / Customer ID: 1306926629 / 60270083
  • Action Type: Bulk Upload
  • Item Changed: Campaign
  • Output Columns: Account, Campaign, Performance Tag
  • Linked Datasource: M1 Report
  • Reference Datasource: None
  • Owner: dwaidhas@marinsoftware.com (dwaidhas@marinsoftware.com)
  • Created by dwaidhas@marinsoftware.com on 2024-05-17 12:11
  • Last Updated by dwaidhas@marinsoftware.com on 2024-05-23 20:25
> 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
58
59
60
61
62
##
## name: Campaign Benchmarks
## description:
##  This Python script is designed to tag campaigns based on their performance metrics compared to benchmarks. The script takes input data with metrics such as conversion rate, cost per conversion, click-through rate, and average cost per click. It then compares these metrics to benchmark values and assigns a performance tag to each campaign based on the comparison. The performance tags include “Over Target,” “Under Target,” and “On Target.” The script also calculates the performance ratio of each metric to its benchmark.
## 
## author: Dana Waidhas 
## created: 2024-05-17
## 


# Assume CLIENT_TIMEZONE is defined somewhere in your environment
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_CAMPAIGN_TYPE = 'Campaign Type'
RPT_COL_CAMPAIGN_STATUS = 'Campaign Status'
RPT_COL_CONV_RATE = 'Conv. Rate %'
RPT_COL_COST_PER_CONV = 'Cost/Conv. $'
RPT_COL_CTR = 'CTR %'
RPT_COL_AVG_CPC = 'Avg. CPC $'
RPT_COL_IMPR = 'Impr.'
RPT_COL_CLICKS = 'Clicks'
RPT_COL_PUB_COST = 'Pub. Cost $'
RPT_COL_CONV = 'Conv.'
RPT_COL_IMPR_SHARE = 'Impr. share %'

# Output Columns
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_PERFORMANCE_TAG = 'Performance Tag'


# Define benchmark values
benchmark_cost_per_conv = 90.0

# Function to tag performance
def tag_performance(metric, benchmark):
    if metric == benchmark:
        return 'On Target'
    elif metric > benchmark:
        return 'Over Target'
    else:
        return 'Under Target'

# Create output DataFrame
outputDf = pd.DataFrame()
outputDf[BULK_COL_ACCOUNT] = inputDf[RPT_COL_ACCOUNT]
outputDf[BULK_COL_CAMPAIGN] = inputDf[RPT_COL_CAMPAIGN]

# Calculate performance ratio and tag
outputDf['Cost/Conv. Ratio'] = inputDf[RPT_COL_COST_PER_CONV] / benchmark_cost_per_conv
outputDf['Cost/Conv. Tag'] = inputDf[RPT_COL_COST_PER_CONV].apply(tag_performance, args=(benchmark_cost_per_conv,))

# Assign the performance tag based only on Cost/Conv
outputDf[BULK_COL_PERFORMANCE_TAG] = outputDf['Cost/Conv. Tag']

# Print the first few rows of the output DataFrame for verification
print(outputDf.head())

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

comments powered by Disqus