Script 1081: Conversion Influencers

Purpose:

The Python script identifies and tags the top 10 keywords as “Top Performer” based on conversion and cost per conversion metrics over the last 60 days.

To Elaborate

The Python script is designed to analyze keyword performance data from a marketing campaign, focusing on conversion rates and cost per conversion over the past 60 days. It filters out keywords that have not achieved at least one conversion and further refines the selection to those with a cost per conversion below $60. The script then sorts these keywords by conversion rate in descending order and cost per conversion in ascending order to identify the top 10 keywords. These top-performing keywords are tagged as “Top Performer” in the dataset, allowing marketers to easily identify which keywords are most effective in driving conversions at a lower cost.

Walking Through the Code

  1. Initialization and Data Preparation
    • The script begins by clearing the ‘Conversion Influencer’ column in the input DataFrame, preparing it for new data.
    • It filters the DataFrame to include only rows where the conversion count is greater than zero, ensuring that only effective keywords are considered.
  2. Filtering and Sorting
    • The script further filters the data to include only keywords with a cost per conversion less than $60, focusing on cost-effective conversions.
    • It sorts the filtered data by conversion count in descending order and cost per conversion in ascending order, prioritizing high conversion rates and low costs.
  3. Tagging Top Performers
    • The top 10 keywords from the sorted list are tagged as “Top Performer” in the ‘Conversion Influencer’ column.
    • The original DataFrame is updated to reflect these top performers, ensuring the tag is applied correctly.
  4. Output Preparation
    • The script prepares the output DataFrame, including specified columns such as account, campaign, group, keyword, match type, and conversion influencer.
    • Finally, it prints the output DataFrame, showcasing the top-performing keywords and their associated data.

Vitals

  • Script ID : 1081
  • Client ID / Customer ID: 1306927027 / 60270153
  • Action Type: Bulk Upload
  • Item Changed: Keyword
  • Output Columns: Account, Campaign, Group, Keyword, Match Type, Conversion Influencer
  • Linked Datasource: M1 Report
  • Reference Datasource: None
  • Owner: dwaidhas@marinsoftware.com (dwaidhas@marinsoftware.com)
  • Created by dwaidhas@marinsoftware.com on 2024-05-13 20:27
  • Last Updated by dwaidhas@marinsoftware.com on 2024-06-12 14:51
> 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
63
64
65
66
67
##
## name: Conversion Influencers
## description:
##  Populates Conversion Influencers dimension for the top 10 keywords based on Conv. and Cost/Conv.
##  - Conv. and Cost/Conv. over the last 60 days are considered
##  - At least 1 conversion needed to be considered
## 
## author: Dana Waidhas 
## created: 2024-05-13
## 

MATCH_TYPE = {
  'EXACT': 'exact',
  'PHRASE': 'phrase',
  'BROAD': 'broad',
}
today = datetime.datetime.now(CLIENT_TIMEZONE).date()

# primary data source and columns
inputDf = dataSourceDict["1"]
RPT_COL_KEYWORD = 'Keyword'
RPT_COL_ACCOUNT = 'Account'
RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_GROUP = 'Group'
RPT_COL_MATCH_TYPE = 'Match Type'
RPT_COL_STATUS = 'Status'
RPT_COL_CONV = 'Conv.'
RPT_COL_COST_PER_CONV = 'Cost/Conv. $'
RPT_COL_CONVERSION_INFLUENCER = 'Conversion Influencer'

# output columns and initial values
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_GROUP = 'Group'
BULK_COL_KEYWORD = 'Keyword'
BULK_COL_MATCH_TYPE = 'Match Type'
BULK_COL_CONVERSION_INFLUENCER = 'Conversion Influencer'

# user code start here

# Assign current date to a parameter
today = datetime.datetime.now(CLIENT_TIMEZONE).date()

# Clear the Conversion Influencer column
inputDf[RPT_COL_CONVERSION_INFLUENCER] = np.nan

# Filter to include only rows with at least 1 conversion
inputDf = inputDf[inputDf[RPT_COL_CONV] > 0]

# Further filter to include only rows with Cost/Conv. $ smaller than 60
filteredDf = inputDf[inputDf[RPT_COL_COST_PER_CONV] < 60]

# Sort by Conv. in descending order and then by Cost/Conv. in ascending order
sortedDf = inputDf.sort_values(by=[RPT_COL_CONV, RPT_COL_COST_PER_CONV], ascending=[False, True])

# Tag the top 10 keywords as "Top Performer"
top10Df = sortedDf.head(10).copy()
top10Df[RPT_COL_CONVERSION_INFLUENCER] = "Top Performer"

# Update the original input dataframe with the top 10 performers
inputDf.loc[top10Df.index, RPT_COL_CONVERSION_INFLUENCER] = "Top Performer"

# Output dataframe includes all keywords with the specified columns
outputDf = inputDf[[BULK_COL_ACCOUNT, BULK_COL_CAMPAIGN, BULK_COL_GROUP, BULK_COL_KEYWORD, BULK_COL_MATCH_TYPE, BULK_COL_CONVERSION_INFLUENCER]]

# Print the output DataFrame
print("outputDf\n", outputDf.to_string(index=False))

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

comments powered by Disqus