analytics.js 7.19 KB
'use strict'
import {LOG_EVENT_HOST, API_HOST, SERVICE_HOST } from '../libs/config';
import { UPLOAD_LOG} from '../libs/request';
import { getYHStorageSync } from '../utils/util';

const YB_ENTER_FOREGROUND = 'YB_ENTER_FOREGROUND'; //程序切换置前台
const YB_ENTER_BACKGROUND = 'YB_ENTER_BACKGROUND'; //系统-程序切换置后台
const YB_LAUNCH_APP = 'YB_LAUNCH_APP';       //系统-启动小程序
const YB_EXIT_APP = 'YB_EXIT_APP';         //系统-退出小程序
const YB_PAGE_OPEN_L = 'YB_PAGE_OPEN_L';      //页面加载/刷新/返回时
const YB_MAIN_TAB_C = 'YB_MAIN_TAB_C';       //点击页面底部的功能按钮时,点击时才上报,默认载入时不上报;
const YB_CATEGORY_FL = 'YB_CATEGORY_FLR_C';//品类页楼层
const YB_MAIN_EVENT = 'YB_MAIN_EVENT';       //首页-楼层事件点击
const YB_MY_LOGIN = 'YB_MY_LOGIN';         //当用户使用该登录方式登录成功时
const YB_GDS_DT_BILL = 'YB_GDS_DT_BILL';      //点击商品详情页底部的立即购买按钮,选择完颜色/尺寸后上报
const YB_SC_ORD = 'YB_SC_ORD';           //生成订单
const YB_SC_PAY_RES = 'YB_SC_PAY_RES';       //购物车-付款结果
const YB_GDS_ADD_TO_CART_C = 'YB_GDS_ADD_TO_CART_C';       //商品详情页-加入购物车
const YB_REGISTER_SUCCESS = 'YB_REGISTER_SUCCESS';       //注册成功
const YB_INVITE_C = 'YB_INVITE_C';       //邀请好友
const YB_INVITE_PICTURE_C = 'YB_INVITE_PICTURE_C';       //点击邀请好友参团“生成图片发朋友圈”
const YB_INVITE_PICTURE_SAVE_C = 'YB_INVITE_PICTURE_SAVE_C';       //点击“保存图片分享到朋友圈”
const YB_SHARE_PICTURE_RESULT_L = 'YB_SHARE_PICTURE_RESULT_L';       //选择生成图片发朋友圈成功时
const YB_INVITE_FRIEND_C = 'YB_INVITE_FRIEND_C';       //邀请好友参团“分享给微信好友”
const YB_ASSIST_C = 'YB_ASSIST_C';//点击红包助力页面中的助力按钮时
const YB_ASSIST_LAUNCH_C = 'YB_ASSIST_LAUNCH_C';//点击红包助力页面中的发起成功时
const YB_SHARE_RESULT_L = 'YB_SHARE_RESULT_L';       //分享
const YB_AWAKE_MP = 'YB_AWAKE_MP'; //渠道落地页
const YB_MY_GRP_BUY_INV_C = 'YB_MY_GRP_BUY_INV_C'; //订单列表点击“拼团详情”
const YB_MY_GRP_BUY ='YB_MY_GRP_BUY';  //个人中心中我的拼团
const YB_SERVICE_PUSH = 'YB_SERVICE_PUSH'; //推送服务
const YB_GRP_BUY_OPEN_C = 'YB_GRP_BUY_OPEN_C'; //去开团
const YB_GRP_BUY_REOPEN_C = 'YB_GRP_BUY_REOPEN_C'; //重新开团
const YB_GRP_BUY_DT_TOG_C = 'YB_GRP_BUY_DT_TOG_C'; //立即购买
const YB_GRP_BUY_DT_SEP_C = 'YB_GRP_BUY_DT_SEP_C'; //单独购买
const YB_COLLECTION_C = 'YB_COLLECTION_C';//点击商品详情页中的收藏按钮时
const YB_MY_FAV = 'YB_MY_FAV';//点击我的页面中的"商品收藏"时
const YB_GDS_BRAND_SHOP_C = 'YB_GDS_BRAND_SHOP_C';//商品详情点击店铺

const YB_BRAND_TAB_C = 'YB_BRAND_TAB_C';//点击品牌分类页的TAB时
const YB_BRAND_FLR_C = 'YB_BRAND_FLR_C';//点击品牌分类页各楼层时
const YB_SEARCH_C = 'YB_SEARCH_C';//点击搜索框时
const YB_SCAN_CODE_SUCCESS = 'YB_SCAN_CODE_SUCCESS';//扫描成功时
const YB_SCAN_CODE_C = 'YB_SCAN_CODE_C';//首页点击扫一扫图标

const YB_MAIN_STROLL_TAB_C = 'YB_MAIN_STROLL_TAB_C';//点击逛楼层tab时

const YB_TO_OPEN_APP_C = 'YB_TO_OPEN_APP_C';//商品详情页&店铺页
const YB_OPEN_APP_RESULT_L = 'YB_OPEN_APP_RESULT_L';//唤起app结果
const YB_SHARE_PROMOTION_C = 'YB_SHARE_PROMOTION_C';//点击创建推广页“分享链接/生成图片/复制口令”时
const YB_MAIN_POP_UP_C = 'YB_MAIN_POP_UP_C';//点击首页弹框

const YB_GROUP_BUY_BANNER_C = 'YB_GROUP_BUY_BANNER_C';//拼团购列表页banner位


let logEvent = function(eventId, data,appData) {
  let app = appData ? appData : getApp();
  let ln;//语言
  let os;//系统类型
  let dm;//设备型号
  let re;//屏幕大小
  let osv;//系统版本
  let ak = 'yohobuy_mp';//
  let net = '0';
  let ts = new Date().getTime() + '';
  //用户id
  let uid = app && app.globalData && app.globalData.userInfo && app.globalData.userInfo.uid ? app.globalData.userInfo.uid : '';
  //设备id
  let udid = app && app.globalData && app.globalData.udid ? app.globalData.udid : '';
  //会话id
  let sid = app && app.globalData && app.globalData.sid ? app.globalData.sid : '';
  let cid = app && app.globalData && app.globalData.cid ? app.globalData.cid : '';
  
  let open_id = app && app.globalData && app.globalData.openID ? app.globalData.openID : getYHStorageSync('openID','analytics');
  let union_id = app && app.globalData && app.globalData.WXUnion_ID ? app.globalData.WXUnion_ID : getYHStorageSync('unionID','analytics');
  let ch = app && app.globalData && app.globalData.ch ? app.globalData.ch : '';

  wx.getSystemInfo({
    success: function (res) {
      //返回设备信息
      dm = res.model;
      ln = res.language;
      os = res.platform;
      osv = res.system;
      re = res.screenWidth+'*'+res.screenHeight;
    },
    complete: function () {
      wx.getNetworkType({
        success: function (res) {
          // 返回网络类型, 有效值:
          // wifi/2g/3g/4g/unknown(Android下不常见的网络类型)/none(无网络)
          var networkType = res.networkType
          if (networkType === 'wifi') {
            net = '1';
          } else if (networkType === '2g') {
            net = '2';
          } else if (networkType === '3g') {
            net = '3';
          } else if (networkType === '4g') {
            net = '4';
          } else {
            net = '0';
          }
        },
        complete: function () {
          let union_type = app.getUnion_type();

          let statusParam = { 'net': net, 'ln': ln };
          let deviceParam = { 'res': re, 'osv': osv, 'os': os, 'ak': ak, 'dm': dm, 'udid': udid, 'ch': union_type != '' ? union_type+"" : ch+""};
          let userParam = data;
          userParam.C_ID = cid;
          userParam.UNION_ID = union_id;
          let eventParam = [{ 'param': userParam, 'ts': ts, 'op': eventId, 'uid': uid, 'sid': sid}]
          let parameters = { 'status': statusParam, 'device': deviceParam, 'events': eventParam }
          // console.log(parameters)

          UPLOAD_LOG(LOG_EVENT_HOST, parameters)
            .then(function (data) {
            //  console.log(data)
            })
            .catch(function (error) {
              // console.log(error)

            });
        }
      })
    }
  })

}

module.exports = {
  logEvent, 
  YB_ENTER_FOREGROUND, 
  YB_ENTER_BACKGROUND, 
  YB_LAUNCH_APP,
  YB_EXIT_APP,
  YB_PAGE_OPEN_L,
  YB_MAIN_TAB_C,
  YB_MAIN_EVENT,
  YB_MY_LOGIN,
  YB_GDS_DT_BILL,
  YB_SC_ORD,
  YB_SC_PAY_RES,
  YB_GDS_ADD_TO_CART_C,
  YB_CATEGORY_FL,
  YB_REGISTER_SUCCESS,
  YB_INVITE_C,
  YB_INVITE_PICTURE_C,
  YB_INVITE_PICTURE_SAVE_C,
  YB_SHARE_PICTURE_RESULT_L,
  YB_INVITE_FRIEND_C,
  YB_ASSIST_C,
  YB_ASSIST_LAUNCH_C,
  YB_SHARE_RESULT_L,
  YB_AWAKE_MP,
  YB_MY_GRP_BUY_INV_C,
  YB_MY_GRP_BUY, 
  YB_SERVICE_PUSH, 
  YB_GRP_BUY_OPEN_C, 
  YB_GRP_BUY_REOPEN_C, 
  YB_GRP_BUY_DT_TOG_C, 
  YB_GRP_BUY_DT_SEP_C, 
  YB_COLLECTION_C,
  YB_MY_FAV,
  YB_BRAND_TAB_C,
  YB_BRAND_FLR_C,
  YB_SEARCH_C,
  YB_SCAN_CODE_SUCCESS,
  YB_GDS_BRAND_SHOP_C,
  YB_SCAN_CODE_C,
  YB_MAIN_STROLL_TAB_C,
  YB_TO_OPEN_APP_C,
  YB_OPEN_APP_RESULT_L,
  YB_SHARE_PROMOTION_C,
  YB_MAIN_POP_UP_C,
  YB_GROUP_BUY_BANNER_C
}