我正在尝试准备一个简单的脚本,以便在用户接受后,以动态方式加载Google Analytics代码和再营销代码。
您能否告诉我此代码是否有任何问题?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://ogp.me/ns/fb#" xml:lang="en" lang="en">
<head>
<title>Test Page</title>
<meta name="DESCRIPTION" content="Just a test page" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script>
function processScripts(){
analytics();
remarketing();
}
function analytics(){
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-YOUR_UA-YOUR_VIEW', 'auto');
ga('set', 'anonymizeIp', true);
ga('send', 'pageview');
}
function remarketing(){
google_conversion_id = YOUR_CONVERSION_ID;
google_custom_params = window.google_tag_params;
google_remarketing_only = true;
var d = document,
h = d.getElementsByTagName('head')[0],
s = d.createElement('script');
s.type = 'text/javascript';
s.async = true;
s.src = '//www.googleadservices.com/pagead/conversion.js';
h.appendChild(s);
}
</script>
</head>
<body>
<p><a href="" onclick="processScripts();return false;">Accept</a></p>
</body>
</html>