Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/scripts/dist/data-layer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export declare class DataLayer {
private static instance;
private encoder;
private endOfGiftProcessStorageKey;
private giftFields;
private excludedFields;
private hashedFields;
private retainedEmailField;
Expand Down
31 changes: 29 additions & 2 deletions packages/scripts/dist/data-layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ export class DataLayer {
this._form = EnForm.getInstance();
this.encoder = new TextEncoder();
this.endOfGiftProcessStorageKey = "ENGRID_END_OF_GIFT_PROCESS_EVENTS";
// pageJson entries related to the gift process
this.giftFields = [
"amount",
"currency",
"donationLogId",
"feeCover",
"giftProcess",
"paymentType",
"receiptNumber",
"recurring",
"transactionId",
"transactionType",
];
this.excludedFields = [
// Credit Card
"transaction.ccnumber",
Expand Down Expand Up @@ -102,13 +115,27 @@ export class DataLayer {
onLoad() {
// Collect all data layer variables to push at once
const dataLayerData = {};
const suppressEcardData = ENGrid.getPageType() === "ECARD" &&
ENGrid.getOption("SuppressPurchaseEcard");
if (ENGrid.getGiftProcess()) {
this.logger.log("EN_SUCCESSFUL_DONATION");
this.addEndOfGiftProcessEventsToDataLayer();
// EN will chain together gift process data on the page json when redirecting from a completed donation to an ecard.
// Since the ecard page can be embedded on the thank you page of a donation, this can cause confusion in the data layer with events
// firing for both the donation and the ecard on the same page.
if (suppressEcardData) {
this.logger.log("⛔ Gift process was detected BUT suppressing EN_SUCCESSFUL_DONATION event due to SuppressPurchaseEcard option enabled");
window.sessionStorage.removeItem(this.endOfGiftProcessStorageKey);
}
else {
this.logger.log("EN_SUCCESSFUL_DONATION");
this.addEndOfGiftProcessEventsToDataLayer();
}
}
if (window.pageJson) {
const pageJson = window.pageJson;
for (const property in pageJson) {
if (suppressEcardData && this.giftFields.includes(property)) {
continue;
}
const key = `EN_PAGEJSON_${property.toUpperCase()}`;
const value = pageJson[property];
dataLayerData[key] = this.transformJSON(value);
Expand Down
1 change: 1 addition & 0 deletions packages/scripts/dist/interfaces/options.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface Options {
UseAmountValidatorFromEN?: boolean;
SkipToMainContentLink?: boolean;
SrcDefer?: boolean;
SuppressPurchaseEcard?: boolean;
NeverBounceAPI?: string | null;
NeverBounceDateField?: string | null;
NeverBounceDateFormat?: string;
Expand Down
1 change: 1 addition & 0 deletions packages/scripts/dist/interfaces/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const OptionsDefaults = {
UseAmountValidatorFromEN: false,
SkipToMainContentLink: true,
SrcDefer: true,
SuppressPurchaseEcard: false,
NeverBounceAPI: null,
NeverBounceDateField: null,
NeverBounceStatusField: null,
Expand Down
34 changes: 32 additions & 2 deletions packages/scripts/src/data-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@ export class DataLayer {
private encoder = new TextEncoder();
private endOfGiftProcessStorageKey = "ENGRID_END_OF_GIFT_PROCESS_EVENTS";

// pageJson entries related to the gift process
private giftFields = [
"amount",
"currency",
"donationLogId",
"feeCover",
"giftProcess",
"paymentType",
"receiptNumber",
"recurring",
"transactionId",
"transactionType",
];

private excludedFields = [
// Credit Card
"transaction.ccnumber",
Expand Down Expand Up @@ -111,15 +125,31 @@ export class DataLayer {
private onLoad() {
// Collect all data layer variables to push at once
const dataLayerData: { [key: string]: any } = {};
const suppressEcardData =
ENGrid.getPageType() === "ECARD" &&
ENGrid.getOption("SuppressPurchaseEcard");

if (ENGrid.getGiftProcess()) {
this.logger.log("EN_SUCCESSFUL_DONATION");
this.addEndOfGiftProcessEventsToDataLayer();
// EN will chain together gift process data on the page json when redirecting from a completed donation to an ecard.
// Since the ecard page can be embedded on the thank you page of a donation, this can cause confusion in the data layer with events
// firing for both the donation and the ecard on the same page.
if (suppressEcardData) {
this.logger.log(
"⛔ Gift process was detected BUT suppressing EN_SUCCESSFUL_DONATION event due to SuppressPurchaseEcard option enabled"
);
window.sessionStorage.removeItem(this.endOfGiftProcessStorageKey);
} else {
this.logger.log("EN_SUCCESSFUL_DONATION");
this.addEndOfGiftProcessEventsToDataLayer();
}
}

if (window.pageJson) {
const pageJson = window.pageJson as Record<string, any>;
for (const property in pageJson) {
if (suppressEcardData && this.giftFields.includes(property)) {
continue;
}
const key = `EN_PAGEJSON_${property.toUpperCase()}`;
const value = pageJson[property];
dataLayerData[key] = this.transformJSON(value);
Expand Down
2 changes: 2 additions & 0 deletions packages/scripts/src/interfaces/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface Options {
UseAmountValidatorFromEN?: boolean;
SkipToMainContentLink?: boolean;
SrcDefer?: boolean;
SuppressPurchaseEcard?: boolean;
NeverBounceAPI?: string | null;
NeverBounceDateField?: string | null;
NeverBounceDateFormat?: string;
Expand Down Expand Up @@ -211,6 +212,7 @@ export const OptionsDefaults: Options = {
UseAmountValidatorFromEN: false,
SkipToMainContentLink: true,
SrcDefer: true,
SuppressPurchaseEcard: false,
NeverBounceAPI: null,
NeverBounceDateField: null,
NeverBounceStatusField: null,
Expand Down
Loading