我一直在按照跟踪 Google 的离线转化的步骤进行操作。我希望能够设置 cookie - 读取 cookie,将其设置为表单中的隐藏字段,然后让表单通过电子邮件发送。
这是谷歌提供的代码:
<script type="text/javascript">
function setCookie(a,d,b){var c=new Date;c.setTime(c.getTime()+864E5*b);b="; expires="+c.toGMTString();document.cookie=a+"="+d+b}function getParam(a){return(a=RegExp("[?&]"+a+"=([^&]*)").exec(window.location.search))&&decodeURIComponent(a[1].replace(/\+/g," "))}var gclid=getParam("gclid");if(gclid){var gclsrc=getParam("gclsrc");(!gclsrc||-1!==gclsrc.indexOf("aw"))&&setCookie("gclid",gclid,90)};
</script>
<script>
function readCookie(name) {
var n = name + "=";
var cookie = document.cookie.split(';');
for(var i=0;i < cookie.length;i++) {
var c = cookie[i];
while (c.charAt(0)==' '){c = c.substring(1,c.length);}
if (c.indexOf(n) == 0){return
c.substring(n.length,c.length);}
}
return null;
}
window.onload = function() {
document.getElementById('gclid').value =
readCookie('gclid');
}
</script>
<form action="" name="myForm">
Name: <input type="text" name="name">
<input type="hidden" id="gclid" name="gclid" value="">
<input type="submit" value="Submit Form" name="btnSubmit">
</form>
两个 JS 都在 Joomla 2.5 的模板中,表格只是在一篇文章中。当我点击提交时,它发送电子邮件并且“gclid”返回为未定义。
它不是设置cookie - 读取cookie吗?我是否必须在模板中的某处调用“setcookie”才能使其工作?