Script 1083: Conversion Influencers

Purpose

The script identifies and tags the top 10 keywords as “Top Performer” based on conversion metrics and cost efficiency 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 a 60-day period. 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 below a specified threshold. It then sorts the remaining keywords by the number of conversions in descending order and 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 keywords that provide the best return on investment.

Walking Through the Code

  1. Initialization and Setup
    • The script begins by defining a dictionary for match types and setting up the primary data source.
    • It initializes the input DataFrame with keyword performance data and specifies the relevant columns for analysis.
  2. Data Filtering and Preparation
    • The script clears the ‘Conversion Influencer’ column in the input DataFrame to prepare for new data.
    • It filters the DataFrame to include only rows where the number of conversions is greater than zero.
    • Further filtering is applied to include only keywords with a cost per conversion below $60.
  3. Sorting and Selection
    • The filtered data is sorted by the number of conversions in descending order and cost per conversion in ascending order.
    • The script then applies an additional filter to include only keywords with a cost per conversion below $40.
  4. Tagging Top Performers
    • The top 10 keywords from the sorted DataFrame are tagged as “Top Performer” in the ‘Conversion Influencer’ column.
    • This updated information is then reflected back in the original input DataFrame.
  5. Output Preparation
    • The final output DataFrame is prepared, including only the specified columns, and is printed for review.

Vitals

  • Script ID : 1083
  • Client ID / Customer ID: 1306927029 / 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:44
  • Last Updated by dwaidhas@marinsoftware.com on 2024-06-12 14:53
> 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
68
69
70
##
## 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])

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

# 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

comments powered by Disqus