zoukankan      html  css  js  c++  java
  • 关于流量统计中的客户端脚本获取来路地址

      最近公司的百度竞价排名的每天定额总是提前用完,而流量统计里却看不到一个相关的关键字,于是打算自己做个简单的统计,看看是不是摆渡有在黑钱了.

     基于js的流量统计一般会涉及下面两个主要问题:

     1.怎么获取来路地址:
      使用 document.referrer, 因为refferrer中可能包含url字符,所以建议使用encodeURIComponent(document.refferrer)进行编码,服务起使用Server.UrlDecode解码,有一点要注意,google搜索过来的跟baidu过来的编码不同,google的来路信息里的中文使用utf-8编码的,而baidu中文部分使用gb2312进行,解码时注意区分.
     2.怎么跨域发送请求:
      使用document.write("<img src='http://www.0576sy.cn/tj.aspx?q=" +ref_url +"' style='display:none;' />")动态创建DOM元素的方式来进行跨域发送数据 ref_url对应上面encodeURLComponent(document.referrer)的书籍,其中tj.aspx可以通过Request对象获取IP,浏览器等一系列信息, tj.aspx可以输出一张图片,或者在style='display:none;'时可以什么多不输出.
    下面通过创建script对象进行跨域投递数据,具体使用那种看你自己的选择
    var obj_script= document.createElement("script");
    obj_script.src=http://www.0576sy.cn/tj.aspx?q= +encodeURIComponent( document.referrer);
    document.getElementsByTagName("head").item(0).appendChild(obj_script);
    alert(document.getElementsByTagName("head").item(0).childNodes.length);

  • 相关阅读:
    Objective-C写出Json文件(可作配置文件)
    关于快速排序的部分内容
    关于折半查找排序的部分内容
    异步下载网络图片
    pytest(5):setup/teardown框架结构
    pytest(4):用例参数化
    pytest(3):pytest运行参数介绍
    pytest(2):使用pycharm运行pytest
    pytest(1):pytest的安装与使用
    pytest文档4-Allure报告清除上一次数据
  • 原文地址:https://www.cnblogs.com/wdfrog/p/1498848.html
Copyright © 2011-2022 走看看