我目前正在开发一个脚本,允许我检索网站上连接尝试的用户名。但主要限制是我无法编辑页面的 HTML,只能通过跟踪代码管理器添加我的脚本。
我必须解释我使用什么工具。我正在使用网络跟踪工具SnowPlow Analytics。它的工作原理与 Google Analytics 相同,带有一个数组 _snaq,(将)包含要处理的数据。问题的核心在于,即使将数据很好地添加到数组中,主脚本 (sp.js) 也没有时间完成工作并在 POST 请求之前向 CloudFront 收集器发送请求。
这是我使用的示例页面,以及捕获数据的脚本:
页:
<html>
<head>
<title>Sign In Example</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- SnowPlow modified -->
<script type="text/javascript">
var _snaq=_snaq||[];
_snaq.push(['setCollectorCf','xxxxxxxxxxxxxx']);
_snaq.push(['trackPageView']);
_snaq.push(['enableLinkTracking']);
/*
* Here is the anonymous function to include properly the snowplow.js
* minified: d1fc8wv8zag5ca.cloudfront.net/0.11.1/sp.js
* github : github.com/snowplow/snowplow/tree/master/1-trackers/javascript-tracker
*/
</script>
<!--/ SnowPlow modified -->
<script src="js/jquery.min.js"></script>
<script async="" type="text/javascript" src="js/getLogin.min.js"></script>
</head>
<body>
<form class="formClass">
<h2>Please sign in</h2>
<input type="text" class="textInput" placeholder="Email address" />
<input type="password" class="passwordInput" placeholder="Password" />
<label class="checkbox">
<input type="checkbox" value="remember-me" /> Remember me
</label>
<button class="submitButton" type="submit">Sign in</button>
</form>
</body>
</html>`
脚本:
var checked, cb = $('input[value="remember-me"]')[0], butt = $('button[type="submit"]')[0];
if(cb.checked)
checked = 1.0;
else
checked = 0.0;
function snaqPush()
{
_snaq.push(['trackStructEvent', 'connection', 'connectionAttempt', 'email', $('input[placeholder = "Email address"]').val(), checked]);
}
cb.addEventListener("click", function(e)
{
if(cb.checked)
checked = 1.0;
else
checked = 0.0;
}, false);
butt.addEventListener("click", function()
{
snaqPush(); //or directly the _snaq push([...]) here
_snaq.push(function()
{
setTimeout(function(){}, 1000);
}); //I have try the setTimeout in and out of a _snaq.push, and it stills not work
});
注意:POST 请求在包含数据的 _snaq.push() 之后使用断点!
在此先感谢您的帮助!