在Cookie中捕获用户gclid

时间:2018-06-05 04:09:23

标签: javascript

我试图通过以下代码捕获特定于Google AdWords点击的ID号,但无济于事。此代码过去曾有效,可以在以下URL中捕获gcid;

https://go.emnify.com/m2m-sim-global?utm_term=m2m%20sim&utm_campaign=Prod- 
M2M+SIM-Global-EN&utm_source=adwords&utm_medium=ppc&hsa_tgt=kwd- 
321680647394&hsa_grp=58273623009&hsa_src=g&hsa_net=adwords&
hsa_mt=e&hsa_ver=3&hsa_ad=270954992832&hsa_acc=6763313939&hsa_
kw=m2m%20sim&hsa_cam=1024596689&
gclid=EAIaIQobChMI0vqV7dK72wIVEMZkCh031w8HEAAYAiAAEgIsJ_D_BwE



<script type="text/javascript">
function setCookie(name, value, days){
var date = new Date();
date.setTime(date.getTime() + (days*24*60*60*1000)); 
var expires = "; expires=" + date.toGMTString();
document.cookie = name + "=" + value + expires + ";path=/";
}
function getParam(p){
var match = RegExp('[?&]' + p + '=        
([^&]*)').exec(window.location.search);
return match && decodeURIComponent(match[1].replace(/\+/g, ' '));}
var gclid = getParam('gclid');
if(gclid){
var gclsrc = getParam('gclsrc');
if(!gclsrc || gclsrc.indexOf('aw') !== -1){
    setCookie('gclid', gclid, 90);
 }
 }
 </script>  

此代码中的任何内容配置错误吗?

干杯,

0 个答案:

没有答案