友盟统计,h5 API

友盟统计,h5 API

/**
       *   友盟统计事件   API   https://developer.umeng.com/docs/67963/detail/74517
       *   _trackEvent  事件统计
       *   _trackPageView   url 统计 // 适用于统计AJAX、异步加载页面,友情链接,下载链接的流量
       *   _setAutoPageview    // 是否关闭自动统计  // false  关闭自动发送  // true 开启自动发送
       *   _setAccount        // 当您的页面上添加了多个统计代码时,需要用到本方法绑定需要哪个siteid对应的统计代码来接受API发送的请求。
       *                      // 未绑定的siteid将忽略相关请求。
       *   _setCustomVar      // 用于发送为访客打自定义标记的请求,用来统计会员访客、登录访客、不同来源访客的浏览数据。
       *   _deleteCustomVar   // 发送删除自定义访客标签的请求。将访客身上已被标记的自定义访客类型去掉,去掉后不再继续统计。
       * 
       *   params        object   所有的统计参数
       *     eventType   string   统计的事件类型 (上面的3中类型之一)
       *     _setAutoPageview  boolean  是否关闭网页曝光自动统计
       * 
       *     _trackPageview 参数
       *     url         string    统计的页面的URL
       *     referer_url  string   该统计页面的来源页面
       *     
       *     _setAccount 参数
       *     id           int      该统计代码的siteid
       *     
       *     _trackEvent 事件类参数
       *     category     string   _trackEvent 的事件类别
       *     action       string   _trackEvent 的交互行为
       *     label        string   _trackEvent 对此事件更详细的描述
       *     value        string   _trackEvent 对此事件的打分(整数)
       *     nodeid       string   _trackEvent 对此事件的div元素的ID,
       *     
       *     _setCustomVar参数
       *     name         string   用来定义访客的种类  (会员级别、访客来源等)
       *     value        string   自定义访客值,用作类型的描述 (VIP1、VIP2)
       *     time         int      1 (默认值)长期有效, 0 仅在发包页面有效 , 2 本次访问有效
       *     _deleteCustomVar params
       *     name  同上
       * 
      */
      function umEvent(obj){
        window._czc = window._czc || [];
        if(window.ENV ) return;
        var allEvent = {
          _trackEvent: function(obj){
            _czc.push(["_trackEvent", obj.category || 'noCategory', obj.action || 'noAction', obj.label || '', obj.value || 1, obj.nodeid || ''])
            return this;
          },
          _trackPageview: function(obj){
            _czc.push(["_trackPageview", obj.url || window.location.href, obj.referer_url || '' ])
            obj._setAutoPageview !== undefined && this._setAutoPageview(obj._setAutoPageview);
            return this;
          },
          _setAutoPageview: function(obj){
            _czc.push([ '_setAutoPageview', obj['_setAutoPageview'] || false ])
            return this;
          },
          _setAccount: function(obj){
            _czc.push([ '_setAccount', obj.id ])
            return this;
          },
          _setCustomVar: function(obj){
            _czc.push([ '_setCustomVar', obj.name || 'noName' , obj.value || 'vip', obj.time || 1 ])
            return this;
          },
          _deleteCustomVar: function(obj){
            _czc.push([ '_deleteCustomVar', obj.name || 'noName' ])
            return this;
          }
        }; 
        allEvent[obj.eventType] && allEvent[obj.eventType](obj) ;
        return umEvent;
      }
    
    

你可能感兴趣的:(javascript)