Script 1505: Sample Script Campaign Benchmark Analysis
Purpose
The Python script tags campaigns based on their performance metrics compared to predefined benchmarks.
To Elaborate
The script is designed to evaluate marketing campaigns by comparing their performance metrics against set benchmarks. It processes input data containing various metrics such as conversion rate, cost per conversion, click-through rate, and average cost per click. By comparing these metrics to benchmark values, the script assigns a performance tag to each campaign, categorizing them as “Over Target,” “Under Target,” or “On Target.” Additionally, it calculates the performance ratio of each metric relative to its benchmark, providing a quantitative measure of how each campaign performs against the expected standards. This analysis helps in identifying campaigns that are performing well or need improvement, thereby aiding in strategic decision-making for marketing efforts.
Walking Through the Code
- Data Preparation
- The script begins by defining the primary data source and relevant columns from the input data, which includes metrics like conversion rate and cost per conversion.
- It sets up an output DataFrame to store results, specifically the account and campaign names.
- Benchmark Definition and Performance Tagging
- A benchmark value for the cost per conversion is defined, which is a user-changeable parameter.
- A function
tag_performance
is created to assign performance tags based on whether the metric is equal to, greater than, or less than the benchmark.
- Performance Calculation and Output
- The script calculates the performance ratio for the cost per conversion by dividing the actual metric by the benchmark.
- It applies the
tag_performance
function to determine the performance tag for each campaign based on the cost per conversion. - The resulting performance tags are stored in the output DataFrame, which is then printed for verification.
Vitals
- Script ID : 1505
- Client ID / Customer ID: 1306928469 / 60270543
- Action Type: Bulk Upload (Preview)
- Item Changed: Campaign
- Output Columns: Account, Campaign, Performance Tag
- Linked Datasource: M1 Report
- Reference Datasource: None
- Owner: emerryfield@marinsoftware.com (emerryfield@marinsoftware.com)
- Created by emerryfield@marinsoftware.com on 2024-11-08 23:57
- Last Updated by emerryfield@marinsoftware.com on 2024-11-08 23:57
> 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