我一直在跟踪从Google跟踪离线转化的步骤。我希望能够设置一个cookie - 读取cookie,将其设置为我表单中的隐藏字段,然后将表单通过电子邮件发送给它。
以下是Google提供的代码:
<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”才能使其正常工作?
答案 0 :(得分:0)
您只需添加:
<input type="hidden" id="google_code" name="google_code" value="<?php echo $_GET['gclid'];?>">
进入你的表格。我的第一篇文章中的上述代码没有为此做任何事情。