sfc-utils 1.4.121 → 1.4.123
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/package.json +1 -1
- package/regwall.js +37 -10
package/package.json
CHANGED
package/regwall.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// NOTE: Script meant to be called when the regwall is requested
|
|
2
2
|
// This script will listen for a successful registration, then run a function passed to it
|
|
3
|
-
const listenForRegSuccess = (
|
|
3
|
+
const listenForRegSuccess = () => {
|
|
4
4
|
return new Promise((resolve, reject) => {
|
|
5
5
|
if (window) {
|
|
6
6
|
let attempts = 0;
|
|
@@ -13,11 +13,34 @@ const listenForRegSuccess = (resultFunc, resultParams) => {
|
|
|
13
13
|
const observerCallback = (entries, observer) => {
|
|
14
14
|
entries.forEach((entry) => {
|
|
15
15
|
if (!entry.isIntersecting) {
|
|
16
|
-
//
|
|
17
|
-
|
|
18
|
-
//
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
// Disconnect the observer
|
|
17
|
+
observer.disconnect();
|
|
18
|
+
// Check the dataLayer for a successful registration (the regwall sends the event to GA)
|
|
19
|
+
const dataLayer = window.dataLayer;
|
|
20
|
+
let foundRegSuccess = false;
|
|
21
|
+
if (dataLayer && dataLayer.length) {
|
|
22
|
+
for (let i = 0; i < dataLayer.length; i++) {
|
|
23
|
+
// Make sure this item is not an array
|
|
24
|
+
if (Array.isArray(dataLayer[i])) {
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
if (
|
|
28
|
+
dataLayer[i].label &&
|
|
29
|
+
dataLayer[i].label.indexOf("Successfull Submission") > -1
|
|
30
|
+
) {
|
|
31
|
+
foundRegSuccess = true;
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (foundRegSuccess) {
|
|
37
|
+
// Perform your action here
|
|
38
|
+
console.log("Registration successful!");
|
|
39
|
+
innerResolve(true);
|
|
40
|
+
} else {
|
|
41
|
+
console.log("User did not register");
|
|
42
|
+
innerResolve(false);
|
|
43
|
+
}
|
|
21
44
|
}
|
|
22
45
|
});
|
|
23
46
|
};
|
|
@@ -43,14 +66,18 @@ const listenForRegSuccess = (resultFunc, resultParams) => {
|
|
|
43
66
|
checkForTarget(innerResolve);
|
|
44
67
|
}, 200);
|
|
45
68
|
} else {
|
|
46
|
-
|
|
69
|
+
console.log("Regwall: Target element not found after attempts");
|
|
70
|
+
innerResolve(false);
|
|
47
71
|
}
|
|
48
72
|
}
|
|
49
73
|
};
|
|
50
|
-
// Kick off check
|
|
51
|
-
|
|
74
|
+
// Kick off check after a short delay
|
|
75
|
+
setTimeout(() => {
|
|
76
|
+
checkForTarget(resolve);
|
|
77
|
+
}, 200);
|
|
52
78
|
} else {
|
|
53
|
-
|
|
79
|
+
console.log("Regwall: No window found");
|
|
80
|
+
resolve(false);
|
|
54
81
|
}
|
|
55
82
|
});
|
|
56
83
|
};
|