Skip to content

Instantly share code, notes, and snippets.

%%[
IF RequestParameter("submitted") == true THEN
/* check if lead already exists */
SET @subscriberRows = RetrieveSalesforceObjects(
"Lead",
"Id,Email",
"Email", "=", RequestParameter("email")
)
<script runat="server">
Platform.Load("Core","1.1.1");
var authEndpoint = 'https://mcxxxxxxxxxxxxxxxxxxxxxxxxx.auth.marketingcloudapis.com';
var payload = {
clientId: "insert Client Id",
clientSecret: "insert Client Secret"
};
var url = authEndpoint + '/v1/requestToken';
var contentType = 'application/json';
<script runat="server">
Platform.Load("Core","1.1.1");
var authEndpoint = 'https://mcxxxxxxxxxxxxxxxxxxxxxxxxx.auth.marketingcloudapis.com';
var payload = {
client_id: "insert Client Id",
client_secret: "insert Client Secret",
grant_type: "client_credentials"
};
var url = authEndpoint + '/v2/token';
<table style="padding: 20px;"><tr><td>
<h2>Please fill in the form:</h2>
<form action="%%=RequestParameter('PAGEURL')=%%" method="post">
<label>First name: </label><input type="text" name="firstname" required=""><br>
<label>Last name: </label><input type="text" name="lastname" required=""><br>
<label>Company: </label><input type="text" name="company" required=""><br>
<label>Email: </label><input type="text" name="email" required=""><br>
<input name="submitted" type="hidden" value="true"><br>
<input type="submit" value="Submit">
</form>
%%[
IF RequestParameter("submitted") == true THEN
/* create a new lead */
SET @leadId = CreateSalesforceObject(
"Lead", 4,
"FirstName", RequestParameter("firstname"),
"LastName", RequestParameter("lastname"),
"Company", RequestParameter("company"),
"Email", RequestParameter("email")
%%[
IF RequestParameter("submitted") == true THEN
/* check if lead already exists */
SET @subscriberRows = RetrieveSalesforceObjects(
"Lead",
"Id,Email",
"Email", "=", RequestParameter("email")
)
%%[
IF RequestParameter("submitted") == true THEN
/* check if lead already exists */
SET @subscriberRows = RetrieveSalesforceObjects(
"Lead",
"Id,Email",
"Email", "=", RequestParameter("email")
)
%%[
VAR @ts, @tsDef, @ts_extkey, @ts_email, @ts_sub, @ts_statusCode, @ts_statusMsg, @errorCode
SET @ts = CreateObject("TriggeredSend")
SET @tsDef = CreateObject("TriggeredSendDefinition")
SET @ts_extkey = "ExternalKey"
SET @ts_email = "email@example.com"
SetObjectProperty(@tsDef, "CustomerKey", @ts_extkey)
SetObjectProperty(@ts, "TriggeredSendDefinition", @tsDef)
SET @ts_sub = CreateObject("Subscriber")
SELECT DISTINCT
s.SubscriberKey,
j.EmailName
FROM _Sent s
LEFT JOIN _Job j
ON s.JobID = j.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
LEFT JOIN _Click c
ON s.JobID = c.JobID AND s.ListID = c.ListID AND s.BatchID = c.BatchID AND s.SubscriberID = c.SubscriberID AND c.IsUnique = 1
SELECT
s.SubscriberKey,
j.EmailName,
s.EventDate as SentDate,
o.EventDate as OpenDate,
c.EventDate as ClickDate,
b.EventDate as BounceDate,
b.BounceCategory,
u.EventDate as UnsubscribeDate
FROM _Sent s LEFT JOIN _Job as j ON s.JobID = j.JobID