Skip to content

Instantly share code, notes, and snippets.

@MyCueCards
MyCueCards / OpenModal_JQuery.js
Last active February 13, 2019 15:09
Using Bootstrap, this is JQuery that will open a modal if a specific line of text is found within the URL.
//Insert JQuery URL into header. Below is from Google.
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
//Place below code in body of page. It will open the modal by whatever ID is there when the page is ready.
$(document).ready(function(){
if(window.location.href.indexOf("sometexthere") > -1) {
$("#id").modal();
}
});
@MyCueCards
MyCueCards / ActiveTab_JQuery.js
Last active February 13, 2019 15:08
In Bootstrap, this looks for a string in the URL and actives the tabs for either English or Spanish without having to open a different window.
$(document).ready(function () {
if (window.location.href.indexOf("?lang=en") > -1) {
function doEnglish() {
$('#english').addClass('active');
$('#en').addClass('active');
$('#español').removeClass('active');
$('#es').removeClass('active');
}
setTimeout(doEnglish, 0);
} else {
@MyCueCards
MyCueCards / LookALike Report.sql
Last active February 13, 2019 15:07
In Salesforce Marketing Cloud, this query 1) find agents, who are designated with the number 1, 2) only pulls records with the purchase date of the previous month, 3) calculates age based on purchase date and birthday, 4) changes column names for a few, and 5) populates a column with the family designation based on product name.
SELECT
ade.AgentSettingsID,
ade.AgentNumber,
pde.Email,
pde.Given_Name,
pde.Surname,
DATEDIFF(Year, pde.Date_Of_Birth, pde.Purchase_Date) AS "Age",
pde.Mobile AS "Mobile_Phone",
pde.Home AS "Home_Phone",
pde.MailingStreet AS "Street_Address",
@MyCueCards
MyCueCards / FindToExclude.sql
Last active February 13, 2019 15:06
In Salesforce Marketing Cloud, this query finds records within the All Subscriber List. The records it finds are those agents designated as "2", as well as a portion of the company name.
SELECT pde.SubKey AS SubscriberKey, pde.Email AS EmailAddress
FROM AgentDataExtension ade
INNER JOIN PrimaryDataExtension pde ON pde.Agent_Number = ade.AgentNumber
WHERE ade.AgentSettingsID = 2 OR pde.Email LIKE '%company name%'
UNION
SELECT SubscriberKey, EmailAddress
FROM _ListSubscribers
WHERE ListID = 000 AND EmailAddress LIKE ‘%company name%’
@MyCueCards
MyCueCards / GTM_GetEmailFromSession.js
Created July 19, 2018 17:16
In Google Tag Manager, get a variable session storage. This is entered into GTM as "Customer JavaScript" variable. The result is also a variable as a "1st Party Cookie."
function ()
{
var result = '';
if(typeof(Storage) !== 'undefined')
{
if (typeof(window.sessionStorage._enterCookieName) !== 'undefined')
{
result = window.sessionStorage._enterCookieName + '';
@MyCueCards
MyCueCards / AllSubscriberExclude.sql
Last active February 13, 2019 15:06
In Salesforce Marketing Cloud, this query finds records within the All Subscriber List. The records it finds are those emails addresses, which match the email within SomeDataExtension. There is an extra parameter to exclude a string.
SELECT sde.*
FROM SomeDataExtension sde
INNER JOIN _ListSubscribers l ON sde.SubKey = l.SubscriberKey
WHERE l.ListID = '000'
AND sde.SubKey = l.SubscriberKey
AND sde.Email = l.EmailAddress
AND sde.Email NOT LIKE '%string here%'
@MyCueCards
MyCueCards / AMPScript_URL_Concat.html
Created October 3, 2018 13:58
In a Salesforce Marketing Cloud email, this builds a URL when using a Google Campaign URL. This includes a couple static parameters and then a field from the sendable data extension.
%%[Set @url = concat('https://www.someurl.com?utm_source=StaticParameter1&utm_medium=StaticParameter2&utm_campaign=StaticParameter3&utm_term=',FieldName,'&utm_content=StaticParameter4')]%%
<a href="%%=RedirectTo(v(@url))=%%" target="_blank" style="font-size: 18px; font-family: Open Sans, Helvetica, Arial, sans-serif; color: #ffffff; text-decoration: none; border-radius: 5px; background-color: #000000; padding: 15px 30px; border: 1px solid #000000; display: block;">Click Here &#187;</a>
@MyCueCards
MyCueCards / SSJS_FindDataExtensionLocation
Created February 13, 2019 15:04
In a Salesforce Marketing Cloud CloudPage, paste the below in an HTML block. Alter values either line 6 or line 8 to find a particular data extension. If you use 'var deName' in line 6, then you must use 'Property:"Name"' in line 7 (commenting out line 8-9). If you use 'var key' in line 8, then you must use 'Property: "CustomerKey"' in line 9 (c…
// Was found posted by Sasa Adzip in December 2018. Source = https://success.salesforce.com/ideaView?id=08730000000cIvUAAU
<script runat=server>
Platform.Load("core","1.1.5");
var deName="INSERT_DataExtensionName";
var FolderScript= DataExtension.Retrieve({Property:"Name",SimpleOperator:"equals",Value:deName});
//var key="INSERT_ExternalKeyOfDataExtension";
//var FolderScript= DataExtension.Retrieve({Property:"CustomerKey",SimpleOperator:"equals",Value:key});
var FolderID = FolderScript[0].CategoryID;
@MyCueCards
MyCueCards / URLEncode.html
Created February 13, 2019 16:59
In Salesforce Marketing Cloud, a client is using AMPscript to pull a URL from the sending data extension (DE) into an email. The client has a Web Analytics Connector (WAC) integration, which adds parameters to the end of a URL when the email recipient opens the email. The URL generated from the WAC attempts to use a value from the sending DE, wh…
<!-- AMPscript Block -->
%%[
var @UTMstring1
set @UTMstring1 = "?utm_source=SFMC&utm_medium=email&utm_campaign"
var @UTMstring2
set @UTMstring2 = "&utm_content="
var @UTMstring3
set @UTMstring3 = "&utm_subscriber="
var @url1
@MyCueCards
MyCueCards / AMPscript-Loops.html
Created April 6, 2019 01:09
Example of loops in Salesforce Marketing Cloud AMPscript
<!-- AMPscript block above <HTML> -->
%%[
VAR @string
SET @string = 'PositionA1[|]PositionA2[|]PositionA3[|]PositionA4a,PositionA4b|PositionA4c,PositionA4d[^]PositionB1[|]PositionB2[|]PositionB3[|]PositionB4a,PositionB4b|PositionB4c'
SET @Array = BuildRowsetFromString(@string,"[^]")
]%%