Skip to content

Commit 828ff7b

Browse files
authored
Merge pull request #385 from 4site-interactive-studios/ecard-supress-datalayer
Option to supress gift related events to dataLayer when on eCard pages
2 parents b31a05d + b01c8a5 commit 828ff7b

6 files changed

Lines changed: 66 additions & 4 deletions

File tree

packages/scripts/dist/data-layer.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export declare class DataLayer {
55
private static instance;
66
private encoder;
77
private endOfGiftProcessStorageKey;
8+
private giftFields;
89
private excludedFields;
910
private hashedFields;
1011
private retainedEmailField;

packages/scripts/dist/data-layer.js

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,19 @@ export class DataLayer {
2424
this._form = EnForm.getInstance();
2525
this.encoder = new TextEncoder();
2626
this.endOfGiftProcessStorageKey = "ENGRID_END_OF_GIFT_PROCESS_EVENTS";
27+
// pageJson entries related to the gift process
28+
this.giftFields = [
29+
"amount",
30+
"currency",
31+
"donationLogId",
32+
"feeCover",
33+
"giftProcess",
34+
"paymentType",
35+
"receiptNumber",
36+
"recurring",
37+
"transactionId",
38+
"transactionType",
39+
];
2740
this.excludedFields = [
2841
// Credit Card
2942
"transaction.ccnumber",
@@ -102,13 +115,27 @@ export class DataLayer {
102115
onLoad() {
103116
// Collect all data layer variables to push at once
104117
const dataLayerData = {};
118+
const suppressEcardData = ENGrid.getPageType() === "ECARD" &&
119+
ENGrid.getOption("SuppressPurchaseEcard");
105120
if (ENGrid.getGiftProcess()) {
106-
this.logger.log("EN_SUCCESSFUL_DONATION");
107-
this.addEndOfGiftProcessEventsToDataLayer();
121+
// EN will chain together gift process data on the page json when redirecting from a completed donation to an ecard.
122+
// 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
123+
// firing for both the donation and the ecard on the same page.
124+
if (suppressEcardData) {
125+
this.logger.log("⛔ Gift process was detected BUT suppressing EN_SUCCESSFUL_DONATION event due to SuppressPurchaseEcard option enabled");
126+
window.sessionStorage.removeItem(this.endOfGiftProcessStorageKey);
127+
}
128+
else {
129+
this.logger.log("EN_SUCCESSFUL_DONATION");
130+
this.addEndOfGiftProcessEventsToDataLayer();
131+
}
108132
}
109133
if (window.pageJson) {
110134
const pageJson = window.pageJson;
111135
for (const property in pageJson) {
136+
if (suppressEcardData && this.giftFields.includes(property)) {
137+
continue;
138+
}
112139
const key = `EN_PAGEJSON_${property.toUpperCase()}`;
113140
const value = pageJson[property];
114141
dataLayerData[key] = this.transformJSON(value);

packages/scripts/dist/interfaces/options.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export interface Options {
1818
UseAmountValidatorFromEN?: boolean;
1919
SkipToMainContentLink?: boolean;
2020
SrcDefer?: boolean;
21+
SuppressPurchaseEcard?: boolean;
2122
NeverBounceAPI?: string | null;
2223
NeverBounceDateField?: string | null;
2324
NeverBounceDateFormat?: string;

packages/scripts/dist/interfaces/options.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export const OptionsDefaults = {
1717
UseAmountValidatorFromEN: false,
1818
SkipToMainContentLink: true,
1919
SrcDefer: true,
20+
SuppressPurchaseEcard: false,
2021
NeverBounceAPI: null,
2122
NeverBounceDateField: null,
2223
NeverBounceStatusField: null,

packages/scripts/src/data-layer.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,20 @@ export class DataLayer {
2323
private encoder = new TextEncoder();
2424
private endOfGiftProcessStorageKey = "ENGRID_END_OF_GIFT_PROCESS_EVENTS";
2525

26+
// pageJson entries related to the gift process
27+
private giftFields = [
28+
"amount",
29+
"currency",
30+
"donationLogId",
31+
"feeCover",
32+
"giftProcess",
33+
"paymentType",
34+
"receiptNumber",
35+
"recurring",
36+
"transactionId",
37+
"transactionType",
38+
];
39+
2640
private excludedFields = [
2741
// Credit Card
2842
"transaction.ccnumber",
@@ -111,15 +125,31 @@ export class DataLayer {
111125
private onLoad() {
112126
// Collect all data layer variables to push at once
113127
const dataLayerData: { [key: string]: any } = {};
128+
const suppressEcardData =
129+
ENGrid.getPageType() === "ECARD" &&
130+
ENGrid.getOption("SuppressPurchaseEcard");
114131

115132
if (ENGrid.getGiftProcess()) {
116-
this.logger.log("EN_SUCCESSFUL_DONATION");
117-
this.addEndOfGiftProcessEventsToDataLayer();
133+
// EN will chain together gift process data on the page json when redirecting from a completed donation to an ecard.
134+
// 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
135+
// firing for both the donation and the ecard on the same page.
136+
if (suppressEcardData) {
137+
this.logger.log(
138+
"⛔ Gift process was detected BUT suppressing EN_SUCCESSFUL_DONATION event due to SuppressPurchaseEcard option enabled"
139+
);
140+
window.sessionStorage.removeItem(this.endOfGiftProcessStorageKey);
141+
} else {
142+
this.logger.log("EN_SUCCESSFUL_DONATION");
143+
this.addEndOfGiftProcessEventsToDataLayer();
144+
}
118145
}
119146

120147
if (window.pageJson) {
121148
const pageJson = window.pageJson as Record<string, any>;
122149
for (const property in pageJson) {
150+
if (suppressEcardData && this.giftFields.includes(property)) {
151+
continue;
152+
}
123153
const key = `EN_PAGEJSON_${property.toUpperCase()}`;
124154
const value = pageJson[property];
125155
dataLayerData[key] = this.transformJSON(value);

packages/scripts/src/interfaces/options.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export interface Options {
1818
UseAmountValidatorFromEN?: boolean;
1919
SkipToMainContentLink?: boolean;
2020
SrcDefer?: boolean;
21+
SuppressPurchaseEcard?: boolean;
2122
NeverBounceAPI?: string | null;
2223
NeverBounceDateField?: string | null;
2324
NeverBounceDateFormat?: string;
@@ -211,6 +212,7 @@ export const OptionsDefaults: Options = {
211212
UseAmountValidatorFromEN: false,
212213
SkipToMainContentLink: true,
213214
SrcDefer: true,
215+
SuppressPurchaseEcard: false,
214216
NeverBounceAPI: null,
215217
NeverBounceDateField: null,
216218
NeverBounceStatusField: null,

0 commit comments

Comments
 (0)