Skip to content
5 changes: 4 additions & 1 deletion packages/scripts/dist/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DonationAmount, DonationFrequency, EnForm, ProcessingFees, Country, } from "./events";
import { AmountLabel, Loader, ProgressBar, UpsellLightbox, ENGrid, OptionsDefaults, setRecurrFreq, PageBackground, MediaAttribution, ApplePay, A11y, CapitalizeFields, Ecard, ClickToExpand, Advocacy, DataAttributes, LiveVariables, iFrame, InputPlaceholders, InputHasValueAndFocus, ShowHideRadioCheckboxes, AutoCountrySelect, SkipToMainContentLink, SrcDefer, NeverBounce, AutoYear, Autocomplete, RememberMe, TranslateFields, ShowIfAmount, EngridLogger, OtherAmount, MinMaxAmount, Ticker, DataReplace, DataHide, AddNameToMessage, ExpandRegionName, AppVersion, UrlToForm, RequiredIfVisible, TidyContact, DataLayer, LiveCurrency, Autosubmit, EventTickets, SwapAmounts, DebugPanel, DebugHiddenFields, FreshAddress, BrandingHtml, CountryDisable, PremiumGift, DigitalWallets, MobileCTA, LiveFrequency, UniversalOptIn, StripeFinancialConnections, GiveBySelect, UrlParamsToBodyAttrs, ExitIntentLightbox, SupporterHub, FastFormFill, SetAttr, ShowIfPresent, ENValidators, CustomCurrency, VGS, PostalCodeValidator, CountryRedirect, WelcomeBack, EcardToTarget, UsOnlyForm, ThankYouPageConditionalContent, EmbeddedEcard, CheckboxLabel, UpsellCheckbox, PostDonationEmbed, FrequencyUpsell, CustomPremium, PreferredPaymentMethod, } from ".";
import { AmountLabel, Loader, ProgressBar, UpsellLightbox, ENGrid, OptionsDefaults, setRecurrFreq, PageBackground, MediaAttribution, ApplePay, A11y, CapitalizeFields, Ecard, ClickToExpand, Advocacy, DataAttributes, LiveVariables, iFrame, InputPlaceholders, InputHasValueAndFocus, ShowHideRadioCheckboxes, AutoCountrySelect, SkipToMainContentLink, SrcDefer, NeverBounce, AutoYear, Autocomplete, RememberMe, TranslateFields, ShowIfAmount, EngridLogger, OtherAmount, MinMaxAmount, Ticker, DataReplace, DataHide, AddNameToMessage, ExpandRegionName, AppVersion, UrlToForm, RequiredIfVisible, TidyContact, DataLayer, LiveCurrency, Autosubmit, EventTickets, SwapAmounts, DebugPanel, DebugHiddenFields, FreshAddress, BrandingHtml, CountryDisable, PremiumGift, DigitalWallets, MobileCTA, LiveFrequency, UniversalOptIn, StripeFinancialConnections, GiveBySelect, UrlParamsToBodyAttrs, ExitIntentLightbox, SupporterHub, FastFormFill, SetAttr, ShowIfPresent, ENValidators, CustomCurrency, VGS, PostalCodeValidator, CountryRedirect, WelcomeBack, EcardToTarget, UsOnlyForm, ThankYouPageConditionalContent, EmbeddedEcard, CheckboxLabel, UpsellCheckbox, PostDonationEmbed, FrequencyUpsell, CustomPremium, StickyNSG, StickyPrepopulation, PreferredPaymentMethod, } from ".";
export class App extends ENGrid {
constructor(options) {
super();
Expand Down Expand Up @@ -160,6 +160,8 @@ export class App extends ENGrid {
new Autosubmit();
// Adjust display of event tickets.
new EventTickets();
// StickyNSG - Must load before SwapAmounts
new StickyNSG();
// Swap Amounts
new SwapAmounts();
// On the end of the script, after all subscribers defined, let's load the current frequency
Expand Down Expand Up @@ -279,6 +281,7 @@ export class App extends ENGrid {
new CheckboxLabel();
new PostDonationEmbed();
new FrequencyUpsell();
new StickyPrepopulation();
//Debug panel
let showDebugPanel = this.options.Debug;
try {
Expand Down
2 changes: 2 additions & 0 deletions packages/scripts/dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ export * from "./optin-ladder";
export * from "./post-donation-embed";
export * from "./frequency-upsell-modal";
export * from "./frequency-upsell";
export * from "./sticky-nsg";
export * from "./sticky-prepopulation";
export * from "./preferred-payment-method";
export * from "./events";
export * from "./version";
2 changes: 2 additions & 0 deletions packages/scripts/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ export * from "./optin-ladder";
export * from "./post-donation-embed";
export * from "./frequency-upsell-modal";
export * from "./frequency-upsell";
export * from "./sticky-nsg";
export * from "./sticky-prepopulation";
export * from "./preferred-payment-method";
// Events
export * from "./events";
Expand Down
4 changes: 4 additions & 0 deletions packages/scripts/dist/interfaces/options.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ export interface Options {
fieldClearSelectorTargetLocation?: string;
checked?: boolean;
};
StickyNSG?: boolean;
StickyPrepopulation?: false | {
fields: string[];
};
TidyContact?: false | {
cid?: string;
page_types?: ("DONATION" | "ECARD" | "SURVEY" | "EMAILTOTARGET" | "ADVOCACY" | "SUBSCRIBEFORM" | "EVENT" | "SUPPORTERHUB" | "UNSUBSCRIBE" | "TWEETPAGE" | "UNKNOWN")[];
Expand Down
2 changes: 2 additions & 0 deletions packages/scripts/dist/interfaces/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export const OptionsDefaults = {
CountryRedirect: false,
WelcomeBack: false,
OptInLadder: false,
StickyNSG: false,
StickyPrepopulation: false,
PreferredPaymentMethod: false,
PageLayouts: [
"leftleft1col",
Expand Down
10 changes: 10 additions & 0 deletions packages/scripts/dist/sticky-nsg.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export declare class StickyNSG {
private logger;
private cookieName;
constructor();
private shouldRun;
private nsgActiveOnPage;
private deleteCookieIfGiftProcessComplete;
private createStickyNSGCookie;
private applyStickyNSGCookie;
}
109 changes: 109 additions & 0 deletions packages/scripts/dist/sticky-nsg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import { EngridLogger } from "./logger";
import { ENGrid } from "./engrid";
import * as cookie from "./cookie";
export class StickyNSG {
constructor() {
this.logger = new EngridLogger("StickyNSG", "teal", "white", "📌");
this.cookieName = "engrid-sticky-nsg";
if (!this.shouldRun())
return;
this.logger.log("Sticky NSG is enabled");
this.deleteCookieIfGiftProcessComplete();
this.createStickyNSGCookie();
this.applyStickyNSGCookie();
}
shouldRun() {
return ENGrid.getOption("StickyNSG") === true;
}
/*
* Determine if NSG provided by EN is active on the page
*/
nsgActiveOnPage() {
return (window.EngagingNetworks &&
window.EngagingNetworks.suggestedGift &&
typeof window.EngagingNetworks.suggestedGift === "object" &&
Object.keys(window.EngagingNetworks.suggestedGift).length > 0);
}
/*
* Delete the cookie if the gift process is complete
*/
deleteCookieIfGiftProcessComplete() {
if (ENGrid.getGiftProcess()) {
this.logger.log("Gift process complete, removing sticky NSG cookie if it exists");
cookie.remove(this.cookieName);
}
}
/*
* Create the sticky NSG cookie if NSG is active on the page
*/
createStickyNSGCookie() {
var _a, _b, _c, _d, _e, _f;
if (!this.nsgActiveOnPage()) {
this.logger.log("No NSG active on page, not creating sticky NSG cookie");
return;
}
const url = new URL(window.location.href);
if (url.searchParams.get("skipstickynsg") === "true") {
this.logger.log("'skipstickynsg' param present, not creating sticky NSG cookie");
return;
}
// We do some reformating to match the EngridAmounts format
// We also add "Other" to the amounts list
const nsg = window.EngagingNetworks.suggestedGift;
this.logger.log("Creating sticky NSG cookie", nsg);
const oneTimeNsg = (_a = nsg.single) === null || _a === void 0 ? void 0 : _a.reduce((acc, curr) => {
acc[curr.value] = curr.value;
return acc;
}, {});
const oneTimeDefault = (_c = (_b = nsg.single) === null || _b === void 0 ? void 0 : _b.find((gift) => gift.nextSuggestedGift)) === null || _c === void 0 ? void 0 : _c.value;
const recurringNsg = (_d = nsg.recurring) === null || _d === void 0 ? void 0 : _d.reduce((acc, curr) => {
acc[curr.value] = curr.value;
return acc;
}, {});
const recurringDefault = (_f = (_e = nsg.recurring) === null || _e === void 0 ? void 0 : _e.find((gift) => gift.nextSuggestedGift)) === null || _f === void 0 ? void 0 : _f.value;
const nsgCookieData = {};
if (oneTimeNsg && oneTimeDefault) {
nsgCookieData.onetime = {
amounts: oneTimeNsg,
default: oneTimeDefault,
stickyDefault: false,
};
}
if (recurringNsg && recurringDefault) {
nsgCookieData.monthly = {
amounts: recurringNsg,
default: recurringDefault,
stickyDefault: false,
};
}
if (Object.keys(nsgCookieData).length === 0) {
this.logger.log("No valid NSG data found to create sticky NSG cookie");
return;
}
const cookieValue = JSON.stringify(nsgCookieData);
cookie.set(this.cookieName, cookieValue, { path: "/", expires: 30 });
this.logger.log("Sticky NSG cookie created", cookieValue);
}
/*
* Apply the sticky NSG cookie values to window.EngridAmounts if NSG is not active on the page
*/
applyStickyNSGCookie() {
if (this.nsgActiveOnPage()) {
this.logger.log("NSG active on page, not applying sticky NSG cookie, leaving the EN NSG values.");
return;
}
const cookieValue = cookie.get(this.cookieName);
if (!cookieValue) {
this.logger.log("No sticky NSG cookie found, nothing to apply");
return;
}
try {
const nsg = JSON.parse(cookieValue);
this.logger.log("Applying sticky NSG cookie values", nsg);
window.EngridAmounts = nsg;
}
catch (e) {
this.logger.error("Error parsing sticky NSG cookie, not applying", e);
}
}
}
17 changes: 17 additions & 0 deletions packages/scripts/dist/sticky-prepopulation.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export declare class StickyPrepopulation {
private logger;
private options;
private cookieName;
constructor();
private shouldRun;
private deleteCookie;
private createCookie;
private applyPrepopulation;
private getSupporterDetailsFromFields;
private encryptSupporterDetails;
private decryptSupporterDetails;
private createEncryptionKey;
private arrayBufferToBase64;
private base64ToArrayBuffer;
private getSeed;
}
Loading
Loading