Skip to content

Instantly share code, notes, and snippets.

View marketingclouded's full-sized avatar

Ed Gray marketingclouded

View GitHub Profile
@marketingclouded
marketingclouded / Overwrites Email_Perf_Sched_Last_28Days
Created September 23, 2020 20:33
Tracking Email Performance in SFMC: Overwrites Email_Perf_Sched_Last_28Days
SELECT *
FROM Email_Performance_Sched
WHERE SentTime > DATEADD(d,DATEDIFF(day,30,GetDate()),0) AND SentTime < DATEADD(d,DATEDIFF(day,2,GetDate()),0)
@marketingclouded
marketingclouded / Updates Rates in Email_Performance_Sched
Created September 23, 2020 20:32
Tracking Email Performance in SFMC: Updates Rates in Email_Performance_Sched
SELECT
JobID,
CAST(Unsubscribes as DECIMAL(18,2)) / CAST(Sent AS DECIMAL(18,2)) * 100 AS 'UnsubRate',
CAST(Opens as DECIMAL(18,2)) / CAST(Sent AS DECIMAL(18,2)) * 100 AS 'OpenRate',
CAST(Clicks as DECIMAL(18,2)) / CAST(Sent AS DECIMAL(18,2)) * 100 AS 'CTR',
CAST(Bounces as DECIMAL(18,2)) / CAST(Sent AS DECIMAL(18,2)) * 100 AS 'BounceRate'
FROM Email_Performance_Sched
@marketingclouded
marketingclouded / Updates Email_Performance_Sched w Opens, Clicks, Bounces, Unsubscribes
Created September 23, 2020 20:31
Tracking Email Performance in SFMC: Updates Email_Performance_Sched w Opens, Clicks, Bounces, Unsubscribes
SELECT
e.JobID,
g.Clicks,
r.Opens,
a.Bounces,
y.Unsubscribes
FROM Email_Performance_Sched e
JOIN (
SELECT JobID, COUNT(JobID) AS Clicks FROM _Click WHERE IsUnique = 1 GROUP BY JobID
) g
@marketingclouded
marketingclouded / Overwrites Email_Performance_Sched w _Sent and _Job Info
Created September 23, 2020 20:29
Tracking Email Performance in SFMC: Overwrites Email_Performance_Sched w _Sent and _Job Info
SELECT TOP 9223372036854775807
e.EmailName,
e.SchedTime AS 'SentTime',
e.JobID,
COUNT(d.JobID) AS 'Sent'
FROM _Job e
JOIN _Sent d
ON d.JobId = e.JobId
WHERE e.TriggererSendDefinitionObjectID IS NULL
GROUP BY e.EmailName, e.SchedTime, e.JobId
@marketingclouded
marketingclouded / Create Email_Performance_Sched Data Extensions
Created September 23, 2020 20:28
Tracking Email Performance in SFMC: Create Email_Performance_Sched Data Extensions
<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;
@marketingclouded
marketingclouded / Creates 3 Account Health Data Extensions
Created September 23, 2020 20:00
Tracking SFMC Account Health: Creates 3 Account Health Data Extensions
<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;
@marketingclouded
marketingclouded / Backfills Account_Health_Daily
Created September 23, 2020 19:58
Tracking SFMC Account Health: Backfills Account_Health_Daily
SELECT Top 1
FORMAT(DATEADD(d,-1,e.DateStamp),'MMM dd yyyy') AS 'Date',
DATEADD(d,-1,e.DateStamp) AS 'DateStamp',
FORMAT(DATEADD(d,-1,e.DateStamp),'MMMM, yyyy') AS 'Month',
(SELECT COUNT(SubscriberID) FROM _Subscribers WHERE DateJoined >= DATEADD(d,DATEDIFF(day, 1, e.DateStamp),0) AND DateJoined < DATEADD(d,DATEDIFF(day, 0, e.DateStamp),0)) AS 'NewSubscribers',
(SELECT COUNT(SubscriberID) FROM _Subscribers WHERE DateUnsubscribed >= DATEADD(d,DATEDIFF(day, 1, e.DateStamp),0) AND DateUnsubscribed < DATEADD(d,DATEDIFF(day, 0, e.DateStamp),0)) AS 'Unsubscribes',
(SELECT COUNT(SubscriberID) FROM _Subscribers WHERE Status = 'active' AND DateJoined < DATEADD(d,DATEDIFF(day, 0, e.DateStamp),0)) AS ActiveSubscribers,
(SELECT COUNT(SubscriberID) FROM _Sent WHERE EventDate >= DATEADD(d,DATEDIFF(day, 1, e.DateStamp),0) AND EventDate < DATEADD(d,DATEDIFF(day, 0, e.DateStamp),0)) AS 'Sent',
(SELECT COUNT(SubscriberID) FROM _Open WHERE EventDate >= DATEADD(d,DATEDIFF(day, 1, e.DateStamp),0) AND EventDate < D
@marketingclouded
marketingclouded / Calculates CTR, Open Rate & List Growth in Account_Health_Monthly
Created September 23, 2020 19:57
Tracking SFMC Account Health: Calculates CTR, Open Rate & List Growth in Account_Health_Monthly
SELECT
e.Month,
CAST(SUM(d.Opens) as DECIMAL(18,2)) / CAST(SUM(d.Sent) AS DECIMAL(18,2)) * 100 AS 'UniqueOpenRate',
CAST(sum(d.Clicks) AS DECIMAL(18,2)) / CAST(SUM(d.Sent) AS DECIMAL(18,2)) * 100 AS 'UniqueCTR',
CAST(e.NetGrowth AS DECIMAL(18,2)) / CAST(e.ActiveSubscribers AS Decimal(18,2)) * 100 AS 'PercentGrowth'
FROM Account_Health_Monthly e
JOIN Account_Health_Daily d
ON e.Month = d.Month
WHERE d.SentCount > 0
GROUP BY e.Month, e.NetGrowth, e.ActiveSubscribers
@marketingclouded
marketingclouded / Updates Account_Health_Monthly w ActiveSubscribers
Created September 23, 2020 19:55
Tracking SFMC Account Health: Updates Account_Health_Monthly w ActiveSubscribers
SELECT e.ActiveSubscribers, d.Month
FROM Account_Health_Daily e
INNER JOIN Account_Health_Monthly d
ON d.MonthStamp = e.DateStamp
@marketingclouded
marketingclouded / Overwrites Account_Health_Monthly w Account_Health_Daily
Created September 23, 2020 19:54
Tracking SFMC Account Health: Overwrites Account_Health_Monthly w Account_Health_Daily
SELECT
Month,
SUM(SentCount) AS 'Sent',
SUM(NewSubscribers) AS 'NewSubscribers',
SUM(Unsubscribes) AS 'Unsubscribes',
SUM(BounceCount) AS 'Bounces',
SUM(NewSubscribers) - SUM(Unsubscribes) AS 'NetGrowth',
MIN(DateStamp) AS 'MonthStamp'
FROM Account_Health_Daily
GROUP BY Month