Script 1399: Auto Tag Campaigns with Service Dimension
Purpose
The Python script automatically tags marketing campaigns with a service dimension based on the campaign name.
To Elaborate
The script is designed to automate the process of tagging marketing campaigns with a specific service dimension by analyzing the campaign names. It reads data from a primary data source, identifies the campaign names, and applies a tagging function to determine the service associated with each campaign. The function checks for specific keywords within the campaign names, such as ‘Implantes’ and ‘Invisalign’, and assigns corresponding service tags like ‘Dental Implants’ and ‘Invisalign’. This automated tagging helps in categorizing campaigns for better analysis and reporting, ensuring that each campaign is associated with the correct service offering.
Walking Through the Code
- Data Initialization
- The script begins by setting up the primary data source and defining the relevant columns for campaigns, accounts, services, and campaign IDs.
- It uses a dictionary
dataSourceDict
to access the input data frameinputDf
.
- Service Tagging Function
- A function
tag_service
is defined to determine the service type based on the campaign name. - The function checks if the campaign name contains specific keywords (‘Implantes’ or ‘Invisalign’) and returns the corresponding service name (‘Dental Implants’ or ‘Invisalign’).
- A function
- Applying the Function
- The script applies the
tag_service
function to each campaign name in the input data frame. - The results are stored in the
outputDf
under the ‘Service’ column, effectively tagging each campaign with the appropriate service dimension.
- The script applies the
- Result Preview
- Finally, the script prints a preview of the first few rows of the output data frame to verify the tagging results.
Vitals
- Script ID : 1399
- Client ID / Customer ID: 1306927943 / 60270393
- Action Type: Bulk Upload
- Item Changed: Campaign
- Output Columns: Account, Campaign, Service, Campaign ID
- Linked Datasource: M1 Report
- Reference Datasource: None
- Owner: dwaidhas@marinsoftware.com (dwaidhas@marinsoftware.com)
- Created by dwaidhas@marinsoftware.com on 2024-09-18 19:17
- Last Updated by dwaidhas@marinsoftware.com on 2024-09-18 21:37
> 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
##
## name: Auto Tag Campaigns with Service Dimension
## description:
##
##
## author: Dana Waidhas
## created: 2024-09-18
##
today = datetime.datetime.now(CLIENT_TIMEZONE).date()
# primary data source and columns
inputDf = dataSourceDict["1"]
RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_ACCOUNT = 'Account'
RPT_COL_SERVICE = 'Service'
RPT_COL_CAMPAIGN_ID = 'Campaign ID'
RPT_COL_CAMPAIGN_STATUS = 'Campaign Status'
# output columns and initial values
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_SERVICE = 'Service'
BULK_COL_CAMPAIGN_ID = 'Campaign ID'
# Function to tag Service based on campaign name
def tag_service(campaign_name):
if 'Implantes' in campaign_name:
return 'Dental Implants'
elif 'Invisalign' in campaign_name:
return 'Invisalign'
else:
return ''
# Apply the function to each campaign
outputDf[BULK_COL_SERVICE] = inputDf[RPT_COL_CAMPAIGN].apply(tag_service)
# Preview the result
print(tableize(outputDf.head()))
Post generated on 2024-11-27 06:58:46 GMT