@@ -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 ) ;
0 commit comments