Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<script runat="server">
Platform.Load("Core","1");
try{
var jsonpost = Platform.Request.GetPostData(0);
var json = Platform.Function.ParseJSON(jsonpost);
var messageKey = json[0].eventCategoryType;
if (messageKey == "TransactionalSendEvents.EmailSent") {
var MessageType = json[0].eventCategoryType;
var jobId = json[0].composite.jobId;
var batchId = json[0].composite.batchId;
var listId = json[0].composite.listId;
var subscriberId = json[0].composite.subscriberId;
var emailId = json[0].composite.emailId;
var definitionKey = json[0].definitionKey;
var mid = json[0].mid;
var eid = json[0].eid;
var Email = json[0].info.to;
var subscriberKey = json[0].info.subscriberKey;
var definitionId = json[0].definitionId;
var compositeId = json[0].compositeId;
var timestampUTC = json[0].timestampUTC;
timestampUTC = new Date(timestampUTC);
var insertResponse = Platform.Function.InsertData("Transactional_Event_Notification_Service",["MessageType","jobId","batchId","listId","subscriberId","emailId","definitionKey","mid","eid","Email","subscriberKey","definitionId","compositeId","timestampUTC"],[MessageType,jobId,batchId,listId,subscriberId,emailId,definitionKey,mid,eid,Email,subscriberKey,definitionId,compositeId,timestampUTC]);
}
else if (messageKey == "TransactionalSendEvents.EmailNotSent"){
var MessageType = json[0].eventCategoryType;
var compositeId = json[0].compositeId;
var definitionKey = json[0].definitionKey;
var definitionId = json[0].definitionId;
var mid = json[0].mid;
var eid = json[0].eid;
var Email = json[0].info.to;
var subscriberKey = json[0].info.subscriberKey;
var EmailNotSentReason = json[0].info.reason;
var EmailNotSentStatusCode = json[0].info.statusCode;
var EmailNotSentStatusMessage = json[0].info.statusMessage;
var timestampUTC = json[0].timestampUTC;
timestampUTC = new Date (timestampUTC);
var insertResponse = Platform.Function.InsertData("Transactional_Event_Notification_Service",["MessageType","compositeId","definitionKey","definitionId","mid","eid","Email","mid","eid","Email","subscriberKey","EmailNotSentReason","EmailNotSentStatusCode","EmailNotSentStatusMessage","timestampUTC"],[MessageType,compositeId,definitionKey,definitionId,mid,eid,Email,mid,eid,Email,subscriberKey,EmailNotSentReason,EmailNotSentStatusCode,EmailNotSentStatusMessage,timestampUTC]);
}
else if (messageKey == "TransactionalSendEvents.EmailBounced"){
var MessageType = json[0].eventCategoryType;
var compositeId = json[0].compositeId;
var definitionKey = json[0].definitionKey;
var definitionId = json[0].definitionId;
var mid = json[0].mid;
var eid = json[0].eid;
var Email = json[0].info.to;
var subscriberKey = json[0].info.subscriberKey;
var bounceCode = json[0].info.bounceCode;
var bounceMessage = json[0].info.bounceMessage;
var smtpReason = json[0].info.smtpReason;
var timestampUTC = json[0].timestampUTC;
timestampUTC = new Date (timestampUTC);
var insertResponse = Platform.Function.InsertData("Transactional_Event_Notification_Service",["MessageType","compositeId","definitionKey","definitionId","mid","eid","Email","mid","eid","Email","subscriberKey","bounceCode","bounceMessage","smtpReason","timestampUTC"],[MessageType,compositeId,definitionKey,definitionId,mid,eid,Email,mid,eid,Email,subscriberKey,bounceCode,bounceMessage,smtpReason,timestampUTC]);
}
else if (messageKey == "EngagementEvents.EmailOpen"){
var MessageType = json[0].eventCategoryType;
var jobId = json[0].composite.jobId;
var batchId = json[0].composite.batchId;
var listId = json[0].composite.listId;
var subscriberId = json[0].composite.subscriberId;
var definitionKey = json[0].definitionKey;
var mid = json[0].mid;
var eid = json[0].eid;
var definitionId = json[0].definitionId;
var compositeId = json[0].compositeId;
var ipAddress = json[0].info.ipAddress;
var userAgent = json[0].info.userAgent;
var country = json[0].info.location.country;
var region = json[0].info.location.region;
var city = json[0].info.location.city;
var postalCode = json[0].info.location.postalCode;
var latitude = json[0].info.location.latitude;
var longitude = json[0].info.location.longitude;
var timestampUTC = json[0].timestampUTC;
timestampUTC = new Date (timestampUTC);
var insertResponse = Platform.Function.InsertData("Transactional_Event_Notification_Service",["MessageType","jobId","batchId","listId","subscriberId","definitionKey","mid","eid","definitionId","compositeId","ipAddress","userAgent","country","region","city","postalCode","latitude","longitude","timestampUTC"],[MessageType,jobId,batchId,listId,subscriberId,definitionKey,mid,eid,definitionId,compositeId,ipAddress,userAgent,country,region,city,postalCode,latitude,longitude,timestampUTC]);
}
else if (messageKey == "EngagementEvents.EmailClick"){
var MessageType = json[0].eventCategoryType;
var jobId = json[0].composite.jobId;
var batchId = json[0].composite.batchId;
var listId = json[0].composite.listId;
var subscriberId = json[0].composite.subscriberId;
var definitionKey = json[0].definitionKey;
var mid = json[0].mid;
var eid = json[0].eid;
var definitionId = json[0].definitionId;
var compositeId = json[0].compositeId;
var jobUrlId = json[0].info.jobUrlId;
var contentLink = json[0].info.contentLink;
var timestampUTC = json[0].timestampUTC;
timestampUTC = new Date (timestampUTC);
var insertResponse = Platform.Function.InsertData("Transactional_Event_Notification_Service",["MessageType","jobId","batchId","listId","subscriberId","definitionKey","mid","eid","definitionId","compositeId","jobUrlId","contentLink","timestampUTC"],[MessageType,jobId,batchId,listId,subscriberId,definitionKey,mid,eid,definitionId,compositeId,jobUrlId,contentLink,timestampUTC]);
}
Write('{"Status":"Success"}');
} catch (e) {
Write("<br>" + Stringify(e))
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.