src/app/components/ATIAnalytics/params/genericPage/buildParams.ts

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
import { LIBRARY_VERSION } from '../../../../lib/analyticsUtils';
import { buildATIPageTrackPath } from '../../atiUrl';
import { ATIDataWithContexts } from '../../types';

export const buildPageATIParams = ({
  atiData,
  requestContext,
  serviceContext,
}: ATIDataWithContexts) => {
  const { isUK, origin, platform, previousPath, statsDestination } =
    requestContext;
  const { atiAnalyticsAppName, atiAnalyticsProducerId, lang, service } =
    serviceContext;
  const {
    campaigns,
    categoryName,
    contentId,
    contentType,
    language,
    ldpThingIds,
    ldpThingLabels,
    nationsProducer,
    pageIdentifier,
    pageTitle,
    producerId,
    timePublished,
    timeUpdated,
  } = atiData;

  return {
    appName: atiAnalyticsAppName,
    campaigns,
    categoryName,
    contentId,
    contentType,
    isUK,
    language: language || lang,
    ldpThingIds,
    ldpThingLabels,
    libraryVersion: LIBRARY_VERSION,
    nationsProducer,
    origin,
    pageIdentifier,
    pageTitle,
    platform,
    previousPath,
    producerId: producerId || atiAnalyticsProducerId,
    service,
    statsDestination,
    timePublished,
    timeUpdated,
  };
};

export const buildPageATIUrl = ({
  atiData,
  requestContext,
  serviceContext,
}: ATIDataWithContexts) =>
  buildATIPageTrackPath(
    buildPageATIParams({ atiData, requestContext, serviceContext }),
  );