根据推荐人、用户代理显示不同的电话号码
我尝试根据多种因素在网站上提供不同的电话号码,从而使我们能够根据用户到达页面的方式来跟踪入站电话。
- 通过检查“?provider=”查询字符串来检查用户是否来自广告,如果存在,则提供广告号码
- 如果不存在,请检查 userAgent 以向机器人提供“默认”号码
- 如果 userAgent 不是机器人,请检查引荐来源网址并提供不同的跟踪基于常见 SERP 点击次数的数字
该网站无法运行服务器端脚本,因此必须使用 javascript 来完成(我对此相当缺乏经验)。我已经将一些零碎的东西拼凑在一起,但最终希望将所有内容组合起来,并使其在一个可以在页面加载时调用的单个 .js 文件中一起工作。
到目前为止,我得到的信息如下:
<script type="text/javascript">
//Querystring to check if paid session or organic
function providercheck() {
var str= location.href;
if (str.indexOf("?provider=") > -1) {
document.write("paid phone number");
}
else {
botcheck();
}
}
//Check userAgent to serve organic number to bots
function botcheck() {
if(navigator.userAgent.toLowerCase().indexOf("googlebot") <= -1) {
document.write("default phone number");
}
else {
refcheck();
}
}
//Check for referrer and serve number based on last referrer
function refcheck() {
var last_referrer = document.referrer;
if (last_referrer.indexOf("google") > -1) {
document.write("google tracking number");
}
else if (last_referrer.indexOf("yahoo") > -1) {
document.write("yahoo tracking number");
}
else {
document.write("default number");
}
}
</script>
非常感谢任何帮助或指导。我还需要设置一个会话 cookie,以继续提供相同的号码,直到用户离开网站,但我想先让它工作
I am attempting to serve different phone numbers on a site based on a number of factors, allowing us to track inbound phone calls based on how users arrived at the page.
- Check to see if user is coming from advertising by checking for "?provider=" querystring, serve advertising number if present
- If not, check userAgent to serve "default" number to bots
- If userAgent is not a bot, check referrer and serve different tracking number based on common SERP clicks
This site is unable to run server-side scripting so this has to be done with javascript (which I am fairly inexperienced with). I've cobbled together bits and pieces but ultimately would like to combine everything and have it work together in a single .js file that can be called on page load.
Here's what I have so far:
<script type="text/javascript">
//Querystring to check if paid session or organic
function providercheck() {
var str= location.href;
if (str.indexOf("?provider=") > -1) {
document.write("paid phone number");
}
else {
botcheck();
}
}
//Check userAgent to serve organic number to bots
function botcheck() {
if(navigator.userAgent.toLowerCase().indexOf("googlebot") <= -1) {
document.write("default phone number");
}
else {
refcheck();
}
}
//Check for referrer and serve number based on last referrer
function refcheck() {
var last_referrer = document.referrer;
if (last_referrer.indexOf("google") > -1) {
document.write("google tracking number");
}
else if (last_referrer.indexOf("yahoo") > -1) {
document.write("yahoo tracking number");
}
else {
document.write("default number");
}
}
</script>
Any help or guidance is very appreciated. I also need to set a session cookie to continue to serve the same number until a user leaves the site, but wanted to get this working first
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试这样的操作:
将此跨度放在页面上的某个位置:
Superdefaultnumber
然后将此代码放在页面头部的脚本标记中文档:
You could try something like this:
put this span somewhere on your page:
<span id="phoneNumber">Superdefaultnumber</span>
And then this code in a script tag in the head of your document: