Script 269: script good performing keyword 2
Purpose
The Python script adjusts search bids and bid overrides for keywords in advertising campaigns based on specific performance criteria.
To Elaborate
The script is designed to optimize search bids and bid overrides for keywords in advertising campaigns by evaluating their performance against predefined criteria. It categorizes campaigns into three types: Brand, Generic/Competitor, and Title, and applies different bid adjustment rules based on these categories. For instance, if a Brand campaign has more than 20 conversions with a cost per conversion below $10 and an impression share of 100%, the bid is adjusted accordingly. Similar rules apply to Generic/Competitor and Title campaigns, but with different thresholds and multipliers. The script ensures that the adjusted bids do not fall below a minimum bid threshold and updates the output data frame with the new bid values and override statuses.
Walking Through the Code
- Initialization and Setup
- The script begins by defining constants for column names used in the input and output data frames.
- It initializes new columns in the input data frame for updated bids and bid overrides, setting them to NaN initially.
- Defining Conditions
- The script defines conditions to categorize campaigns into Brand, Generic/Competitor, and Title based on the campaign name.
- These conditions are used to apply specific bid adjustment rules.
- Applying Bid Adjustments
- For Brand campaigns, if certain performance criteria are met, the script adjusts the bid or sets the bid override to ‘On’.
- Similar logic is applied to Generic/Competitor and Title campaigns, with different performance thresholds and bid multipliers.
- Finalizing Bid Overrides
- The script ensures that any bid not explicitly set to ‘On’ is marked as ‘Off’.
- It also ensures that the updated bid does not fall below the minimum bid if the bid override is ‘On’.
- Updating Output Data Frame
- The script updates the output data frame with the new bid values and override statuses.
- It filters the output data frame to include only rows where the bid has been updated or the bid override status has changed.
Vitals
- Script ID : 269
- Client ID / Customer ID: 1306912115 / 69058
- Action Type: Bulk Upload (Preview)
- Item Changed: Keyword
- Output Columns: Account, Campaign, Group, Keyword, Match Type, Bid Override, Search Bid
- Linked Datasource: M1 Report
- Reference Datasource: None
- Owner: Jonathan Reichl (jreichl@marinsoftware.com)
- Created by Jonathan Reichl on 2023-08-03 09:51
- Last Updated by Jeremy Brown on 2024-07-09 13:00
> 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
71
72
73
74
75
76
77
78
79
RPT_COL_KEYWORD = 'Keyword'
RPT_COL_CAMPAIGN_LANGUAGE = 'Campaign Language'
RPT_COL_MATCH_TYPE = 'Match Type'
RPT_COL_TITLE = 'Title'
RPT_COL_GROUP = 'Group'
RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_CAMPAIGN_STATUS = 'Campaign Status'
RPT_COL_GROUP_STATUS = 'Group Status'
RPT_COL_ACCOUNT = 'Account'
RPT_COL_IMPR = 'Impr.'
RPT_COL_CONV = 'Conv.'
RPT_COL_COST_PER_CONV = 'Cost/Conv. $'
RPT_COL_IMPR_SHARE = 'Impr. share %'
RPT_COL_SEARCH_BID = 'Search Bid'
RPT_COL_MIN_BID = 'Min Bid $'
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_GROUP = 'Group'
BULK_COL_KEYWORD = 'Keyword'
BULK_COL_MATCH_TYPE = 'Match Type'
BULK_COL_SEARCH_BID = 'Search Bid'
BULK_COL_BID_OVERRIDE = 'Bid Override'
RPT_COL_BID_OVERRIDE = 'Bid Override'
outputDf[BULK_COL_SEARCH_BID] = "<<YOUR VALUE>>"
outputDf[BULK_COL_BID_OVERRIDE] = "<<YOUR VALUE>>"
today = datetime.datetime.now(CLIENT_TIMEZONE).date()
print(tableize(inputDf))
UPDATE_BID = RPT_COL_SEARCH_BID + '_new'
UPDATE_BID_OV = BULK_COL_BID_OVERRIDE + '_new'
# blank out tmp field
inputDf[UPDATE_BID] = np.nan
inputDf[UPDATE_BID_OV] = np.nan
# Conditions for bid adjustments
brand_condition = inputDf[RPT_COL_CAMPAIGN].str.contains('Brand', case=False)
generic_competitor_condition = inputDf[RPT_COL_CAMPAIGN].str.contains('Generic|Competitor', case=False) & ~brand_condition
title_condition = inputDf[RPT_COL_CAMPAIGN].str.contains('Title', case=False) & ~brand_condition & ~generic_competitor_condition
# Apply bid adjustments
inputDf.loc[brand_condition & (inputDf[RPT_COL_CONV] > 20) & (inputDf[RPT_COL_COST_PER_CONV] < 10) & (inputDf[RPT_COL_IMPR_SHARE] <= 100), UPDATE_BID_OV] = 'On'
inputDf.loc[brand_condition & (inputDf[RPT_COL_CONV] > 20) & (inputDf[RPT_COL_COST_PER_CONV] < 10) & (inputDf[RPT_COL_IMPR_SHARE] < 100), UPDATE_BID] = inputDf[RPT_COL_SEARCH_BID]*1.15
inputDf.loc[brand_condition & (inputDf[RPT_COL_CONV] > 20) & (inputDf[RPT_COL_COST_PER_CONV] < 10) & (inputDf[RPT_COL_IMPR_SHARE] == 100), UPDATE_BID] = inputDf[RPT_COL_SEARCH_BID]
inputDf.loc[generic_competitor_condition & (inputDf[RPT_COL_CONV] > 10) & (inputDf[RPT_COL_COST_PER_CONV] < 15) & (inputDf[RPT_COL_IMPR_SHARE] <= 100), UPDATE_BID_OV] = 'On'
inputDf.loc[generic_competitor_condition & (inputDf[RPT_COL_CONV] > 10) & (inputDf[RPT_COL_COST_PER_CONV] < 15) & (inputDf[RPT_COL_IMPR_SHARE] < 100), UPDATE_BID] = inputDf[RPT_COL_SEARCH_BID]*1.10
inputDf.loc[generic_competitor_condition & (inputDf[RPT_COL_CONV] > 10) & (inputDf[RPT_COL_COST_PER_CONV] < 15) & (inputDf[RPT_COL_IMPR_SHARE] == 100), UPDATE_BID] = inputDf[RPT_COL_SEARCH_BID]
inputDf.loc[title_condition & (inputDf[RPT_COL_CONV] > 10) & (inputDf[RPT_COL_COST_PER_CONV] < 15) & (inputDf[RPT_COL_IMPR_SHARE] <= 100), UPDATE_BID_OV] = 'On'
inputDf.loc[title_condition & (inputDf[RPT_COL_CONV] > 10) & (inputDf[RPT_COL_COST_PER_CONV] < 15) & (inputDf[RPT_COL_IMPR_SHARE] < 100), UPDATE_BID] = inputDf[RPT_COL_SEARCH_BID]*1.15
inputDf.loc[title_condition & (inputDf[RPT_COL_CONV] > 10) & (inputDf[RPT_COL_COST_PER_CONV] < 15) & (inputDf[RPT_COL_IMPR_SHARE] == 100), UPDATE_BID] = inputDf[RPT_COL_SEARCH_BID]
inputDf.loc[(inputDf[UPDATE_BID_OV] != 'On'), UPDATE_BID_OV] = 'Off'
inputDf.loc[(inputDf[UPDATE_BID_OV] != 'On'), UPDATE_BID] = inputDf[RPT_COL_SEARCH_BID]
inputDf[UPDATE_BID] = inputDf.apply(
lambda row: max(row[UPDATE_BID], row[RPT_COL_MIN_BID]) if row[UPDATE_BID_OV] == 'On' else row[UPDATE_BID],
axis=1
)
#add new values to outputDf
outputDf.loc[:,BULK_COL_SEARCH_BID] = inputDf.loc[:, UPDATE_BID]
outputDf.loc[:,BULK_COL_BID_OVERRIDE] = inputDf.loc[:, UPDATE_BID_OV]
outputDf = outputDf[
(inputDf[UPDATE_BID].notnull()) &
((inputDf[UPDATE_BID_OV] == 'On') | (inputDf[UPDATE_BID_OV] != inputDf[RPT_COL_BID_OVERRIDE]))
]
Post generated on 2024-11-27 06:58:46 GMT