@4site/engrid-scripts 0.22.8 → 0.22.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -86,68 +86,50 @@ export class DataLayer {
86
86
  return "";
87
87
  }
88
88
  onLoad() {
89
+ // Collect all data layer events and variables to push at once
90
+ const dataLayerData = {};
91
+ const dataLayerEvents = [];
89
92
  if (ENGrid.getGiftProcess()) {
90
93
  this.logger.log("EN_SUCCESSFUL_DONATION");
91
- this.dataLayer.push({
92
- event: "EN_SUCCESSFUL_DONATION",
93
- });
94
+ dataLayerEvents.push("EN_SUCCESSFUL_DONATION");
94
95
  this.addEndOfGiftProcessEventsToDataLayer();
95
96
  }
96
97
  else {
97
98
  this.logger.log("EN_PAGE_VIEW");
98
- this.dataLayer.push({
99
- event: "EN_PAGE_VIEW",
100
- });
99
+ dataLayerEvents.push("EN_PAGE_VIEW");
101
100
  }
102
101
  if (window.pageJson) {
103
102
  const pageJson = window.pageJson;
104
103
  for (const property in pageJson) {
105
104
  if (!Number.isNaN(pageJson[property])) {
106
- this.dataLayer.push({
107
- event: `EN_PAGEJSON_${property.toUpperCase()}-${pageJson[property]}`,
108
- });
109
- this.dataLayer.push({
110
- [`'EN_PAGEJSON_${property.toUpperCase()}'`]: pageJson[property],
111
- });
105
+ dataLayerEvents.push(`EN_PAGEJSON_${property.toUpperCase()}-${pageJson[property]}`);
106
+ dataLayerData[`'EN_PAGEJSON_${property.toUpperCase()}'`] =
107
+ pageJson[property];
112
108
  }
113
109
  else {
114
- this.dataLayer.push({
115
- event: `EN_PAGEJSON_${property.toUpperCase()}-${this.transformJSON(pageJson[property])}`,
116
- });
117
- this.dataLayer.push({
118
- [`'EN_PAGEJSON_${property.toUpperCase()}'`]: this.transformJSON(pageJson[property]),
119
- });
110
+ dataLayerEvents.push(`EN_PAGEJSON_${property.toUpperCase()}-${this.transformJSON(pageJson[property])}`);
111
+ dataLayerData[`'EN_PAGEJSON_${property.toUpperCase()}'`] =
112
+ this.transformJSON(pageJson[property]);
120
113
  }
121
- this.dataLayer.push({
122
- event: "EN_PAGEJSON_" + property.toUpperCase(),
123
- eventValue: pageJson[property],
124
- });
114
+ dataLayerEvents.push("EN_PAGEJSON_" + property.toUpperCase());
115
+ dataLayerData.eventValue = pageJson[property];
125
116
  }
126
117
  if (ENGrid.getPageCount() === ENGrid.getPageNumber()) {
127
- this.dataLayer.push({
128
- event: "EN_SUBMISSION_SUCCESS_" + pageJson.pageType.toUpperCase(),
129
- });
130
- this.dataLayer.push({
131
- [`'EN_SUBMISSION_SUCCESS_${pageJson.pageType.toUpperCase()}'`]: "TRUE",
132
- });
118
+ dataLayerEvents.push("EN_SUBMISSION_SUCCESS_" + pageJson.pageType.toUpperCase());
119
+ dataLayerData[`'EN_SUBMISSION_SUCCESS_${pageJson.pageType.toUpperCase()}'`] = "TRUE";
133
120
  }
134
121
  }
135
122
  const urlParams = new URLSearchParams(window.location.search);
136
123
  urlParams.forEach((value, key) => {
137
- this.dataLayer.push({
138
- event: `EN_URLPARAM_${key.toUpperCase()}-${this.transformJSON(value)}`,
139
- });
140
- this.dataLayer.push({
141
- [`'EN_URLPARAM_${key.toUpperCase()}'`]: this.transformJSON(value),
142
- });
124
+ dataLayerEvents.push(`EN_URLPARAM_${key.toUpperCase()}-${this.transformJSON(value)}`);
125
+ dataLayerData[`'EN_URLPARAM_${key.toUpperCase()}'`] =
126
+ this.transformJSON(value);
143
127
  });
144
128
  if (ENGrid.getPageType() === "DONATION") {
145
129
  const recurrFreqEls = document.querySelectorAll('[name="transaction.recurrfreq"]');
146
130
  const recurrValues = [...recurrFreqEls].map((el) => el.value);
147
- this.dataLayer.push({
148
- event: "EN_RECURRING_FREQUENCIES",
149
- [`'EN_RECURRING_FREQEUENCIES'`]: recurrValues,
150
- });
131
+ dataLayerEvents.push("EN_RECURRING_FREQUENCIES");
132
+ dataLayerData[`'EN_RECURRING_FREQEUENCIES'`] = recurrValues;
151
133
  }
152
134
  let fastFormFill = false;
153
135
  // Fast Form Fill - Personal Details
@@ -156,20 +138,14 @@ export class DataLayer {
156
138
  const allPersonalMandatoryInputsAreFilled = FastFormFill.allMandatoryInputsAreFilled(fastPersonalDetailsFormBlock);
157
139
  const somePersonalMandatoryInputsAreFilled = FastFormFill.someMandatoryInputsAreFilled(fastPersonalDetailsFormBlock);
158
140
  if (allPersonalMandatoryInputsAreFilled) {
159
- this.dataLayer.push({
160
- event: "EN_FASTFORMFILL_PERSONALINFO_SUCCESS",
161
- });
141
+ dataLayerEvents.push("EN_FASTFORMFILL_PERSONALINFO_SUCCESS");
162
142
  fastFormFill = true;
163
143
  }
164
144
  else if (somePersonalMandatoryInputsAreFilled) {
165
- this.dataLayer.push({
166
- event: "EN_FASTFORMFILL_PERSONALINFO_PARTIALSUCCESS",
167
- });
145
+ dataLayerEvents.push("EN_FASTFORMFILL_PERSONALINFO_PARTIALSUCCESS");
168
146
  }
169
147
  else {
170
- this.dataLayer.push({
171
- event: "EN_FASTFORMFILL_PERSONALINFO_FAILURE",
172
- });
148
+ dataLayerEvents.push("EN_FASTFORMFILL_PERSONALINFO_FAILURE");
173
149
  }
174
150
  }
175
151
  // Fast Form Fill - Address Details
@@ -178,31 +154,29 @@ export class DataLayer {
178
154
  const allAddressMandatoryInputsAreFilled = FastFormFill.allMandatoryInputsAreFilled(fastAddressDetailsFormBlock);
179
155
  const someAddressMandatoryInputsAreFilled = FastFormFill.someMandatoryInputsAreFilled(fastAddressDetailsFormBlock);
180
156
  if (allAddressMandatoryInputsAreFilled) {
181
- this.dataLayer.push({
182
- event: "EN_FASTFORMFILL_ADDRESS_SUCCESS",
183
- });
157
+ dataLayerEvents.push("EN_FASTFORMFILL_ADDRESS_SUCCESS");
184
158
  fastFormFill = fastFormFill ? true : false; // Only set to true if it was true before
185
159
  }
186
160
  else if (someAddressMandatoryInputsAreFilled) {
187
- this.dataLayer.push({
188
- event: "EN_FASTFORMFILL_ADDRESS_PARTIALSUCCESS",
189
- });
161
+ dataLayerEvents.push("EN_FASTFORMFILL_ADDRESS_PARTIALSUCCESS");
190
162
  }
191
163
  else {
192
- this.dataLayer.push({
193
- event: "EN_FASTFORMFILL_ADDRESS_FAILURE",
194
- });
164
+ dataLayerEvents.push("EN_FASTFORMFILL_ADDRESS_FAILURE");
195
165
  }
196
166
  }
197
167
  if (fastFormFill) {
198
- this.dataLayer.push({
199
- event: "EN_FASTFORMFILL_ALL_SUCCESS",
200
- });
168
+ dataLayerEvents.push("EN_FASTFORMFILL_ALL_SUCCESS");
201
169
  }
202
170
  else {
203
- this.dataLayer.push({
204
- event: "EN_FASTFORMFILL_ALL_FAILURE",
205
- });
171
+ dataLayerEvents.push("EN_FASTFORMFILL_ALL_FAILURE");
172
+ }
173
+ // Push all collected events individually (GTM requirement)
174
+ dataLayerEvents.forEach((event) => {
175
+ this.dataLayer.push({ event });
176
+ });
177
+ // Push all collected variables at once
178
+ if (Object.keys(dataLayerData).length > 0) {
179
+ this.dataLayer.push(dataLayerData);
206
180
  }
207
181
  this.attachEventListeners();
208
182
  }
@@ -12,6 +12,7 @@ export declare class NeverBounce {
12
12
  private logger;
13
13
  private shouldRun;
14
14
  private nbLoaded;
15
+ private bypassEmails;
15
16
  constructor(apiKey: string, dateField: string | null, statusField: string | null, dateFormat: string | undefined);
16
17
  private init;
17
18
  private clearStatus;
@@ -19,5 +20,6 @@ export declare class NeverBounce {
19
20
  private setEmailStatus;
20
21
  private insertAfter;
21
22
  private wrap;
23
+ private isBypassEmail;
22
24
  private validate;
23
25
  }
@@ -14,6 +14,14 @@ export class NeverBounce {
14
14
  this.logger = new EngridLogger("NeverBounce", "#039bc4", "#dfdfdf", "📧");
15
15
  this.shouldRun = true;
16
16
  this.nbLoaded = false;
17
+ this.bypassEmails = [
18
+ "noaddress.ea",
19
+ ];
20
+ const searchParams = new URLSearchParams(window.location.search);
21
+ if (searchParams.has("bypassemailvalidation")) {
22
+ this.logger.log("Bypass Email Validation Enabled - not running NeverBounce");
23
+ return;
24
+ }
17
25
  this.emailField = document.getElementById("en__field_supporter_emailAddress");
18
26
  window._NBSettings = {
19
27
  apiKey: this.apiKey,
@@ -154,6 +162,10 @@ export class NeverBounce {
154
162
  this.logger.log("E-mail Field Not Found");
155
163
  return;
156
164
  }
165
+ if (this.isBypassEmail()) {
166
+ this.logger.log("Bypass email detected. Skipping status update.");
167
+ return;
168
+ }
157
169
  // Search page for the NB Wrapper div and set as variable
158
170
  const nb_email_field_wrapper = (document.getElementById("nb-wrapper"));
159
171
  // Search page for the NB Feedback div and set as variable
@@ -222,6 +234,12 @@ export class NeverBounce {
222
234
  (_a = el.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(wrapper, el);
223
235
  wrapper.appendChild(el);
224
236
  }
237
+ isBypassEmail() {
238
+ if (!this.emailField || !this.emailField.value)
239
+ return false;
240
+ const email = this.emailField.value.toLowerCase();
241
+ return this.bypassEmails.some((bypassEmail) => email.includes(bypassEmail.toLowerCase()));
242
+ }
225
243
  validate() {
226
244
  var _a;
227
245
  if (!this.form.validate)
@@ -231,6 +249,10 @@ export class NeverBounce {
231
249
  this.logger.log("validate(): Should Not Run. Returning true.");
232
250
  return;
233
251
  }
252
+ if (this.isBypassEmail()) {
253
+ this.logger.log("Bypass email detected. Skipping validation.");
254
+ return;
255
+ }
234
256
  if (this.nbStatus) {
235
257
  this.nbStatus.value = nbResult;
236
258
  }
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const AppVersion = "0.22.8";
1
+ export declare const AppVersion = "0.22.10";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const AppVersion = "0.22.8";
1
+ export const AppVersion = "0.22.10";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@4site/engrid-scripts",
3
- "version": "0.22.8",
3
+ "version": "0.22.10",
4
4
  "description": "Scripts for the ENGRID Project",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -25,7 +25,7 @@
25
25
  "strongly-typed-events": "^2.0.9"
26
26
  },
27
27
  "homepage": "https://github.com/4site-interactive-studios/engrid#readme",
28
- "gitHead": "06c2bc30e43887085cec5def6770db4dcc073297",
28
+ "gitHead": "c005c8d8cf69b549193e053ed270a5a04ffe57af",
29
29
  "devDependencies": {
30
30
  "nodemon": "^2.0.20"
31
31
  }