Script 1081: Conversion Influencers
Purpose
The script identifies and tags the top 10 keywords as “Top Performer” based on conversion metrics over the last 60 days.
To Elaborate
The Python script is designed to analyze keyword performance data and identify the top 10 keywords that are most effective in terms of conversions and cost per conversion over the past 60 days. The script filters out keywords that have not achieved at least one conversion and further narrows down the selection to those with a cost per conversion of less than $60. It then sorts the remaining keywords by the number of conversions in descending order and by cost per conversion in ascending order. The top 10 keywords from this sorted list are tagged as “Top Performer” in the dataset. This process helps in optimizing marketing strategies by focusing on the most cost-effective keywords that drive conversions.
Walking Through the Code
- Initialization and Data Preparation
- The script begins by defining a dictionary for match types and assigns the current date to a variable.
- It initializes the primary data source and specifies the relevant columns for processing.
- Data Filtering
- The script clears the “Conversion Influencer” column in the input DataFrame.
- It filters the data to include only rows where the number of conversions is greater than zero.
- Further filtering is applied to retain only those rows where the cost per conversion is less than $60.
- Sorting and Tagging
- The filtered data is sorted by the number of conversions in descending order and by cost per conversion in ascending order.
- The top 10 keywords from this sorted list are identified and tagged as “Top Performer” in the “Conversion Influencer” column.
- Output Preparation
- The script updates the original DataFrame with the “Top Performer” tags for the top 10 keywords.
- It prepares an output DataFrame that includes specified columns and prints this DataFrame to display the results.
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 2024-11-27 06:58:46 GMT