infomationCardClick.ets 3.8 KB
import { TrackingContent, TrackConstants, ParamType } from 'wdTracking';
import { CompDTO, ContentDTO } from 'wdBean';
import { Logger } from 'wdKit';

export class InfomationCardClick {

  private static getLiveState(contentDTO: ContentDTO) {
    if (contentDTO?.liveInfo?.liveState === 'wait') {
      return 'liveSubscribe'
    } else if (contentDTO?.liveInfo?.liveState === 'running') {
      return 'livePlaying'
    } else if (contentDTO?.liveInfo?.liveState === 'end') {
      return 'liveEnd'
    } else {
      return ''
    }
  }

  private static getSummaryType(objectType: string) {
    let summaryType: string = ''
    switch(objectType) {
      case '2':
        summaryType = 'liveTopic';
        break;
      case '8':
        summaryType = 'articleTopic';
        break;
      case '13':
        summaryType = 'audioTopic';
        break;
    // case '':
    //   summaryType = 'talkTopic';
    //   break;
    // case '':
    //   summaryType = 'morningAndEveningNewsTopic';
    //   break;
    // case '':
    //   summaryType = 'timeAxisTopic';
    //   break;
      default:
        summaryType = '';
        break;
    }
    return summaryType;
  }

  public static track(
    compDTO: CompDTO,
    contentDTO: ContentDTO,
    pageId: string,
    pageName: string,
    action = 'detailPageShow', // like, commentClick, follow
    bl = false,
    followUserId = '',
    followUserName = ''
  ): void {
    try {
      const extParams: ParamType = {
        'action': action,
        'shareChannel': '',
        'duration': 0,
        'contentName': contentDTO.newsTitle,
        'contentType': contentDTO.objectType,
        // 'contentClassify': '' // 废除
        'contentId': contentDTO.objectId,
        // 'compId': contentDTO.relId,
        'contentStyle': contentDTO.appStyle,
        'liveType': InfomationCardClick.getLiveState(contentDTO),
        'channelSourceId': contentDTO.channelId,
        'contentShowChannelId': contentDTO.channelId,
        // 'contentShowChannelName': '',
        'linkUrl': contentDTO.linkUrl,
        'regionName': 2, // 信息流:2
        'componentType': compDTO.compStyle,
        'sceneId': contentDTO.sceneId,
        'subSceneId': contentDTO.subSceneId,
        'cnsTraceId': contentDTO.cnsTraceId,
        'cardItemId': compDTO.cardItemId,
        'itemId': compDTO.itemId || contentDTO.itemId,
        'expIds': compDTO.expIds || contentDTO.expIds
      }
      if (contentDTO.objectType === '5') {
        extParams['summaryId'] = contentDTO.objectId;
        extParams['summaryType'] = InfomationCardClick.getSummaryType(contentDTO.objectType);
        extParams['specialLink'] = contentDTO.linkUrl;
      }
      if (contentDTO.objectType === '2') {
        extParams['liveStreamType'] = contentDTO?.liveInfo.vrType === 0 ? 1 : 2;
        extParams['vliveId'] = contentDTO.objectId;
        extParams['vliveName'] = contentDTO.newsTitle;
        extParams['liveMode'] = 1;
      }
      if (contentDTO.rmhPlatform === 1) {
        extParams['saAuthorName'] = contentDTO.rmhInfo?.rmhName;
        extParams['saAuthorId'] = contentDTO.rmhInfo?.rmhId;
      } else if (contentDTO.source) {
        extParams['saAuthorName'] = contentDTO.source;
      }
      Logger.debug('InfomationCardClick-params:', JSON.stringify(extParams))
      if (action === 'detailPageShow') {
        TrackingContent.common(TrackConstants.EventType.Click, pageId, pageName, extParams);
      } else if (action === 'like') {
        TrackingContent.like(bl, pageId, pageName, extParams);
      } else if (action === 'commentClick') {
        TrackingContent.commentClick(pageId, pageName, extParams);
      } else if (action === 'follow') {
        TrackingContent.follow(bl, followUserId, followUserName, pageId, pageName, extParams)
      }
    } catch (err) {
      Logger.error('InfomationCardClick-err', JSON.stringify(err))
    }
  }
}