在此期间,我们一直在使用这个可靠的网站重定向HTML/JavaScript代码。
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<meta http-equiv="refresh" content="1;url=https://www.nosuchwebsite.com">
<script type="text/javascript">
window.location.href = "https://www.nosuchwebsite.com"
</script>
<title>Page Redirection</title>
</head>
<body>
<!-- Note: don't tell people to `click` the link, just tell them that it is a link. -->
If you are not redirected automatically, follow the <a href='https://www.nosuchwebsite.com'>nosuchwebsite</a>
</body>
</html>
现在,我们希望在重定向之前执行Google Analytics跟踪代码。
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxxxx-x']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
我意识到,meta "refresh" 可能会比 JavaScript 跟踪代码先执行。 我想知道,是否有任何方法使 Google Analytics 跟踪代码在 meta "refresh" 之前运行
window.stop()
停止刷新,然后根据需要执行脚本操作。最后重定向到meta标签中的URL。 - shramee