@liiift-studio/sanity-visitor-insights 0.45.0 → 0.46.0

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.
package/dist/server.js CHANGED
@@ -1495,7 +1495,11 @@ async function measurementHealth(input) {
1495
1495
  ordersByDate = counts.byDate;
1496
1496
  ordersMeasured = true;
1497
1497
  revenueByDate = counts.revenueByDate;
1498
- revenue = counts.revenue === null ? unavailable("not_applicable", "No order total field is configured for this site") : ok(counts.revenue);
1498
+ revenue = counts.revenue === null ? unavailable("not_applicable", "No order total field is configured for this site") : counts.ordersMissingTotal > 0 ? partial(
1499
+ counts.revenue,
1500
+ range.start,
1501
+ `Covers ${counts.total - counts.ordersMissingTotal} of ${counts.total} counted orders \u2014 the rest carry no amount, so real revenue is higher.`
1502
+ ) : ok(counts.revenue);
1499
1503
  currency = config.orders.currency ?? null;
1500
1504
  orderStatuses = counts.byStatus;
1501
1505
  if (counts.ordersMissingTotal > 0) {
@@ -1726,6 +1730,7 @@ async function acquisition(input) {
1726
1730
  const purchasesBySource = /* @__PURE__ */ new Map();
1727
1731
  const revenueBySource = /* @__PURE__ */ new Map();
1728
1732
  let purchasesAvailable = false;
1733
+ let purchasesTruncated = false;
1729
1734
  try {
1730
1735
  const purchaseReport = await ga4.runReport({
1731
1736
  dimensions: [
@@ -1761,7 +1766,8 @@ async function acquisition(input) {
1761
1766
  notices?.push("GA4 answered the purchase-attribution query from a sample, so the revenue split is approximate even before its own coverage is considered.");
1762
1767
  }
1763
1768
  if (purchaseReport.thresholded || purchaseReport.rowCount > purchaseReport.rows.length) {
1764
- notices?.push("GA4 withheld or truncated some attributed purchases, so the revenue split does not account for every sale it tracked.");
1769
+ purchasesTruncated = true;
1770
+ notices?.push("GA4 withheld or truncated some attributed purchases, so revenue cannot be split by channel for this range. Choose a shorter range or a narrower window.");
1765
1771
  }
1766
1772
  for (const row of purchaseReport.rows) {
1767
1773
  const count2 = row.metrics[0];
@@ -1789,7 +1795,7 @@ async function acquisition(input) {
1789
1795
  const MIN_COVERAGE = 0.25;
1790
1796
  const MAX_COVERAGE = 1.2;
1791
1797
  const coverage = actuals?.orders != null && actuals.orders > 0 ? trackedPurchases / actuals.orders : null;
1792
- const splitIsSound = trackedPurchases >= MIN_TRACKED_PURCHASES && trackedRevenue > 0 && coverage !== null && coverage >= MIN_COVERAGE && coverage <= MAX_COVERAGE;
1798
+ const splitIsSound = !purchasesTruncated && trackedPurchases >= MIN_TRACKED_PURCHASES && trackedRevenue > 0 && coverage !== null && coverage >= MIN_COVERAGE && coverage <= MAX_COVERAGE;
1793
1799
  if (splitIsSound) {
1794
1800
  for (const row of rows) {
1795
1801
  const money2 = row.trackedRevenue;