Script 1019: Tagging dimension Script Campaigns Intent
Purpose
The Python script identifies and tags the intent of marketing campaigns based on specific keywords in their names.
To Elaborate
The script is designed to analyze marketing campaign names and determine their intent by searching for specific keywords. It uses a predefined list of keywords to identify whether a campaign is targeting the top, middle, or bottom of the sales funnel, commonly referred to as TOFU, MOFU, and BOFU. The script processes each campaign name, extracts the relevant intent keyword, and updates the dataset with this information. It ensures that only campaigns with identified intents are retained in the final output, thus providing a structured way to categorize and analyze marketing efforts based on their strategic intent.
Walking Through the Code
- Define Configurable Parameters
- The script begins by defining a list of keywords (
INTENT_KEYWORDS
) that represent different stages of the marketing funnel: TOFU, MOFU, and BOFU. - It also sets up column names for both the report and bulk data, which are used to identify and update the relevant fields in the dataset.
- The script begins by defining a list of keywords (
- Extract Intent Function
- A function named
extract_intent
is defined to process each campaign name. It converts the campaign name to lowercase and checks for the presence of any keywords from theINTENT_KEYWORDS
list. - If a keyword is found, it returns the keyword as the intent; otherwise, it returns an empty string.
- A function named
- Process Input Data
- The script creates a copy of the input data (
inputDf
) to work with, ensuring the original data remains unchanged. - It iterates over each row in the dataset, extracting the campaign name and using the
extract_intent
function to determine the intent.
- The script creates a copy of the input data (
- Update and Filter Data
- The identified intent is printed for each campaign and updated in the corresponding column of the output dataset (
outputDf
). - Rows with missing intent values are removed from the dataset to ensure only campaigns with identified intents are included in the final output.
- The identified intent is printed for each campaign and updated in the corresponding column of the output dataset (
- Output Results
- The script checks if the output dataset is empty. If not, it prints the structured data; otherwise, it indicates that no campaigns with identified intents were found.
Vitals
- Script ID : 1019
- Client ID / Customer ID: 1306927457 / 60270313
- Action Type: Bulk Upload
- Item Changed: Campaign
- Output Columns: Account, Campaign, Intent
- Linked Datasource: M1 Report
- Reference Datasource: None
- Owner: Autumn Archibald (aarchibald@marinsoftware.com)
- Created by Autumn Archibald on 2024-04-29 19:27
- Last Updated by Autumn Archibald on 2024-04-29 19:28
> 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
# Define the configurable parameters for the script
INTENT_KEYWORDS = ['tofu', 'mofu', 'bofu']
RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_ACCOUNT = 'Account'
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_INTENT = 'Intent'
# Function to extract intent from campaign name
def extract_intent(campaign_name):
campaign_lower = campaign_name.lower()
for intent in INTENT_KEYWORDS:
if intent in campaign_lower:
return intent
return ''
# Copy input rows to output
outputDf = inputDf.copy()
# Loop through all rows
for index, row in inputDf.iterrows():
campaign_name = row[RPT_COL_CAMPAIGN]
# Extract intent from campaign name
intent = extract_intent(campaign_name)
print("Campaign [%s] => Intent [%s]" % (campaign_name, intent))
# Update intent column
outputDf.at[index, BULK_COL_INTENT] = intent
# Drop any rows with missing intent values
outputDf = outputDf.dropna(subset=[BULK_COL_INTENT])
if not outputDf.empty:
print("outputDf", tableize(outputDf))
else:
print("Empty outputDf")
Post generated on 2024-11-27 06:58:46 GMT