Script 1545: Script Keywords Clicks 100 & Cost per Conversion =2 00€ = PAUSE

Purpose:

The Python script pauses keywords with more than 100 clicks and a cost per conversion above €2 for the last 7 days.

To Elaborate

The script is designed to manage keyword performance in advertising campaigns by automatically pausing keywords that are not cost-effective. Specifically, it targets keywords that have accumulated over 100 clicks and have a cost per conversion (CPA) equal to or greater than €2 within the last week. This helps in optimizing the budget allocation by preventing further expenditure on underperforming keywords. The script uses data from a primary source to identify such keywords and updates their status to “PAUSED” in the output dataset. Additionally, it sets a flag for overriding certain conditions based on the presence of specific template data, ensuring that only relevant keywords are affected by the pause action.

Walking Through the Code

  1. Initialization:
    • The script begins by defining a dictionary for match types, which categorizes keywords into ‘exact’, ‘phrase’, and ‘broad’ types.
    • It retrieves the current date based on the client’s timezone to timestamp actions.
  2. Data Handling:
    • The script accesses a primary data source, inputDf, which contains various columns related to keyword performance metrics.
    • It creates a copy of this data source, outputDf, to prepare for modifications.
  3. Keyword Evaluation:
    • The script sets the status of all keywords in outputDf to “PAUSED”.
    • It records the date of this action in a new column, BULK_COL_SCRIPT_PAUSE_DATE.
  4. Conditional Overrides:
    • It checks if the CCT_sourcetemplate column is blank and sets the BULK_COL_CCTOVERRIDE column to “True” if not blank, allowing for conditional overrides.
  5. Output:
    • The script prints a tabular representation of the first few rows of the input data for verification purposes.

Vitals

  • Script ID : 1545
  • 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:29
  • Last Updated by Grégory Pantaine on 2024-12-04 16: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
51
52
53
54
55
56
57
58
59
60
61
##
## name: Script: Keywords: Clicks >100
## & Cost per Conversion >=2,00€= PAUSE
##
## description: Pause any keyword with more than 100 clicks
## and a CPA above 2 for the last 7 days.
##  
## 
## author: ChatGPT, Marin AI, 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

comments powered by Disqus