Created
September 23, 2020 16:01
-
-
Save marketingclouded/cef27a4c9acc94da02c13416819e2706 to your computer and use it in GitHub Desktop.
Tracking SFMC Subscriber Behavior: Creating the Data Extensions Performance_Subscriber using SSJS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script runat="server"> | |
Platform.Load("core", "1.1.1"); | |
var api = new Script.Util.WSProxy(); | |
try { | |
var FolderName = "Reporting"; | |
var FolderAttributes = Folder.Retrieve({ Property: "Name", SimpleOperator: "equals", Value: FolderName }); | |
var FolderID = FolderAttributes[0].ID; | |
var perf = api.retrieve("DataExtension", ["CustomerKey"], { | |
Property: "Name", | |
SimpleOperator: "equals", | |
Value: "Performance_Subscriber" | |
}); | |
var perfKey = perf.Results[0].CustomerKey; | |
var perfFields = [ | |
{ | |
"Name": "EmailAddress", | |
"FieldType": "EmailAddress" | |
}, | |
{ | |
"Name": "Sent", | |
"FieldType": "Number", | |
"DefaultValue": 0 | |
}, | |
{ | |
"Name": "UniqueOpens", | |
"FieldType": "Number", | |
"DefaultValue": 0 | |
}, | |
{ | |
"Name": "UniqueOpenRate", | |
"FieldType": "Decimal", | |
"DefaultValue": 0, | |
"MaxLength": 18, | |
"Scale": 2 | |
}, | |
{ | |
"Name": "UniqueClicks", | |
"FieldType": "Number", | |
"DefaultValue": 0 | |
}, | |
{ | |
"Name": "UniqueCTR", | |
"FieldType": "Decimal", | |
"MaxLength": 18, | |
"Scale": 2, | |
"DefaultValue": 0 | |
}, | |
{ | |
"Name": "AllOpens", | |
"FieldType": "Number", | |
"DefaultValue": 0 | |
}, | |
{ | |
"Name": "AllOpenRate", | |
"FieldType": "Decimal", | |
"MaxLength": 18, | |
"Scale": 2, | |
"DefaultValue": 0 | |
}, | |
{ | |
"Name": "AllClicks", | |
"FieldType": "Number", | |
"DefaultValue": 0 | |
}, | |
{ | |
"Name": "AllCTR", | |
"FieldType": "Decimal", | |
"MaxLength": 18, | |
"Scale": 2, | |
"DefaultValue": 0 | |
}, | |
{ | |
"Name": "Bounces", | |
"FieldType": "Number", | |
"DefaultValue": 0 | |
}, | |
{ | |
"Name": "Status", | |
"FieldType": "Text", | |
"MaxLength": 12 | |
}, | |
{ | |
"Name": "DateJoined", | |
"FieldType": "Date" | |
}, | |
{ | |
"Name": "DateUnsubscribed", | |
"FieldType": "Date" | |
}, | |
{ | |
"Name": "SubscriberID", | |
"FieldType": "Number", | |
"IsPrimaryKey": true, | |
"IsRequired" : true | |
} | |
]; | |
var perfConfig = { | |
"CustomerKey": perfKey, | |
"Name": "Performance_Subscriber", | |
"CategoryID": FolderID, | |
"Fields": perfFields | |
}; | |
var createPerf = api.createItem("DataExtension", perfConfig); | |
Write(Stringify(createPerf)); | |
} catch(error) { | |
Write(Stringify(error)); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment