Script 1079: Conversion Influencers

Purpose

Populates Conversion Influencers dimension for the top 10 keywords based on cost/conv.

To Elaborate

The Python script solves the problem of populating the Conversion Influencers dimension for the top 10 keywords based on the cost per conversion. The script considers the cost per conversion over the last 60 days and requires at least 1 conversion to be considered. The goal is to identify the keywords that have the highest cost per conversion and designate them as “Top Performers” in the Conversion Influencers dimension.

Walking Through the Code

  1. The script defines a dictionary MATCH_TYPE that maps different match types to their corresponding values.
  2. The script assigns the current date to the variable today using the datetime.now() function.
  3. The script defines the input dataframe inputDf and sets the column constants for various columns in the dataframe.
  4. The script defines the output columns and their initial values for the output dataframe.
  5. The user code starts with assigning the current date to the today variable again.
  6. The script creates a new dataframe outputDf by copying the first 10 rows of the input dataframe. The input dataframe is assumed to be sorted by the highest cost per conversion to the lowest cost per conversion.
  7. The script adds a new column BULK_COL_CONVERSION_INFLUENCER to the outputDf dataframe and sets all values to “Top Performer”.
  8. The script prints the outputDf dataframe using the tableize() function.

Vitals

  • Script ID : 1079
  • Client ID / Customer ID: 1306927757 / 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:18
  • Last Updated by dwaidhas@marinsoftware.com on 2024-05-13 20:22
> 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
##
## name: Conversion Influencers
## description:
##  Populates Conversion Influencers dimension for the top 10 keywords based on cost/conv.
##  - Cost/Conv over the last 60 days is 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()

# Copy the first 10 rows of input dataframe to a new dataframe **incoming report is sorted by highest cost/conv to the lowest cost/conv**
outputDf = inputDf.head(10)
outputDf[BULK_COL_CONVERSION_INFLUENCER] = "Top Performer"

print("outputDf", tableize(outputDf))

Post generated on 2024-05-15 07:44:05 GMT

comments powered by Disqus