Browse Source

视频播放埋点

jwyu 2 years ago
parent
commit
7b94a7bd7f
2 changed files with 33 additions and 3 deletions
  1. 9 0
      api/video.js
  2. 24 3
      pages/video/videoList.vue

+ 9 - 0
api/video.js

@@ -12,4 +12,13 @@ import { httpGet, httpPost } from "@/utils/request.js";
  */
 export const apiVideoList=params=>{
     return httpGet('/community/video/list',params)
+}
+
+/**
+ * 视频播放埋点
+ * @param video_id
+ * @param source_agent 来源平台:1:小程序、2:小程序(pc)、3:公众号、4:官网web(pc)
+ */
+export const apiVideoPlayLog=params=>{
+    return httpPost('/community/video/play_log',{...params,source_agent:1})
 }

+ 24 - 3
pages/video/videoList.vue

@@ -42,6 +42,7 @@
                     :src="item.video_url"
                     enable-play-gesture
                     :id="item.community_video_id"
+                    @ended="curVideoId=0"
                     v-if="item.community_video_id==curVideoId"
                 ></video>
                 <image @click="handelClickPlay(item)" v-else class="poster" :src="item.cover_img_url" mode="aspectFill" lazy-load/>
@@ -92,8 +93,9 @@
     
 </template>
 <script>
-import {apiVideoList} from '@/api/video'
+import {apiVideoList,apiVideoPlayLog} from '@/api/video'
 import {apiOptionList} from '@/api/question'
+import {apiGetSceneToParams} from '@/api/common'
 export default {
     data() {
         return {
@@ -112,8 +114,7 @@ export default {
         }
     },
     onLoad(options){
-        this.videoId=options.videoId||0
-        this.getList()
+        this.init(options)
         this.getPermissionList()
     },
     onHide(){
@@ -148,11 +149,25 @@ export default {
         }, 1500)
     },
     methods: {
+        async init(options){
+            if(options.scene){
+                const resScene=await apiGetSceneToParams({scene_key:options.scene})
+                if(resScene.code===200){
+                    const obj=JSON.parse(resScene.data)
+                    this.videoId=obj.videoId||0
+                }
+            }else{
+                this.videoId=options.videoId||0
+            }
+            this.getList()
+        },
+
         goSearchPage(){
             uni.navigateTo({
                 url: '/pages/video/videoSearch',
             });
         },
+
         change(e){
             this.active=e.detail
         },
@@ -200,6 +215,12 @@ export default {
 
         handelClickPlay(item){
             this.curVideoId=item.community_video_id
+            // 记录播放
+            apiVideoPlayLog({video_id:Number(item.community_video_id)}).then(res=>{
+                if(res.code===200){
+                    console.log('视频埋点成功');
+                }
+            })
         }
     },
 }