Script 893: campaign 30 day cost conv assignment

Purpose

The script updates the “Campaign 30 Day Cost per Conversion” dimension to support keyword-level anomaly detection for cost per conversion.

To Elaborate

The Python script is designed to update a specific dimension, “Campaign 30 Day Cost per Conversion,” on a daily basis. This update is crucial for facilitating a keyword-level anomaly detection process focused on cost per conversion metrics. The script extracts relevant data from a primary data source, processes it, and then updates the output data frame with the necessary values. This ensures that the cost per conversion data is current and accurate, which is essential for identifying any anomalies or irregularities in keyword performance. The script is part of a larger system that monitors and optimizes campaign performance by analyzing conversion costs over a 30-day period.

Walking Through the Code

  1. Data Source Initialization
    • The script begins by defining the primary data source and the columns it will use. It extracts data from a dictionary object, dataSourceDict, using a key to access the relevant data frame, inputDf.
  2. Column Selection and Data Preparation
    • A list of columns, cols, is defined to specify which data fields are necessary for the operation. The script creates a copy of these columns from the input data frame to ensure that the original data remains unaltered.
  3. Output Data Frame Update
    • The script initializes the output data frame, outputDf, with specific columns for account, campaign, and the campaign 30-day cost per conversion. It then populates these columns with data from the input data frame, ensuring that the output reflects the latest cost per conversion values.
  4. User Changeable Parameters
    • The placeholder "<<YOUR VALUE>>" in the output data frame initialization can be replaced by the user with a specific value or calculation as needed. This allows for customization based on specific business requirements or data processing needs.

Vitals

  • Script ID : 893
  • Client ID / Customer ID: 1306913420 / 60268008
  • Action Type: Bulk Upload
  • Item Changed: Campaign
  • Output Columns: Account, Campaign, Campaign 30 Day Cost per Conversion
  • Linked Datasource: M1 Report
  • Reference Datasource: None
  • Owner: Chris Jetton (cjetton@marinsoftware.com)
  • Created by Chris Jetton on 2024-04-02 16:36
  • Last Updated by Chris Jetton on 2024-04-02 16:57
> 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
##
## name: campaign 30 day cost/conv assignment
## description:
##  daily job that will update the value of the "Campaign 30 day cost per conversion" dimension to facilitate the keyword-level anomaly detection script for cost/conv
## 
## author: 
## created: 2024-04-02
## 

today = datetime.datetime.now(CLIENT_TIMEZONE).date()

# primary data source and columns
inputDf = dataSourceDict["1"]
RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_CUSTOM_PARAMETERS = 'Custom Parameters'
RPT_COL_CAMPAIGN_30_DAY_COST_PER_CONVERSION = 'Campaign 30 Day Cost per Conversion'
RPT_COL_CAMPAIGN_STATUS = 'Campaign Status'
RPT_COL_ACTIVE_GROUPS = 'Active Groups'
RPT_COL_ACCOUNT = 'Account'
RPT_COL_HISTORICAL_CONVERSIONS = 'Historical Conversions'
RPT_COL_IMPR = 'Impr.'
RPT_COL_CLICKS = 'Clicks'
RPT_COL_UTMCAMPAIGN = 'utmcampaign'
RPT_COL_PUB_COST = 'Pub. Cost $'
RPT_COL_CONV = 'Conv.'
RPT_COL_COST_PER_CONV = 'Cost/Conv. $'
RPT_COL_CTR = 'CTR %'
RPT_COL_DAILY_BUDGET = 'Daily Budget'
RPT_COL_SUBREGION = 'Subregion'
RPT_COL_BRAND = 'Brand'
RPT_COL_INQUIRY_OFFLINE_CONV_DATE_OF_CONV = 'Inquiry (Offline) Conv. (Date Of Conv.)'
RPT_COL_INQUIRY_OFFLINE_REVENUE_DATE_OF_CONV = 'Inquiry (Offline) Revenue (Date Of Conv.)'
RPT_COL_MCL_OFFLINE_CONV_DATE_OF_CONV = 'MCL (Offline) Conv. (Date Of Conv.)'
RPT_COL_MCL_OFFLINE_REVENUE_DATE_OF_CONV = 'MCL (Offline) Revenue (Date Of Conv.)'
RPT_COL_MQL_OFFLINE_CONV_DATE_OF_CONV = 'MQL (Offline) Conv. (Date Of Conv.)'
RPT_COL_MQL_OFFLINE_REVENUE_DATE_OF_CONV = 'MQL (Offline) Revenue (Date Of Conv.)'
RPT_COL_OPPORTUNITY_OFFLINE_CONV_DATE_OF_CONV = 'Opportunity (Offline) Conv. (Date Of Conv.)'
RPT_COL_OPPORTUNITY_OFFLINE_REVENUE_DATE_OF_CONV = 'Opportunity (Offline) Revenue (Date Of Conv.)'
RPT_COL_PIPELINE_OPPORTUNITY_OFFLINE_CONV_DATE_OF_CONV = 'Pipeline Opportunity (Offline) Conv. (Date Of Conv.)'
RPT_COL_PIPELINE_OPPORTUNITY_OFFLINE_REVENUE_DATE_OF_CONV = 'Pipeline Opportunity (Offline) Revenue (Date Of Conv.)'
RPT_COL_SAL_OFFLINE_CONV_DATE_OF_CONV = 'SAL (Offline) Conv. (Date Of Conv.)'
RPT_COL_SAL_OFFLINE_REVENUE_DATE_OF_CONV = 'SAL (Offline) Revenue (Date Of Conv.)'
RPT_COL_SQL_OFFLINE_CONV_DATE_OF_CONV = 'SQL (Offline) Conv. (Date Of Conv.)'
RPT_COL_SQL_OFFLINE_REVENUE_DATE_OF_CONV = 'SQL (Offline) Revenue (Date Of Conv.)'
RPT_COL_WON_OPPORTUNITY_OFFLINE_CONV_DATE_OF_CONV = 'Won Opportunity (Offline) Conv. (Date Of Conv.)'
RPT_COL_WON_OPPORTUNITY_OFFLINE_REVENUE_DATE_OF_CONV = 'Won Opportunity (Offline) Revenue (Date Of Conv.)'

# output columns and initial values
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_CAMPAIGN_30_DAY_COST_PER_CONVERSION = 'Campaign 30 Day Cost per Conversion'
outputDf[BULK_COL_CAMPAIGN_30_DAY_COST_PER_CONVERSION] = "<<YOUR VALUE>>"

# user code start here
cols = [RPT_COL_ACCOUNT, RPT_COL_CAMPAIGN, RPT_COL_COST_PER_CONV]
df = inputDf[cols].copy()
#df = inputDf[cols].copy().head(1)  # Select only the first row
outputDf[BULK_COL_ACCOUNT] = inputDf[RPT_COL_ACCOUNT]
outputDf[BULK_COL_CAMPAIGN] = inputDf[RPT_COL_CAMPAIGN]
outputDf[BULK_COL_CAMPAIGN_30_DAY_COST_PER_CONVERSION] = inputDf[RPT_COL_COST_PER_CONV]


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

comments powered by Disqus