Skip to content

Instantly share code, notes, and snippets.

@binderclip
Created October 12, 2015 04:12
Show Gist options
  • Save binderclip/437fbc9c3a6a78a8dd43 to your computer and use it in GitHub Desktop.
Save binderclip/437fbc9c3a6a78a8dd43 to your computer and use it in GitHub Desktop.
简单的广告统计测试页面
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>广告统计</title>
<script src="jquery.js"></script>
</head>
<body>
<a href="http://localhost:8000/apple" ad-load-url="http://localhost:8000/apple/load" ad-click-url="http://localhost:8000/apple/click">apple</a>
<a href="http://localhost:8000/orange" ad-load-url="http://localhost:8000/orange/load" ad-click-url="http://localhost:8000/orange/click">orange</a>
<a href="http://localhost:8000/banana">banana</a>
<a href="http://localhost:8000/watermelon">watermelon</a>
<script type="text/javascript">
// 获取元素测试
// console.log($("a"));
// console.log($("[ad-load-url]"));
// console.log($("[ad-click-url]"));
// 绑定事件,打印自己的内容
$(function(){
var ads_load = $("a[ad-load-url]");
var ads_click = $("a[ad-click-url]");
// console.log(ads_load);
// console.log(ads_click);
// 加载完成加载
ads_load.each(function() {
sendAdLog($(this).attr("ad-load-url"));
});
// 绑定点击事件
ads_click.each(function() {
$(this).click(function() {
sendAdLog($(this).attr("ad-click-url"))
});
});
function sendAdLog(url){
// 简单打印
// console.log("url: " + url);
// 发送请求
var sender = new Image();
sender.src = url;
}
})
</script>
</body>
</html>
@binderclip
Copy link
Author

整理出来的格式:

    <script type="text/javascript">
    $(function(){
      var ads_load = $("a[data-expose-tracking-url]");
      var ads_click = $("a[data-click-tracking-url]");
      // 加载完成加载
      ads_load.each(function() {
        sendAdLog($(this).attr("data-expose-tracking-url"));
      });
      // 绑定点击事件
      ads_click.each(function() {
        $(this).click(function() {
          sendAdLog($(this).attr("data-click-tracking-url"))
        });
      });
      function sendAdLog(url){
        var sender = new Image();
        sender.src = url;
      }
    })
    </script>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment