-
-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathevents.diff
More file actions
71 lines (64 loc) · 2.81 KB
/
events.diff
File metadata and controls
71 lines (64 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
diff --git a/fastn-js/js/ftd.js b/fastn-js/js/ftd.js
index 9ec65539e..0e4ebe486 100644
--- a/fastn-js/js/ftd.js
+++ b/fastn-js/js/ftd.js
@@ -237,7 +237,7 @@ const ftd = (function () {
method = method.trim().toUpperCase();
const init = {
method,
- headers: { "Content-Type": "application/json" },
+ headers: {"Content-Type": "application/json"},
};
if (headers && headers instanceof fastn.recordInstanceClass) {
Object.assign(init.headers, headers.toObject());
@@ -550,6 +550,7 @@ const ftd = (function () {
}
if (url instanceof fastn.mutableClass) url = url.get();
+ let ga_data = {};
for (let i = 0, len = args.length; i < len; i += 1) {
let obj = args[i];
@@ -567,6 +568,11 @@ const ftd = (function () {
key = fastn_utils.getFlattenStaticValue(key);
+ if (key.starts_with("external-data:")) {
+ external_data[key] = value;
+ continue;
+ }
+
if (key == "all") {
console.error(
`[submit_form]: "all" key is reserved. Please change it to something else. Got for (${key}, ${value}, ${error})`,
@@ -577,8 +583,8 @@ const ftd = (function () {
if (error === "") {
console.warn(
`[submit_form]: ${obj} has empty error field. You're` +
- "probably passing a mutable string type which does not" +
- "work. You have to use `-- optional string $error:` for the error variable",
+ "probably passing a mutable string type which does not" +
+ "work. You have to use `-- optional string $error:` for the error variable",
);
}
@@ -624,12 +630,17 @@ const ftd = (function () {
redirect: "error",
// TODO: set credentials?
credentials: "same-origin",
- headers: { "Content-Type": "application/json" },
+ headers: {"Content-Type": "application/json"},
body: JSON.stringify(data),
};
console.log(url, data);
+ if (ga_data.not_emptu()) {
+ // also to /-/event/create/
+ external_event(ga_data);
+ }
+
fetch(url, init)
.then((res) => {
if (!res.ok) {
@@ -639,6 +650,7 @@ const ftd = (function () {
})
.then((response) => {
console.log("[http]: Response OK", response);
+ // if response.ga: call ga with whatever
if (response.redirect) {
window.location.href = response.redirect;
} else if (!!response && !!response.reload) {