cmSrsMixins.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // 统计Ross 用户
  2. import Vue from 'vue'
  3. import { includeList , roosConfig } from './router.config.js' // 配置信息
  4. // 参数
  5. const defaultParams = {
  6. accessClient: 1, // 来源 0 网站 1 小程序
  7. pagePath: '', //页面路径
  8. accessDuration: 0, //浏览时长初始值为 0
  9. pageType: '', //页面类型
  10. pageLabel: '', //页面标签
  11. userId: 0, //用户Id
  12. productId: 0, //商品Id
  13. behaviorType: 1 // 统计类型
  14. }
  15. const cmSrsMixins = {
  16. data() {
  17. return {
  18. handleProsId: 0,
  19. handleShopId: 0,
  20. handleProsKey: '',
  21. handleShopKey: '',
  22. showRossHtml: false,
  23. isDisabled: true
  24. }
  25. },
  26. methods: {
  27. checkedIsRossSet() {
  28. if (roosConfig.productIdList.includes(this.handleProsId * 1) ||
  29. roosConfig.shopIds.includes(this.handleShopId * 1) ||
  30. roosConfig.keyWords.includes(this.handleProsKey) ||
  31. roosConfig.shopKeyWords.includes(this.handleShopKey)
  32. ) {
  33. uni.setStorageSync('behaviorType', 2)
  34. this.setingSysParams()
  35. if (!this.hasLogin) {
  36. this.userInformationIsClick()
  37. }
  38. }else{
  39. this.setingSysParams()
  40. }
  41. },
  42. // 接口参数设置
  43. async setingSysParams(){
  44. const sysParams = Object.assign({}, defaultParams)
  45. const userSync = uni.getStorageSync('userInfo')
  46. const route = this.getPath()
  47. const pageData = this.isIncludeType(route.path)
  48. // 协销不记录
  49. if (userSync.userIdentity === 1) return
  50. // 参数设置
  51. sysParams.userId = userSync.userId ? userSync.userId : 0
  52. sysParams.pagePath = route.fullPath
  53. sysParams.pageType = pageData ? pageData.pageType : ''
  54. sysParams.behaviorType = uni.getStorageSync('behaviorType') ? uni.getStorageSync('behaviorType') : 1
  55. // 根据path获取不同的参数
  56. if (route.path === '/pages/goods/product') {
  57. sysParams.productId = route.query.id ? route.query.id : 0
  58. sysParams.pageLabel = uni.getStorageSync('productLabel')
  59. } else {
  60. sysParams.pageLabel = uni.getStorageSync('pageLabel') ? uni.getStorageSync('pageLabel') : pageData.pageLabel
  61. }
  62. console.log('记录路径:', sysParams.pagePath, '标签:', sysParams.pageLabel)
  63. // 统计接口调用
  64. this.userRecordStatistics(sysParams)
  65. console.log('---用户行为轨迹记录成功---')
  66. },
  67. userRecordStatistics(params){
  68. // 上送
  69. this.UserService.userRecordStatistics(params)
  70. .then(response => {
  71. console.log('---用户行为轨迹记录成功---')
  72. uni.removeStorageSync('pageLabel')
  73. uni.removeStorageSync('behaviorType')
  74. })
  75. .catch(error => {
  76. console.log('---用户行为轨迹记录失败---')
  77. })
  78. },
  79. userInformationIsClick() {
  80. // 查看用户是否有过弹框游客当天是否有过弹框
  81. this.UserService.userInformationIsClick()
  82. .then(response => {
  83. if (response.data) {
  84. setTimeout(() => {
  85. this.showRossHtml = true
  86. }, 5000)
  87. }
  88. })
  89. .catch(error => {
  90. console.log('查询失败~')
  91. })
  92. },
  93. isIncludeType(url){
  94. // 校验返回页面类型
  95. if (!url) return false
  96. return includeList.find(item => url === item.url)
  97. },
  98. getPath(){
  99. // 获取路径
  100. const pages = getCurrentPages()
  101. const len = pages.length
  102. const page = pages[len - 1]
  103. const route = { path: '/' + page.route, fullPath: page.$page.fullPath, query: page.options, meta: {} }
  104. return route
  105. }
  106. }
  107. }
  108. export default cmSrsMixins