Script 1543: Script Keywords Clicks 10 & Clicks 100 & Cost per Conversion 2 80€ = PAUSE
Purpose:
The Python script pauses keywords in a report that have between 10 and 100 clicks and a cost per conversion greater than €2.80 over the last 7 days.
To Elaborate
The script is designed to manage keyword performance in advertising campaigns by pausing keywords that meet specific criteria. It targets keywords that have received more than 10 clicks but fewer than 100 clicks, and have a cost per conversion exceeding €2.80 within the last 7 days. This is a common practice in digital marketing to optimize budget allocation by halting underperforming keywords that are not cost-effective. By pausing these keywords, the script helps in reallocating resources to more profitable keywords, thereby improving the overall efficiency of the advertising campaign. The script operates on data extracted from a report, updating the status of qualifying keywords to “PAUSED” and recording the date of this action.
Walking Through the Code
- Initialization:
- The script begins by defining a dictionary
MATCH_TYPE
to categorize keywords by match type (exact, phrase, broad). - It retrieves the current date using the
datetime
module, which is used later to timestamp actions.
- The script begins by defining a dictionary
- Data Handling:
- The script accesses the primary data source,
inputDf
, which contains keyword performance metrics. - It initializes an output DataFrame,
outputDf
, as a copy ofinputDf
to store modified data.
- The script accesses the primary data source,
- Keyword Filtering and Status Update:
- The script sets the status of all keywords in
outputDf
to “PAUSED”. - It updates the
BULK_COL_SCRIPT_PAUSE_DATE
column with the current date to record when the keywords were paused.
- The script sets the status of all keywords in
- Conditional Override:
- The script checks if the
RPT_COL_CONV_CCTSOURCETEMPLATE
column is blank and setsBULK_COL_CCTOVERRIDE
to “True” if it is not blank, otherwise it remains empty.
- The script checks if the
- Output:
- The script prints a table representation of the first few rows of
inputDf
for verification purposes.
- The script prints a table representation of the first few rows of
Vitals
- Script ID : 1543
- Client ID / Customer ID: 1306928253 / 60270461
- Action Type: Bulk Upload (Preview)
- Item Changed: Keyword
- Output Columns: Account, Campaign, Group, Keyword, Match Type, Status, Script Pause Date, CCT_override
- Linked Datasource: M1 Report
- Reference Datasource: None
- Owner: Grégory Pantaine (gpantaine@marinsoftware.com)
- Created by Grégory Pantaine on 2024-11-27 14:24
- Last Updated by Grégory Pantaine on 2024-12-04 09:49
> 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
##
## name: Script: Keywords: Clicks > 10
## & Clicks <100 & Cost per Conversion >2,80€ = PAUSE
##
## description: Pause all keywords in the report which matches
## more than 10 clicks, less than 100 and a CPA of over 2.80 for
## the last 7 days.
##
##
## author: ChatGPT, Marin, Gregory Pantaine
## created: 2024-11-27
##
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_STATUS = 'Status'
RPT_COL_MATCH_TYPE = 'Match Type'
RPT_COL_PUBLISHER = 'Publisher'
RPT_COL_ACCOUNT = 'Account'
RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_GROUP = 'Group'
RPT_COL_IMPR = 'Impr.'
RPT_COL_CLICKS = 'Clicks'
RPT_COL_PUB_COST = 'Pub. Cost €'
RPT_COL_CTR = 'CTR %'
RPT_COL_AVG_CPC = 'Avg. CPC €'
RPT_COL_IMPR_SHARE = 'Impr. share %'
RPT_COL_CONV = 'Conv.'
RPT_COL_COST_PER_CONV = 'Cost/Conv. €'
RPT_COL_CONV_RATE = 'Conv. Rate %'
RPT_COL_CONV_CCTSOURCETEMPLATE = 'CCT_sourcetemplate'
# 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_STATUS = 'Status'
BULK_COL_SCRIPT_PAUSE_DATE = 'Script Pause Date'
BULK_COL_CCTOVERRIDE = 'CCT_override'
# Initialize output DataFrame
outputDf = inputDf.copy()
outputDf[BULK_COL_STATUS] = "PAUSED"
outputDf[BULK_COL_SCRIPT_PAUSE_DATE] = today.strftime('%Y-%m-%d')
# Set CCT_override to "true" only when CCT_sourcetemplate is blank
outputDf[BULK_COL_CCTOVERRIDE] = outputDf[RPT_COL_CONV_CCTSOURCETEMPLATE].isna().map({True: "", False: "True"})
# user code start here
print(tableize(inputDf.head()))
Post generated on 2025-03-11 01:25:51 GMT