@4site/engrid-scripts 0.22.9 → 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.
- package/dist/data-layer.js +36 -62
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
package/dist/data-layer.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
107
|
-
|
|
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
|
-
|
|
115
|
-
|
|
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
|
-
|
|
122
|
-
|
|
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
|
-
|
|
128
|
-
|
|
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
|
-
|
|
138
|
-
|
|
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
|
-
|
|
148
|
-
|
|
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
|
-
|
|
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
|
-
|
|
166
|
-
event: "EN_FASTFORMFILL_PERSONALINFO_PARTIALSUCCESS",
|
|
167
|
-
});
|
|
145
|
+
dataLayerEvents.push("EN_FASTFORMFILL_PERSONALINFO_PARTIALSUCCESS");
|
|
168
146
|
}
|
|
169
147
|
else {
|
|
170
|
-
|
|
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
|
-
|
|
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
|
-
|
|
188
|
-
event: "EN_FASTFORMFILL_ADDRESS_PARTIALSUCCESS",
|
|
189
|
-
});
|
|
161
|
+
dataLayerEvents.push("EN_FASTFORMFILL_ADDRESS_PARTIALSUCCESS");
|
|
190
162
|
}
|
|
191
163
|
else {
|
|
192
|
-
|
|
193
|
-
event: "EN_FASTFORMFILL_ADDRESS_FAILURE",
|
|
194
|
-
});
|
|
164
|
+
dataLayerEvents.push("EN_FASTFORMFILL_ADDRESS_FAILURE");
|
|
195
165
|
}
|
|
196
166
|
}
|
|
197
167
|
if (fastFormFill) {
|
|
198
|
-
|
|
199
|
-
event: "EN_FASTFORMFILL_ALL_SUCCESS",
|
|
200
|
-
});
|
|
168
|
+
dataLayerEvents.push("EN_FASTFORMFILL_ALL_SUCCESS");
|
|
201
169
|
}
|
|
202
170
|
else {
|
|
203
|
-
|
|
204
|
-
|
|
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
|
}
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const AppVersion = "0.22.
|
|
1
|
+
export declare const AppVersion = "0.22.10";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const AppVersion = "0.22.
|
|
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.
|
|
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": "
|
|
28
|
+
"gitHead": "c005c8d8cf69b549193e053ed270a5a04ffe57af",
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"nodemon": "^2.0.20"
|
|
31
31
|
}
|