Script 893: campaign 30 day cost conv assignment

Purpose

Python script that updates the value of the “Campaign 30 day cost per conversion” dimension for keyword-level anomaly detection.

To Elaborate

The Python script is a daily job that updates the value of the “Campaign 30 day cost per conversion” dimension. This update is done to facilitate the keyword-level anomaly detection script for cost per conversion. The script is designed to be run on a daily basis to ensure that the dimension is always up to date.

Walking Through the Code

  1. The script starts by importing the necessary libraries and defining the necessary constants.
  2. The current date is obtained using the datetime library and stored in the today variable.
  3. The primary data source and column constants are defined.
  4. The output columns and initial values are defined.
  5. The user code starts with the creation of a new DataFrame df that contains only the columns RPT_COL_ACCOUNT, RPT_COL_CAMPAIGN, and RPT_COL_COST_PER_CONV from the input DataFrame inputDf.
  6. The values from the input DataFrame are copied to the output DataFrame outputDf for the corresponding columns BULK_COL_ACCOUNT, BULK_COL_CAMPAIGN, and BULK_COL_CAMPAIGN_30_DAY_COST_PER_CONVERSION.
  7. The script ends.

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-05-15 07:44:05 GMT

comments powered by Disqus