Script 739: Automate Campaigns DimensionTag Tactic

Purpose

The script automates the assignment of dimension tags to campaigns based on their names.

To Elaborate

The Python script is designed to automate the process of setting dimension tags for marketing campaigns by analyzing the campaign names. It identifies specific keywords within the campaign names and assigns corresponding tactic tags. This is particularly useful for marketing teams who need to categorize and manage campaigns efficiently based on predefined strategies. The script processes input data, applies rules to determine the appropriate tactic for each campaign, and outputs a refined dataset that includes only the campaigns with updated tactics. This ensures that only relevant changes are captured and reflected in the final output, streamlining the campaign management process.

Walking Through the Code

  1. Initialization and Setup
    • The script begins by defining constants for column names used in both the report and bulk data files. These constants are used to ensure consistency when referencing columns throughout the script.
    • A temporary field is created to store new tactic values as they are determined.
  2. Processing Campaign Names
    • The script initializes the temporary field with NaN values to ensure a clean slate for processing.
    • It then uses conditional logic to check if the campaign names contain specific keywords such as ‘KW-Defense’, ‘PAT-Defense’, ‘SBV-PAT-Defense’, and ‘SD-Defense’. If a match is found, the corresponding tactic is assigned to the temporary field.
  3. Output Preparation
    • The script checks for duplicate indices in the input data to ensure data integrity.
    • It copies the newly assigned tactics from the temporary field to the output data frame.
    • Finally, it filters the output data to include only those campaigns where the tactic has changed, ensuring that only relevant updates are captured in the bulk file.

Vitals

  • Script ID : 739
  • Client ID / Customer ID: 1306927405 / 60270279
  • Action Type: Bulk Upload (Preview)
  • Item Changed: Campaign
  • Output Columns: Account, Campaign, Tactic
  • Linked Datasource: M1 Report
  • Reference Datasource: None
  • Owner: Grégory Pantaine (gpantaine@marinsoftware.com)
  • Created by Grégory Pantaine on 2024-03-04 15:29
  • Last Updated by Grégory Pantaine on 2024-03-04 15:29
> 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
# Author: Gregory Pantaine
# Created: 2024-03-04
# Description: set dimensions based on campaign name
# Scripts name: Automate-Campaigns-DimensionTag-Tactic
# Report name (M1): Automate-Campaigns-SetDimensionTactic


RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_PUB_NAME = 'Publisher Name'
RPT_COL_ACCOUNT = 'Account'
RPT_COL_TACTIC = 'Tactic'
BULK_COL_ACCOUNT = 'Account'
BULK_COL_PUB_NAME = 'Publisher Name'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_TACTIC = 'Tactic'

#outputDf[BULK_COL_TACTIC] = "<<YOUR VALUE>>"

today = datetime.datetime.now(CLIENT_TIMEZONE).date()
print(tableize(inputDf))



TMP_FIELD = BULK_COL_TACTIC + '_new'
# blank out tmp field
inputDf[TMP_FIELD] = numpy.nan
inputDf.loc[ (inputDf[RPT_COL_CAMPAIGN].str.contains('KW-Defense', case=False)) , TMP_FIELD ] = 'KW Defense'
inputDf.loc[ (inputDf[RPT_COL_CAMPAIGN].str.contains('PAT-Defense', case=False)) , TMP_FIELD ] = 'PAT Defense'
inputDf.loc[ (inputDf[RPT_COL_CAMPAIGN].str.contains('SBV-PAT-Defense', case=False)) , TMP_FIELD ] = 'SBV PAT Defense'
inputDf.loc[ (inputDf[RPT_COL_CAMPAIGN].str.contains('SD-Defense', case=False)) , TMP_FIELD ] = 'SD Defense'

print(tableize(inputDf))

print(inputDf.index.duplicated())

# copy new strategy to output
outputDf.loc[:,BULK_COL_TACTIC] = inputDf.loc[:, TMP_FIELD]

# only include campaigns with changed strategy in bulk file
outputDf = outputDf[ inputDf[TMP_FIELD].notnull() & (inputDf[BULK_COL_TACTIC] != inputDf[TMP_FIELD]) ]

Post generated on 2024-11-27 06:58:46 GMT

comments powered by Disqus