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

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): void {
    try {
      const extParams: ParamType = {
        'action': 'detailPageShow',
        '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;
      }
      console.log('InfomationCardClick-params:', JSON.stringify(extParams))
      TrackingContent.common(TrackConstants.EventType.Click, pageId, pageName, extParams)
    } catch (err) {
      console.log('InfomationCardClick-err', JSON.stringify(err))
    }
  }
}