@eric-emg/symphiq-components 1.2.187 → 1.2.189

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -57279,42 +57279,39 @@ function calculateMetricTargetsFromRevenue(revenueTarget, priorYearRevenue, funn
57279
57279
  const bRelated = b.relatedInd ?? 999;
57280
57280
  return aRelated - bRelated;
57281
57281
  });
57282
- const funnelStages = new Set();
57283
- const relatedMetricsPerStage = new Map();
57284
- sortedFunnelMetrics.forEach((fm) => {
57285
- const funnelInd = fm.funnelInd ?? 0;
57286
- funnelStages.add(funnelInd);
57287
- const isFunnelStage = fm.funnelMetric === fm.relatedMetric;
57288
- if (!isFunnelStage) {
57289
- relatedMetricsPerStage.set(funnelInd, (relatedMetricsPerStage.get(funnelInd) || 0) + 1);
57282
+ const funnelStages = getUniqueFunnelStages(sortedFunnelMetrics);
57283
+ const numFunnelStages = funnelStages.length;
57284
+ const revenueIncreaseFactor = revenueTarget / priorYearRevenue;
57285
+ const perStageFactor = Math.pow(revenueIncreaseFactor, 1 / numFunnelStages);
57286
+ const funnelStageMetrics = new Map();
57287
+ sortedFunnelMetrics.forEach(fm => {
57288
+ if (fm.funnelMetric) {
57289
+ if (!funnelStageMetrics.has(fm.funnelMetric)) {
57290
+ funnelStageMetrics.set(fm.funnelMetric, []);
57291
+ }
57292
+ funnelStageMetrics.get(fm.funnelMetric).push(fm);
57290
57293
  }
57291
57294
  });
57292
- const numFunnelStages = funnelStages.size;
57293
- const revenueMultiplier = 1 + revenuePercentageIncrease / 100;
57294
- const perStageMultiplier = Math.pow(revenueMultiplier, 1 / numFunnelStages);
57295
- const funnelStagePercentageIncrease = (perStageMultiplier - 1) * 100;
57295
+ const stagePercentageIncrease = (perStageFactor - 1) * 100;
57296
57296
  sortedFunnelMetrics.forEach((funnelMetric) => {
57297
57297
  const metric = funnelMetric.relatedMetric;
57298
57298
  if (!metric)
57299
57299
  return;
57300
57300
  const currentValue = baselineValues.get(metric) || 0;
57301
57301
  const isFunnelStage = funnelMetric.funnelMetric === metric;
57302
- const funnelInd = funnelMetric.funnelInd ?? 0;
57303
- const isBounceRate = metric === MetricEnum.BOUNCE_RATE;
57304
57302
  let percentageIncrease;
57305
57303
  let targetValue;
57306
- if (isBounceRate) {
57307
- percentageIncrease = -funnelStagePercentageIncrease;
57304
+ if (metric === MetricEnum.BOUNCE_RATE) {
57305
+ percentageIncrease = -stagePercentageIncrease;
57308
57306
  targetValue = currentValue * (1 + percentageIncrease / 100);
57309
57307
  }
57310
- else if (isFunnelStage) {
57311
- percentageIncrease = funnelStagePercentageIncrease;
57312
- targetValue = currentValue * (1 + percentageIncrease / 100);
57308
+ else if (isDerivedMetric(metric)) {
57309
+ percentageIncrease = 0;
57310
+ targetValue = currentValue;
57313
57311
  }
57314
57312
  else {
57315
- const numRelatedInStage = relatedMetricsPerStage.get(funnelInd) || 1;
57316
- percentageIncrease = funnelStagePercentageIncrease / numRelatedInStage;
57317
- targetValue = currentValue * (1 + percentageIncrease / 100);
57313
+ percentageIncrease = stagePercentageIncrease;
57314
+ targetValue = currentValue * perStageFactor;
57318
57315
  }
57319
57316
  metricCalculations.push({
57320
57317
  metric,
@@ -57334,6 +57331,25 @@ function calculateMetricTargetsFromRevenue(revenueTarget, priorYearRevenue, funn
57334
57331
  metricCalculations
57335
57332
  };
57336
57333
  }
57334
+ function getUniqueFunnelStages(funnelMetrics) {
57335
+ const stages = [];
57336
+ const seen = new Set();
57337
+ funnelMetrics.forEach(fm => {
57338
+ if (fm.funnelMetric && fm.funnelMetric === fm.relatedMetric && !seen.has(fm.funnelMetric)) {
57339
+ seen.add(fm.funnelMetric);
57340
+ stages.push(fm.funnelMetric);
57341
+ }
57342
+ });
57343
+ return stages;
57344
+ }
57345
+ const DERIVED_METRICS = new Set([
57346
+ MetricEnum.REVENUE_PER_PRODUCT_VIEW,
57347
+ MetricEnum.REVENUE_PER_ADD_TO_CART,
57348
+ MetricEnum.REVENUE_PER_CHECKOUT
57349
+ ]);
57350
+ function isDerivedMetric(metric) {
57351
+ return DERIVED_METRICS.has(metric);
57352
+ }
57337
57353
  function generateTargetsFromCalculations(shopId, calculations) {
57338
57354
  const startDate = getCurrentYearStart();
57339
57355
  const endDate = getCurrentYearEnd();