@liiift-studio/sanity-visitor-insights 0.41.0 → 0.43.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 +8 -6
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +8 -6
- package/dist/server.mjs.map +1 -1
- package/package.json +1 -1
- package/src/core/core.test.ts +29 -0
- package/src/server/cache.test.ts +35 -0
- package/src/server/createHandler.ts +20 -13
- package/src/server/reports/acquisition.ts +8 -1
- package/src/server/reports/reports.test.ts +153 -0
package/dist/server.js
CHANGED
|
@@ -1751,7 +1751,7 @@ async function acquisition(input) {
|
|
|
1751
1751
|
row.apportionedRevenue = actuals?.revenue != null ? actuals.revenue * row.revenueShare : null;
|
|
1752
1752
|
}
|
|
1753
1753
|
} else if (purchasesAvailable) {
|
|
1754
|
-
const why = trackedPurchases > 0 && trackedRevenue <= 0 ? `GA4 attributed ${trackedPurchases} purchase${trackedPurchases === 1 ? "" : "s"} to a source but recorded no revenue against them, so there is no shape to split your takings by. The purchase event is firing without its value.` : coverage
|
|
1754
|
+
const why = trackedPurchases > 0 && trackedRevenue <= 0 ? `GA4 attributed ${trackedPurchases} purchase${trackedPurchases === 1 ? "" : "s"} to a source but recorded no revenue against them, so there is no shape to split your takings by. The purchase event is firing without its value.` : coverage === null ? "Your orders could not be read for this range, so there is nothing to check GA4\u2019s attribution against and revenue cannot be split by channel." : coverage > MAX_COVERAGE ? `GA4 attributed ${trackedPurchases} purchases to a source but you only have ${actuals?.orders} orders in this range. It is counting sales that did not happen \u2014 usually a purchase tag firing twice \u2014 so its split cannot be trusted.` : trackedPurchases === 0 ? "GA4 attributed no purchases at all to a source in this range, so revenue cannot be split by channel. That usually means the purchase event is not firing, or is firing without its source." : coverage !== null && coverage < MIN_COVERAGE ? `GA4 attributed ${trackedPurchases} of your ${actuals?.orders} orders to a source in this range \u2014 too small a sample of your own sales to divide revenue by.` : `GA4 attributed only ${trackedPurchases} purchase${trackedPurchases === 1 ? "" : "s"} to a source in this range, which is too few to split revenue by channel. Choose a longer range.`;
|
|
1755
1755
|
notices?.push(why);
|
|
1756
1756
|
}
|
|
1757
1757
|
const shownPurchases = rows.reduce((total, row) => total + (row.purchases ?? 0), 0);
|
|
@@ -2542,7 +2542,7 @@ function createVisitorInsightsHandler(options) {
|
|
|
2542
2542
|
} : {}
|
|
2543
2543
|
};
|
|
2544
2544
|
}, (envelope2) => {
|
|
2545
|
-
return sourceFailed(envelope2) ? Math.min(ttl, 2e4) : ttl;
|
|
2545
|
+
return sourceFailed(envelope2.data) ? Math.min(ttl, 2e4) : ttl;
|
|
2546
2546
|
});
|
|
2547
2547
|
res.status(200).json(envelope);
|
|
2548
2548
|
} catch (e) {
|
|
@@ -2551,10 +2551,12 @@ function createVisitorInsightsHandler(options) {
|
|
|
2551
2551
|
}
|
|
2552
2552
|
};
|
|
2553
2553
|
}
|
|
2554
|
-
function sourceFailed(
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2554
|
+
function sourceFailed(value, depth = 4) {
|
|
2555
|
+
if (!value || typeof value !== "object" || depth <= 0) return false;
|
|
2556
|
+
const candidate = value;
|
|
2557
|
+
if (candidate.status === "unavailable" && candidate.reason === "source_error") return true;
|
|
2558
|
+
const children = Array.isArray(value) ? value : Object.values(value);
|
|
2559
|
+
return children.some((child) => sourceFailed(child, depth - 1));
|
|
2558
2560
|
}
|
|
2559
2561
|
async function runReport(report, ctx) {
|
|
2560
2562
|
const { config, range, ga4, vercel, sanity, mailchimp, notices } = ctx;
|