列表数据滚动曝光埋点和点击埋点

21 篇文章 0 订阅

使用的IntersectionObserver API

<template>
  <div class="job_list" v-if="showList.length > 0">
    <div class="title">列表title</div>
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="我们是有底线的~"
      loading-text="内容加载中"
      :error.sync="error"
      error-text="请求失败,点击重新加载"
      offset="160"
      @load="getList"
      v-if="showList.length > 0"
    >
      <ListCard
        v-for="(item, index) in showList"
        :key="index + 'likejobList'"
        :listItem="item"
        textType="corporateName"
        class="job_list_card"
        :data-jobid="item.jobId"
        :data-ojobid="oJobId"
        :data-impid="item.point.impid"
        :data-transinfo="JSON.stringify(item.point.algoMeta.transInfo)"
        @click.native="clickCard(oJobId, item.jobId, item.point.impid, item.point.algoMeta.transInfo)"
      ></ListCard>
    </van-list>
  </div>
</template>

<script>
import ListCard from './ListCard.vue'
import { List } from 'vant'
import { likeListDsLog, clickLikeListDsLog } from '../api/dslogList'
export default {
  name: 'likeList',
  components: {
    ListCard,
    [List.name]: List,
  },
  props: {
    companyList: {
      type: Array,
    },
    jobId: {
      type: [Number,String]
    }
  },
  watch: {
    companyList: {
      handler(newVal) {
        this.allList = newVal
        this.getList('now')
      },
      immediate: true,
      deep: true,
    },
    jobId: {
      handler(newVal) {
        this.oJobId = newVal
      },
      immediate: true,
    }
  },
  data() {
    return {
      oJobId: '',
      allList: [],
      showList: [],
      // 列表
      loading: false,
      finished: false,
      error: false,
      size: 5,
      target: 0,
    }
  },
  methods: {
    getList(tag) {
      let allarr = JSON.parse(JSON.stringify(this.allList))
      let arr = this.showList
      if(tag && allarr.length < 5 && allarr.length != 0){
        this.showList = allarr
        this.loading = false
        this.finished = true
        // 埋点-列表曝光
        this.initElementSensor()
        return
      }
      if (tag) {
        arr = arr.concat(
          allarr.slice(this.target * this.size, (this.target + 1) * this.size)
        )
        this.showList = arr
        this.loading = false
        this.target++
        if (arr.length >= this.allList.length || arr.length >= 20) {
          this.finished = true
        }
        // 埋点-列表曝光
        this.initElementSensor()
        return
      }
      setTimeout(() => {
        arr = arr.concat(
          allarr.slice(this.target * this.size, (this.target + 1) * this.size)
        )
        this.showList = arr
        this.loading = false
        this.target++
        if (arr.length >= this.allList.length || arr.length >= 20) {
          this.finished = true
        }
      }, 1000)
    },
    clickCard(jobid, ojobid, impid, transinfo){
      clickLikeListDsLog(jobid, ojobid, impid, transinfo)
    },
    // 列表曝光
    initElementSensor () {
      this.$nextTick(() => {
        const obserRef = new IntersectionObserver((entries) => {
          entries.forEach((v) => {
            const {jobid, ojobid, impid, transinfo} = v.target.dataset;//自定义
            if (v.isIntersecting) {
              //v.isIntersecting=true的时候表示露出
              likeListDsLog(jobid, ojobid, impid, transinfo)
            }
          });
        },{
          threshold: [1]
        });
        setTimeout(() => {
          const items = document.querySelectorAll(".job_list_card") || [];
          items.forEach((item) => {
            obserRef.observe(item);
          });
        }, 0);
      });
    },
  },
}
</script>

<style lang="scss" scoped>
.job_list {
  background-color: #ffffff;
  overflow: hidden;
  .title {
    font-size: 18px;
    font-weight: bold;
    color: #333333;
    padding: 20px 0 0 16px;
  }
}
</style>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值