Display Google Keywords that brought a user to the site

房东的猫 提交于 2019-12-23 15:41:06

问题


I am looking to display something like:

Hello, you've reached this site by looking for [google keyword(s)]

I'm pretty sure I've seen this done before but I am having troubles figuring out how to grab the keywords that were used to lead a user to my site. Anyone know the answer?


回答1:


You need to get the referring URL and then strip out everything for the "q" query string. This will give you the query that was used to get you to your page.




回答2:


Using the referrer (http://www.netmechanic.com/news/vol4/javascript_no14.htm) you can find where the user comes from. Then it's just a matter of parsing it correctly.


I saw this script :

function getkeywords() {
var x = document.referrer;
var lastparturl = 0;
if (x.search(/google/) != -1) {
lastparturl = x.indexOf("&btnG=Google+Search"); 
x = x.slice(38,lastparturl); 
x = x.concat("via google");
}
else if (x.search(/yahoo/) != -1) {
lastparturl = x.indexOf("&ei=UTF-8&iscqry=&fr=sfp"); 
x = x.slice(63,lastparturl); 
x = x.concat("via yahoo");
}
else if (x.search(/ask.com/) != -1) {
lastparturl = x.indexOf("&search=search&qsrc=0&o=0&l=dir"); 
x = x.slice(25,lastparturl); 
x = x.concat("via ask");
}
else if (x.search(/dogpile/) != -1) {
lastparturl = x.indexOf("/1/417/TopNavigation/Relevance/iq=true/zoom=off/_iceUrlFlag=7?_IceUrl=true"); 
x = x.slice(46,lastparturl); 
x = x.concat("via dogpile");
}
else if (x.search(/altavista/) != -1) {
lastparturl = x.indexOf("&kgs=1&kls=0"); 
x = x.slice(48,lastparturl); 
x = x.concat("via altavista");
}
else { 
x = "no keywords available";
} 
x = x.replace(/+/, " ");
return x; 
}

Here http://www.webmonkey.com/codelibrary/Get_Referrer_Keywords

I'm not sure if it works perfectly, but it worked OK when I reached their website through google.

I also saw that some scripts that you can download do that, for instance : http://webscripts.softpedia.com/script/Search-Engines/Keyword-Grabber-45299.html

Again, this will need to be tested.



来源:https://stackoverflow.com/questions/803009/display-google-keywords-that-brought-a-user-to-the-site

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!