【发布时间】:2019-11-11 19:21:05
【问题描述】:
我正在使用 crowd-html 元素制作一个相当简单的表单,这使得一切都变得非常简单。作为我们研究的一部分,我们想看看工人如何与表单交互,所以我们有一堆基本的 JS 日志记录。这一切都准备为 JSON,其想法是使用 AWS API Gateway 和 AWS Lambda 记录它。代码似乎都在单元测试中工作,但不是真正的形式。我正在尝试这样做:
document.querySelector('crowd-form').onsubmit = function (e) {
if (!validateForm()) {
window.alert("Please check the form carefully, it isn't filled out completely!");
e.preventDefault();
} else {
let event_data = {
'specific_scroll_auditor': auditor_scrolled_pixels_specific.submit_callable(),
'specific_clicks_auditor': auditor_clicks_specific.submit_callable(),
'mouse_movements_total': auditor_mouse_movement_total.submit_callable(),
'on_focus_time': auditor_on_focus_time.submit_callable(),
'total_task_time': auditor_total_task_time.submit_callable(),
'focus_changes': auditor_focus_changes.submit_callable()
};
log_client_event('auditors', event_data);
post_event_log()
}
}
请注意,验证位有效,但日志记录无效。我已经自己测试了 post_event_log() ,它工作得很好,所以看起来要么 1) 出于某种原因我从来没有遇到过 else 子句,或者 2) 提交发生的速度比我调用日志记录函数的速度要快. (但是为什么,因为验证有效?)
我也试过这个,借鉴了我们的灵感来自土耳其代码 (https://github.com/CuriousG102/turkey)。
$(window).ready(function () {
window.onbeforeunload = function () {
let event_data = {
'specific_scroll_auditor': auditor_scrolled_pixels_specific.submit_callable(),
'specific_clicks_auditor': auditor_clicks_specific.submit_callable(),
'mouse_movements_total': auditor_mouse_movement_total.submit_callable(),
'on_focus_time': auditor_on_focus_time.submit_callable(),
'total_task_time': auditor_total_task_time.submit_callable(),
'focus_changes': auditor_focus_changes.submit_callable()
};
log_client_event('auditors', event_data);
post_event_log()
}
});
这也行不通。我宁愿像上面那样以某种简单的方式来做这件事,而不是完全重写提交函数,但也许我必须这样做?
【问题讨论】: