Skip to content

Instantly share code, notes, and snippets.

View marketing-cloud-app-authorization.html
<script runat="server">
Platform.Load("core", "1");
var client_id = "xxxxx", //add the client id from the installed package
client_secret = "xxxxxx", //add the client secret from the installed package
subdomain = "xxxxx", //add the 28 character subdomain (starts with mc....)
redirect_uri = "xxxxx"; //add the url of the CloudPage that hosts your app
var auth = true;
View masking-email-addresses-ampscript.html
%%[
/* pull the field to be masked from a data extension */
set @email = AttributeValue("email")
/* find the position of the first occurrence of an @ sign in the string */
set @at = indexOf(@email, "@")
/* extract the username portion of the email address */
set @username = Substring(@email,1, Subtract(@at,1))
View masking-pii-data-ampscript.html
%%[
/* pull the field to be masked from a data extension */
set @text = AttributeValue("email")
/* check the length of the string */
set @length = Length(@text)
/* count the number of characters to mask.
it also controls how many characters will not be masked.
currently set to 2, change to more if needed */
View Journey-consolidated-tracking.sql
SELECT
jou.JourneyName,
j.EmailName,
COUNT(s.JobID) AS Sent,
COUNT(o.JobID) AS Opened,
COUNT(c.JobID) AS Clicked,
COUNT(b.JobID) AS Bounced,
COUNT(u.JobID) AS Unsubscribed
FROM _Job j LEFT JOIN _Sent s ON j.JobID = s.JobID
LEFT JOIN _Open o ON s.JobID = o.JobID and s.ListID = o.ListID and s.BatchID = o.BatchID and s.SubscriberID = o.SubscriberID and o.IsUnique = 1
View WaitUntilEventActivityAPI-link-tracking.html
View WaitUntilEventActivityAPI
Host: https://YOUR_SUBDOMAIN.rest.marketingcloudapis.com
POST /interaction/v1/events
Content-Type: application/json
Authorization: Bearer YOUR_ACCESS_TOKEN
{
"ContactKey": {{emailAddress}},
"EventDefinitionKey": {{WaitUntilEventActivityAPIkey}},
"Data": {
"email": {{emailAddress}},
View FireEntryEvent
Host: https://YOUR_SUBDOMAIN.rest.marketingcloudapis.com
POST /interaction/v1/events
Content-Type: application/json
Authorization: Bearer YOUR_ACCESS_TOKEN
{
"ContactKey": {{emailAddress}},
"EventDefinitionKey": {{EventDefinitionKey}},
"Data": {
"email": {{emailAddress}},
View ampscript-loops.html
%%[
set @CustomerID = AttributeValue("CustomerID")
set @rows = LookupRows("Orders","CustomerID",@CustomerID)
set @rowCount = RowCount(@rows)
for @counter = 1 to @rowCount do
set @row = row(@rows,@counter)
set @orderItem = field(@row,"Item")
]%%
View total-number-urls.sql
select distinct
jobid,
ListID,
BatchID,
subscriberid,
count(distinct url) AS URLs
from _click
group by subscriberid, jobid, ListID, BatchID
View total-number-clicks.sql
select
jobid,
ListID,
BatchID,
subscriberid,
count(subscriberid) AS Clicks
from _click
group by subscriberid, jobid, ListID, BatchID