@levi-gemcommerce/analytics 1.0.0-dev.39 → 1.0.0-dev.40
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/esm/components/CardPathAnalysis/helpers/pathAnalysis.d.ts +1 -1
- package/dist/esm/gemxql.js +1 -1
- package/dist/esm/gemxql.mjs +1 -1
- package/dist/esm/index.js +337 -104
- package/dist/esm/index.mjs +337 -104
- package/dist/esm/modules/analytics/constants/index.d.ts +15 -0
- package/dist/esm/modules/analytics/index.d.ts +2 -13
- package/dist/esm/modules/analytics/metric.d.ts +26 -0
- package/dist/esm/modules/analytics/types/index.d.ts +41 -0
- package/dist/esm/modules/analytics/types.d.ts +18 -0
- package/dist/esm/modules/analytics/utils/formatMetric.d.ts +8 -0
- package/dist/esm/modules/analytics/utils/getPAMetricValue.d.ts +3 -0
- package/dist/esm/modules/analytics/utils/index.d.ts +3 -0
- package/dist/esm/modules/analytics/utils/metric.d.ts +26 -0
- package/dist/esm/modules/page-analytic/index.d.ts +6 -4
- package/dist/esm/modules/page-analytic/modules/analytic/index.d.ts +3 -5
- package/dist/esm/providers/ConvertMoneyProvider.d.ts +1 -1
- package/dist/esm/types/metric.d.ts +3 -0
- package/dist/umd/esm/components/CardPathAnalysis/helpers/pathAnalysis.d.ts +1 -1
- package/dist/umd/esm/modules/analytics/constants/index.d.ts +15 -0
- package/dist/umd/esm/modules/analytics/index.d.ts +2 -13
- package/dist/umd/esm/modules/analytics/types/index.d.ts +41 -0
- package/dist/umd/esm/modules/analytics/utils/formatMetric.d.ts +8 -0
- package/dist/umd/esm/modules/analytics/utils/getPAMetricValue.d.ts +3 -0
- package/dist/umd/esm/modules/analytics/utils/index.d.ts +3 -0
- package/dist/umd/esm/modules/analytics/utils/metric.d.ts +26 -0
- package/dist/umd/esm/providers/ConvertMoneyProvider.d.ts +1 -1
- package/dist/umd/esm/types/metric.d.ts +3 -0
- package/dist/umd/gemxql.js +1 -1
- package/dist/umd/index.js +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IGetTextPrice } from '@/
|
|
1
|
+
import type { IGetTextPrice } from '@/core/gemxql';
|
|
2
2
|
import type { IBasePathAnalyticPageWithChild, IBasePathAnalyticPageWithParent } from '../types';
|
|
3
3
|
export declare const processPathAnalytics: (analyticsData: IBasePathAnalyticPageWithParent[] | undefined, locationPath: string) => IBasePathAnalyticPageWithChild | undefined;
|
|
4
4
|
export declare const processPathAnalyticsTree: (analyticsData: IBasePathAnalyticPageWithParent[] | undefined) => IBasePathAnalyticPageWithChild[] | undefined;
|
package/dist/esm/gemxql.js
CHANGED
|
@@ -4,8 +4,8 @@ import timezone from 'dayjs/plugin/timezone.js';
|
|
|
4
4
|
import utc from 'dayjs/plugin/utc.js';
|
|
5
5
|
import { useQuery } from '@tanstack/react-query';
|
|
6
6
|
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
7
|
-
import { create } from 'zustand';
|
|
8
7
|
import { createContext, useContext, useState, useRef, useCallback, useEffect } from 'react';
|
|
8
|
+
import { create } from 'zustand';
|
|
9
9
|
|
|
10
10
|
const NONE_VALUE = 'None';
|
|
11
11
|
const PLACEHOLDER_VALUE = '-';
|
package/dist/esm/gemxql.mjs
CHANGED
|
@@ -4,8 +4,8 @@ import timezone from 'dayjs/plugin/timezone.js';
|
|
|
4
4
|
import utc from 'dayjs/plugin/utc.js';
|
|
5
5
|
import { useQuery } from '@tanstack/react-query';
|
|
6
6
|
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
7
|
-
import { create } from 'zustand';
|
|
8
7
|
import { createContext, useContext, useState, useRef, useCallback, useEffect } from 'react';
|
|
8
|
+
import { create } from 'zustand';
|
|
9
9
|
|
|
10
10
|
const NONE_VALUE = 'None';
|
|
11
11
|
const PLACEHOLDER_VALUE = '-';
|
package/dist/esm/index.js
CHANGED
|
@@ -1133,6 +1133,8 @@ const GChartSkeleton = () => {
|
|
|
1133
1133
|
return jsx(GSkeletonDisplayText, { height: "188px" });
|
|
1134
1134
|
};
|
|
1135
1135
|
|
|
1136
|
+
const useEnhancedEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;
|
|
1137
|
+
|
|
1136
1138
|
const useCurrencyRatesStore = create((set) => ({
|
|
1137
1139
|
currencyRates: null,
|
|
1138
1140
|
setCurrencyRates: (rates) => set({ currencyRates: rates }),
|
|
@@ -1174,100 +1176,6 @@ const useFetchCurrencyRates = () => {
|
|
|
1174
1176
|
}, [data, setCurrencyRates]);
|
|
1175
1177
|
};
|
|
1176
1178
|
|
|
1177
|
-
const getPriceByCurrency = (price, currency = DEFAULT_CURRENCY_ANALYTIC, options) => {
|
|
1178
|
-
if (typeof price === 'string')
|
|
1179
|
-
return price;
|
|
1180
|
-
if (typeof price !== 'number')
|
|
1181
|
-
return;
|
|
1182
|
-
// Support legacy 3rd arg as locale string
|
|
1183
|
-
const opts = typeof options === 'string' ? { locale: options } : options;
|
|
1184
|
-
const locale = opts?.locale ?? 'en-US';
|
|
1185
|
-
if (price >= 1_000_000_000) {
|
|
1186
|
-
return `${new Intl.NumberFormat(locale, {
|
|
1187
|
-
style: 'currency',
|
|
1188
|
-
currency,
|
|
1189
|
-
minimumFractionDigits: 2,
|
|
1190
|
-
maximumFractionDigits: 2,
|
|
1191
|
-
}).format(price / 1_000_000_000)}B`;
|
|
1192
|
-
}
|
|
1193
|
-
if (price >= 1_000_000) {
|
|
1194
|
-
return `${new Intl.NumberFormat(locale, {
|
|
1195
|
-
style: 'currency',
|
|
1196
|
-
currency,
|
|
1197
|
-
minimumFractionDigits: 2,
|
|
1198
|
-
maximumFractionDigits: 2,
|
|
1199
|
-
}).format(price / 1_000_000)}M`;
|
|
1200
|
-
}
|
|
1201
|
-
if (opts?.compact && Math.abs(price) >= 1_000) {
|
|
1202
|
-
return `${new Intl.NumberFormat(locale, {
|
|
1203
|
-
style: 'currency',
|
|
1204
|
-
currency,
|
|
1205
|
-
minimumFractionDigits: 1,
|
|
1206
|
-
maximumFractionDigits: 1,
|
|
1207
|
-
}).format(price / 1_000)}K`;
|
|
1208
|
-
}
|
|
1209
|
-
return new Intl.NumberFormat(locale, {
|
|
1210
|
-
style: 'currency',
|
|
1211
|
-
currency,
|
|
1212
|
-
}).format(price);
|
|
1213
|
-
};
|
|
1214
|
-
|
|
1215
|
-
const ConvertMoneyContext = createContext({
|
|
1216
|
-
getTextPrice: (price) => {
|
|
1217
|
-
if (typeof price === 'string')
|
|
1218
|
-
return price;
|
|
1219
|
-
return `${price ?? 0}`;
|
|
1220
|
-
},
|
|
1221
|
-
});
|
|
1222
|
-
const convertAmount = (amount, from, to, rates) => {
|
|
1223
|
-
if (from === to || !rates[from] || !rates[to])
|
|
1224
|
-
return amount;
|
|
1225
|
-
const converted = (amount * rates[from]) / rates[to];
|
|
1226
|
-
return converted ? Number(converted.toFixed(2)) : amount;
|
|
1227
|
-
};
|
|
1228
|
-
const ConvertMoneyProvider = ({ children, currency, locale = 'en-US' }) => {
|
|
1229
|
-
useFetchCurrencyRates();
|
|
1230
|
-
const currencyRates = useCurrencyRatesStore((state) => state.currencyRates);
|
|
1231
|
-
const getTextPrice = useCallback((price, _hasCurrency, options) => {
|
|
1232
|
-
if (typeof price === 'string')
|
|
1233
|
-
return price;
|
|
1234
|
-
if (typeof price !== 'number')
|
|
1235
|
-
return '0';
|
|
1236
|
-
if (!currency)
|
|
1237
|
-
return price.toString();
|
|
1238
|
-
const converted = currencyRates
|
|
1239
|
-
? convertAmount(price, DEFAULT_CURRENCY_ANALYTIC, currency, currencyRates)
|
|
1240
|
-
: price;
|
|
1241
|
-
return trimDecimalZeros(getPriceByCurrency(converted, currency, { locale, compact: options?.compact }) ?? '0');
|
|
1242
|
-
}, [currency, locale, currencyRates]);
|
|
1243
|
-
const value = useMemo(() => ({ getTextPrice }), [getTextPrice]);
|
|
1244
|
-
return jsx(ConvertMoneyContext.Provider, { value: value, children: children });
|
|
1245
|
-
};
|
|
1246
|
-
const useConvertMoneyContext = () => useContext(ConvertMoneyContext);
|
|
1247
|
-
|
|
1248
|
-
const LINE_SERIES_COLORS = {
|
|
1249
|
-
comparison: SERIES_COLORS.comparison,
|
|
1250
|
-
single: SERIES_COLORS.current,
|
|
1251
|
-
all: [...SERIES_COLORS.all],
|
|
1252
|
-
};
|
|
1253
|
-
const MetricChartProvider = ({ children, minHeight = CHART_MIN_HEIGHT, seriesColors = LINE_SERIES_COLORS, }) => {
|
|
1254
|
-
return (jsxs(Fragment, { children: [jsx("link", { rel: "stylesheet", href: chartStyle }), jsx(PolarisVizProvider, { themes: {
|
|
1255
|
-
Light: {
|
|
1256
|
-
chartContainer: {
|
|
1257
|
-
minHeight,
|
|
1258
|
-
},
|
|
1259
|
-
grid: {
|
|
1260
|
-
horizontalOverflow: true,
|
|
1261
|
-
verticalOverflow: true,
|
|
1262
|
-
horizontalMargin: 0,
|
|
1263
|
-
},
|
|
1264
|
-
seriesColors,
|
|
1265
|
-
},
|
|
1266
|
-
}, children: children })] }));
|
|
1267
|
-
};
|
|
1268
|
-
|
|
1269
|
-
const useEnhancedEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;
|
|
1270
|
-
|
|
1271
1179
|
const NONE_VALUE = 'None';
|
|
1272
1180
|
const PLACEHOLDER_VALUE = '-';
|
|
1273
1181
|
|
|
@@ -1637,6 +1545,98 @@ const useWindowSize = () => {
|
|
|
1637
1545
|
return { windowSize, windowWidth, isMobileTabletView, isMobileView };
|
|
1638
1546
|
};
|
|
1639
1547
|
|
|
1548
|
+
const getPriceByCurrency = (price, currency = DEFAULT_CURRENCY_ANALYTIC, options) => {
|
|
1549
|
+
if (typeof price === 'string')
|
|
1550
|
+
return price;
|
|
1551
|
+
if (typeof price !== 'number')
|
|
1552
|
+
return;
|
|
1553
|
+
// Support legacy 3rd arg as locale string
|
|
1554
|
+
const opts = typeof options === 'string' ? { locale: options } : options;
|
|
1555
|
+
const locale = opts?.locale ?? 'en-US';
|
|
1556
|
+
if (price >= 1_000_000_000) {
|
|
1557
|
+
return `${new Intl.NumberFormat(locale, {
|
|
1558
|
+
style: 'currency',
|
|
1559
|
+
currency,
|
|
1560
|
+
minimumFractionDigits: 2,
|
|
1561
|
+
maximumFractionDigits: 2,
|
|
1562
|
+
}).format(price / 1_000_000_000)}B`;
|
|
1563
|
+
}
|
|
1564
|
+
if (price >= 1_000_000) {
|
|
1565
|
+
return `${new Intl.NumberFormat(locale, {
|
|
1566
|
+
style: 'currency',
|
|
1567
|
+
currency,
|
|
1568
|
+
minimumFractionDigits: 2,
|
|
1569
|
+
maximumFractionDigits: 2,
|
|
1570
|
+
}).format(price / 1_000_000)}M`;
|
|
1571
|
+
}
|
|
1572
|
+
if (opts?.compact && Math.abs(price) >= 1_000) {
|
|
1573
|
+
return `${new Intl.NumberFormat(locale, {
|
|
1574
|
+
style: 'currency',
|
|
1575
|
+
currency,
|
|
1576
|
+
minimumFractionDigits: 1,
|
|
1577
|
+
maximumFractionDigits: 1,
|
|
1578
|
+
}).format(price / 1_000)}K`;
|
|
1579
|
+
}
|
|
1580
|
+
return new Intl.NumberFormat(locale, {
|
|
1581
|
+
style: 'currency',
|
|
1582
|
+
currency,
|
|
1583
|
+
}).format(price);
|
|
1584
|
+
};
|
|
1585
|
+
|
|
1586
|
+
const ConvertMoneyContext = createContext({
|
|
1587
|
+
getTextPrice: (price) => {
|
|
1588
|
+
if (typeof price === 'string')
|
|
1589
|
+
return price;
|
|
1590
|
+
return `${price ?? 0}`;
|
|
1591
|
+
},
|
|
1592
|
+
});
|
|
1593
|
+
const convertAmount = (amount, from, to, rates) => {
|
|
1594
|
+
if (from === to || !rates[from] || !rates[to])
|
|
1595
|
+
return amount;
|
|
1596
|
+
const converted = (amount * rates[from]) / rates[to];
|
|
1597
|
+
return converted ? Number(converted.toFixed(2)) : amount;
|
|
1598
|
+
};
|
|
1599
|
+
const ConvertMoneyProvider = ({ children, currency, locale = 'en-US' }) => {
|
|
1600
|
+
useFetchCurrencyRates();
|
|
1601
|
+
const currencyRates = useCurrencyRatesStore((state) => state.currencyRates);
|
|
1602
|
+
const getTextPrice = useCallback((price, _hasCurrency, options) => {
|
|
1603
|
+
if (typeof price === 'string')
|
|
1604
|
+
return price;
|
|
1605
|
+
if (typeof price !== 'number')
|
|
1606
|
+
return '0';
|
|
1607
|
+
if (!currency)
|
|
1608
|
+
return price.toString();
|
|
1609
|
+
const converted = currencyRates
|
|
1610
|
+
? convertAmount(price, DEFAULT_CURRENCY_ANALYTIC, currency, currencyRates)
|
|
1611
|
+
: price;
|
|
1612
|
+
return trimDecimalZeros(getPriceByCurrency(converted, currency, { locale, compact: options?.compact }) ?? '0');
|
|
1613
|
+
}, [currency, locale, currencyRates]);
|
|
1614
|
+
const value = useMemo(() => ({ getTextPrice }), [getTextPrice]);
|
|
1615
|
+
return jsx(ConvertMoneyContext.Provider, { value: value, children: children });
|
|
1616
|
+
};
|
|
1617
|
+
const useConvertMoneyContext = () => useContext(ConvertMoneyContext);
|
|
1618
|
+
|
|
1619
|
+
const LINE_SERIES_COLORS = {
|
|
1620
|
+
comparison: SERIES_COLORS.comparison,
|
|
1621
|
+
single: SERIES_COLORS.current,
|
|
1622
|
+
all: [...SERIES_COLORS.all],
|
|
1623
|
+
};
|
|
1624
|
+
const MetricChartProvider = ({ children, minHeight = CHART_MIN_HEIGHT, seriesColors = LINE_SERIES_COLORS, }) => {
|
|
1625
|
+
return (jsxs(Fragment, { children: [jsx("link", { rel: "stylesheet", href: chartStyle }), jsx(PolarisVizProvider, { themes: {
|
|
1626
|
+
Light: {
|
|
1627
|
+
chartContainer: {
|
|
1628
|
+
minHeight,
|
|
1629
|
+
},
|
|
1630
|
+
grid: {
|
|
1631
|
+
horizontalOverflow: true,
|
|
1632
|
+
verticalOverflow: true,
|
|
1633
|
+
horizontalMargin: 0,
|
|
1634
|
+
},
|
|
1635
|
+
seriesColors,
|
|
1636
|
+
},
|
|
1637
|
+
}, children: children })] }));
|
|
1638
|
+
};
|
|
1639
|
+
|
|
1640
1640
|
const MetricChart = ({ lineChartData, isLoading, isEmptyMetricData, columnTypes, metricKey, }) => {
|
|
1641
1641
|
const { formatValue, yAxisOptions } = useFormatLineChartData({ metricKey, columnTypes: columnTypes || {} });
|
|
1642
1642
|
if (!metricKey) {
|
|
@@ -2967,10 +2967,177 @@ var IPAMetricKey;
|
|
|
2967
2967
|
IPAMetricKey["PAGE_AOV"] = "PAGE_AVERAGE_ORDER_VALUE";
|
|
2968
2968
|
IPAMetricKey["PAGE_VISITORS"] = "PAGE_VISITORS";
|
|
2969
2969
|
})(IPAMetricKey || (IPAMetricKey = {}));
|
|
2970
|
+
var IMetricFormatter;
|
|
2971
|
+
(function (IMetricFormatter) {
|
|
2972
|
+
IMetricFormatter["PERCENTAGE_STRING"] = "PERCENTAGE_STRING";
|
|
2973
|
+
IMetricFormatter["CURRENCY"] = "CURRENCY";
|
|
2974
|
+
IMetricFormatter["DURATION"] = "DURATION";
|
|
2975
|
+
IMetricFormatter["DURATION_MS"] = "DURATION_MS";
|
|
2976
|
+
IMetricFormatter["MILLISECONDS"] = "MILLISECONDS";
|
|
2977
|
+
IMetricFormatter["NORMAL"] = "NORMAL";
|
|
2978
|
+
IMetricFormatter["NUMBER_COMMAS"] = "NUMBER_COMMAS";
|
|
2979
|
+
IMetricFormatter["NUMBER_COMMAS_LEAN"] = "NUMBER_COMMAS_LEAN";
|
|
2980
|
+
})(IMetricFormatter || (IMetricFormatter = {}));
|
|
2981
|
+
|
|
2982
|
+
const formatMetricByFormatter = ({ value, formatter, getTextPrice, compact }) => {
|
|
2983
|
+
const dataValue = value ?? 0;
|
|
2984
|
+
switch (formatter) {
|
|
2985
|
+
case IMetricFormatter.PERCENTAGE_STRING: {
|
|
2986
|
+
if (typeof dataValue !== 'number')
|
|
2987
|
+
return calcPercentageString(0, 1, 2) ?? '';
|
|
2988
|
+
return calcPercentageString(dataValue, 1, 2) ?? '';
|
|
2989
|
+
}
|
|
2990
|
+
case IMetricFormatter.NUMBER_COMMAS:
|
|
2991
|
+
case IMetricFormatter.NUMBER_COMMAS_LEAN:
|
|
2992
|
+
case IMetricFormatter.NORMAL: {
|
|
2993
|
+
if (compact && typeof dataValue === 'number' && Math.abs(dataValue) >= 1_000) {
|
|
2994
|
+
return new Intl.NumberFormat('en', { notation: 'compact', maximumFractionDigits: 1 }).format(dataValue);
|
|
2995
|
+
}
|
|
2996
|
+
return numberWithCommas(dataValue.toString());
|
|
2997
|
+
}
|
|
2998
|
+
case IMetricFormatter.DURATION: {
|
|
2999
|
+
return getTimeDurationLabel(Number(dataValue));
|
|
3000
|
+
}
|
|
3001
|
+
case IMetricFormatter.DURATION_MS:
|
|
3002
|
+
case IMetricFormatter.MILLISECONDS: {
|
|
3003
|
+
return getTimeDurationLabel(Number(dataValue) / 1000);
|
|
3004
|
+
}
|
|
3005
|
+
case IMetricFormatter.CURRENCY: {
|
|
3006
|
+
return getTextPrice(dataValue, false, compact ? { compact } : undefined);
|
|
3007
|
+
}
|
|
3008
|
+
default:
|
|
3009
|
+
return `${dataValue}`;
|
|
3010
|
+
}
|
|
3011
|
+
};
|
|
2970
3012
|
|
|
2971
|
-
const
|
|
2972
|
-
|
|
3013
|
+
const getPAMetricValueV2 = (metric, key) => {
|
|
3014
|
+
if (!metric || !key || !(key in PAGE_ANALYTIC_MAPPING))
|
|
3015
|
+
return { value: 0, formatter: IMetricFormatter.NORMAL };
|
|
3016
|
+
return PAGE_ANALYTIC_MAPPING[key].getMetricValue({ metric });
|
|
3017
|
+
};
|
|
2973
3018
|
|
|
3019
|
+
const detectDataV2By = ({ data, formatter, extractValue, }) => {
|
|
3020
|
+
const valueEmpty = { formatter, value: 0 };
|
|
3021
|
+
if (!data)
|
|
3022
|
+
return valueEmpty;
|
|
3023
|
+
const value = extractValue(data);
|
|
3024
|
+
if (typeof value === 'undefined')
|
|
3025
|
+
return valueEmpty;
|
|
3026
|
+
return { value, formatter };
|
|
3027
|
+
};
|
|
3028
|
+
const toNumber = (value) => value ?? 0;
|
|
3029
|
+
const divideRatio = (part, total) => {
|
|
3030
|
+
const numerator = toNumber(part);
|
|
3031
|
+
const denominator = toNumber(total);
|
|
3032
|
+
const ratio = numerator > 0 && denominator > 0 ? numerator / denominator : 0;
|
|
3033
|
+
return ratio ? ratio : undefined;
|
|
3034
|
+
};
|
|
3035
|
+
const getTotalSessionMetric = ({ metric }) => detectDataV2By({
|
|
3036
|
+
data: metric,
|
|
3037
|
+
extractValue: (value) => value?.totalSessions ?? undefined,
|
|
3038
|
+
formatter: IMetricFormatter.NORMAL,
|
|
3039
|
+
});
|
|
3040
|
+
const getTotalVisitorMetric = ({ metric }) => detectDataV2By({
|
|
3041
|
+
data: metric,
|
|
3042
|
+
extractValue: (value) => value?.totalVisitors ?? undefined,
|
|
3043
|
+
formatter: IMetricFormatter.NORMAL,
|
|
3044
|
+
});
|
|
3045
|
+
const getTotalOrderMetric = ({ metric }) => detectDataV2By({
|
|
3046
|
+
data: metric,
|
|
3047
|
+
extractValue: (value) => value?.totalOrders ?? undefined,
|
|
3048
|
+
formatter: IMetricFormatter.NORMAL,
|
|
3049
|
+
});
|
|
3050
|
+
const getTotalPageViewMetric = ({ metric }) => detectDataV2By({
|
|
3051
|
+
data: metric,
|
|
3052
|
+
extractValue: (value) => value?.totalPageViewed ?? undefined,
|
|
3053
|
+
formatter: IMetricFormatter.NORMAL,
|
|
3054
|
+
});
|
|
3055
|
+
const getTotalRevenueMetric = ({ metric }) => detectDataV2By({
|
|
3056
|
+
data: metric,
|
|
3057
|
+
extractValue: (value) => value?.totalRevenue ?? undefined,
|
|
3058
|
+
formatter: IMetricFormatter.CURRENCY,
|
|
3059
|
+
});
|
|
3060
|
+
const getBounceRateMetric = ({ metric }) => detectDataV2By({
|
|
3061
|
+
data: metric,
|
|
3062
|
+
extractValue: (value) => divideRatio(value?.totalSessionsWithoutAction, value?.totalSessions),
|
|
3063
|
+
formatter: IMetricFormatter.PERCENTAGE_STRING,
|
|
3064
|
+
});
|
|
3065
|
+
const getLinkCtrMetric = ({ metric }) => detectDataV2By({
|
|
3066
|
+
data: metric,
|
|
3067
|
+
extractValue: (value) => divideRatio(value?.totalClickedHasHref, value?.totalPageViewed),
|
|
3068
|
+
formatter: IMetricFormatter.PERCENTAGE_STRING,
|
|
3069
|
+
});
|
|
3070
|
+
const getConversionRateMetric = ({ metric }) => detectDataV2By({
|
|
3071
|
+
data: metric,
|
|
3072
|
+
extractValue: (value) => divideRatio(value?.totalSessionsThatCompletedCheckout, value?.totalSessions),
|
|
3073
|
+
formatter: IMetricFormatter.PERCENTAGE_STRING,
|
|
3074
|
+
});
|
|
3075
|
+
const getAddToCartRateMetric = ({ metric }) => detectDataV2By({
|
|
3076
|
+
data: metric,
|
|
3077
|
+
extractValue: (value) => divideRatio(value?.totalSessionsWithCartAdditions, value?.totalSessions),
|
|
3078
|
+
formatter: IMetricFormatter.PERCENTAGE_STRING,
|
|
3079
|
+
});
|
|
3080
|
+
const getAverageTimeOnPageMetric = ({ metric }) => detectDataV2By({
|
|
3081
|
+
data: metric,
|
|
3082
|
+
extractValue: (value) => {
|
|
3083
|
+
const averageTimeOnPage = divideRatio(value?.totalTimeOnPage, value?.totalPageViewedHaveTimeOnPage);
|
|
3084
|
+
return averageTimeOnPage ? Number(averageTimeOnPage.toFixed(2)) : undefined;
|
|
3085
|
+
},
|
|
3086
|
+
formatter: IMetricFormatter.DURATION,
|
|
3087
|
+
});
|
|
3088
|
+
const getRevenuePerVisitorMetric = ({ metric }) => detectDataV2By({
|
|
3089
|
+
data: metric,
|
|
3090
|
+
extractValue: (value) => {
|
|
3091
|
+
const revenuePerVisitor = divideRatio(value?.totalRevenue, value?.totalVisitors);
|
|
3092
|
+
return revenuePerVisitor ? Number(revenuePerVisitor.toFixed(2)) : undefined;
|
|
3093
|
+
},
|
|
3094
|
+
formatter: IMetricFormatter.CURRENCY,
|
|
3095
|
+
});
|
|
3096
|
+
const getAverageOrderValueMetric = ({ metric }) => detectDataV2By({
|
|
3097
|
+
data: metric,
|
|
3098
|
+
extractValue: (value) => {
|
|
3099
|
+
const averageOrderValue = divideRatio(value?.totalRevenue, value?.totalOrders);
|
|
3100
|
+
return averageOrderValue ? Number(averageOrderValue.toFixed(2)) : undefined;
|
|
3101
|
+
},
|
|
3102
|
+
formatter: IMetricFormatter.CURRENCY,
|
|
3103
|
+
});
|
|
3104
|
+
const getTotalATCMetric = ({ metric }) => detectDataV2By({
|
|
3105
|
+
data: metric,
|
|
3106
|
+
extractValue: (value) => value?.totalAddedToCart ?? undefined,
|
|
3107
|
+
formatter: IMetricFormatter.NORMAL,
|
|
3108
|
+
});
|
|
3109
|
+
const getTotalSessionWithCartAdditionMetric$1 = ({ metric }) => detectDataV2By({
|
|
3110
|
+
data: metric,
|
|
3111
|
+
extractValue: (value) => value?.totalSessionsWithCartAdditions ?? undefined,
|
|
3112
|
+
formatter: IMetricFormatter.NORMAL,
|
|
3113
|
+
});
|
|
3114
|
+
const getTotalSessionReachedCheckoutMetric$1 = ({ metric }) => detectDataV2By({
|
|
3115
|
+
data: metric,
|
|
3116
|
+
extractValue: (value) => value?.totalSessionsThatReachedCheckout ?? undefined,
|
|
3117
|
+
formatter: IMetricFormatter.NORMAL,
|
|
3118
|
+
});
|
|
3119
|
+
const getTotalSessionCompletedCheckoutMetric$1 = ({ metric }) => detectDataV2By({
|
|
3120
|
+
data: metric,
|
|
3121
|
+
extractValue: (value) => value?.totalSessionsThatCompletedCheckout ?? undefined,
|
|
3122
|
+
formatter: IMetricFormatter.NORMAL,
|
|
3123
|
+
});
|
|
3124
|
+
const getPathAnalysisMetric = ({ metric }) => detectDataV2By({
|
|
3125
|
+
data: metric,
|
|
3126
|
+
extractValue: () => undefined,
|
|
3127
|
+
formatter: IMetricFormatter.NORMAL,
|
|
3128
|
+
});
|
|
3129
|
+
const getTotalSessionByDeviceMetric = ({ metric }) => detectDataV2By({
|
|
3130
|
+
data: metric,
|
|
3131
|
+
extractValue: () => undefined,
|
|
3132
|
+
formatter: IMetricFormatter.NORMAL,
|
|
3133
|
+
});
|
|
3134
|
+
const getNewReturningCustomerMetric = ({ metric }) => detectDataV2By({
|
|
3135
|
+
data: metric,
|
|
3136
|
+
extractValue: () => undefined,
|
|
3137
|
+
formatter: IMetricFormatter.NORMAL,
|
|
3138
|
+
});
|
|
3139
|
+
|
|
3140
|
+
const PA_METRIC_TOOLTIP = {};
|
|
2974
3141
|
const METRICS_COLUMNS = {
|
|
2975
3142
|
[IPAMetricKey.PAGE_SESSIONS]: { label: 'Sessions' },
|
|
2976
3143
|
[IPAMetricKey.PAGE_BR]: { label: 'Bounce rate' },
|
|
@@ -2994,7 +3161,72 @@ const METRICS_COLUMNS = {
|
|
|
2994
3161
|
[IPAMetricKey.PAGE_SESSIONS_BY_DEVICE]: { label: 'Sessions by device type' },
|
|
2995
3162
|
[IPAMetricKey.PAGE_NEW_RETURNING_CUSTOMER]: { label: 'New vs returning visitors' },
|
|
2996
3163
|
};
|
|
2997
|
-
const
|
|
3164
|
+
const getHeading = (key) => ({ title: METRICS_COLUMNS[key].label });
|
|
3165
|
+
const PAGE_ANALYTIC_MAPPING = {
|
|
3166
|
+
[IPAMetricKey.PAGE_SESSIONS]: {
|
|
3167
|
+
getMetricValue: getTotalSessionMetric,
|
|
3168
|
+
heading: getHeading(IPAMetricKey.PAGE_SESSIONS),
|
|
3169
|
+
},
|
|
3170
|
+
[IPAMetricKey.PAGE_BR]: { getMetricValue: getBounceRateMetric, heading: getHeading(IPAMetricKey.PAGE_BR) },
|
|
3171
|
+
[IPAMetricKey.PAGE_CTR]: { getMetricValue: getLinkCtrMetric, heading: getHeading(IPAMetricKey.PAGE_CTR) },
|
|
3172
|
+
[IPAMetricKey.PAGE_CR]: { getMetricValue: getConversionRateMetric, heading: getHeading(IPAMetricKey.PAGE_CR) },
|
|
3173
|
+
[IPAMetricKey.PAGE_VISITORS]: {
|
|
3174
|
+
getMetricValue: getTotalVisitorMetric,
|
|
3175
|
+
heading: getHeading(IPAMetricKey.PAGE_VISITORS),
|
|
3176
|
+
},
|
|
3177
|
+
[IPAMetricKey.PAGE_AVG_TIME]: {
|
|
3178
|
+
getMetricValue: getAverageTimeOnPageMetric,
|
|
3179
|
+
heading: getHeading(IPAMetricKey.PAGE_AVG_TIME),
|
|
3180
|
+
},
|
|
3181
|
+
[IPAMetricKey.PAGE_VIEWS]: { getMetricValue: getTotalPageViewMetric, heading: getHeading(IPAMetricKey.PAGE_VIEWS) },
|
|
3182
|
+
[IPAMetricKey.PAGE_REVENUE]: {
|
|
3183
|
+
getMetricValue: getTotalRevenueMetric,
|
|
3184
|
+
heading: getHeading(IPAMetricKey.PAGE_REVENUE),
|
|
3185
|
+
},
|
|
3186
|
+
[IPAMetricKey.PAGE_ADDED_TO_CART]: {
|
|
3187
|
+
getMetricValue: getTotalATCMetric,
|
|
3188
|
+
heading: getHeading(IPAMetricKey.PAGE_ADDED_TO_CART),
|
|
3189
|
+
},
|
|
3190
|
+
[IPAMetricKey.PAGE_REACHED_CHECKOUT]: {
|
|
3191
|
+
getMetricValue: getTotalSessionReachedCheckoutMetric$1,
|
|
3192
|
+
heading: getHeading(IPAMetricKey.PAGE_REACHED_CHECKOUT),
|
|
3193
|
+
},
|
|
3194
|
+
[IPAMetricKey.PAGE_COMPLETE_CHECKOUT]: {
|
|
3195
|
+
getMetricValue: getTotalSessionCompletedCheckoutMetric$1,
|
|
3196
|
+
heading: getHeading(IPAMetricKey.PAGE_COMPLETE_CHECKOUT),
|
|
3197
|
+
},
|
|
3198
|
+
[IPAMetricKey.PAGE_RPV]: { getMetricValue: getRevenuePerVisitorMetric, heading: getHeading(IPAMetricKey.PAGE_RPV) },
|
|
3199
|
+
[IPAMetricKey.PAGE_CART_ADDITION]: {
|
|
3200
|
+
getMetricValue: getTotalSessionWithCartAdditionMetric$1,
|
|
3201
|
+
heading: getHeading(IPAMetricKey.PAGE_CART_ADDITION),
|
|
3202
|
+
},
|
|
3203
|
+
[IPAMetricKey.PAGE_ADD_TO_CART_RATE]: {
|
|
3204
|
+
getMetricValue: getAddToCartRateMetric,
|
|
3205
|
+
heading: getHeading(IPAMetricKey.PAGE_ADD_TO_CART_RATE),
|
|
3206
|
+
},
|
|
3207
|
+
[IPAMetricKey.PAGE_ORDERS]: { getMetricValue: getTotalOrderMetric, heading: getHeading(IPAMetricKey.PAGE_ORDERS) },
|
|
3208
|
+
[IPAMetricKey.PAGE_AOV]: { getMetricValue: getAverageOrderValueMetric, heading: getHeading(IPAMetricKey.PAGE_AOV) },
|
|
3209
|
+
[IPAMetricKey.PAGE_SESSIONS_BY_VISITOR]: {
|
|
3210
|
+
getMetricValue: getTotalVisitorMetric,
|
|
3211
|
+
heading: getHeading(IPAMetricKey.PAGE_SESSIONS_BY_VISITOR),
|
|
3212
|
+
},
|
|
3213
|
+
[IPAMetricKey.PAGE_SESSIONS_BY_TRAFFIC]: {
|
|
3214
|
+
getMetricValue: getTotalSessionMetric,
|
|
3215
|
+
heading: getHeading(IPAMetricKey.PAGE_SESSIONS_BY_TRAFFIC),
|
|
3216
|
+
},
|
|
3217
|
+
[IPAMetricKey.PAGE_PATH_ANALYSIS]: {
|
|
3218
|
+
getMetricValue: getPathAnalysisMetric,
|
|
3219
|
+
heading: getHeading(IPAMetricKey.PAGE_PATH_ANALYSIS),
|
|
3220
|
+
},
|
|
3221
|
+
[IPAMetricKey.PAGE_SESSIONS_BY_DEVICE]: {
|
|
3222
|
+
getMetricValue: getTotalSessionByDeviceMetric,
|
|
3223
|
+
heading: getHeading(IPAMetricKey.PAGE_SESSIONS_BY_DEVICE),
|
|
3224
|
+
},
|
|
3225
|
+
[IPAMetricKey.PAGE_NEW_RETURNING_CUSTOMER]: {
|
|
3226
|
+
getMetricValue: getNewReturningCustomerMetric,
|
|
3227
|
+
heading: getHeading(IPAMetricKey.PAGE_NEW_RETURNING_CUSTOMER),
|
|
3228
|
+
},
|
|
3229
|
+
};
|
|
2998
3230
|
|
|
2999
3231
|
const removeDuplicates = (data, keys) => {
|
|
3000
3232
|
if (!Array.isArray(data))
|
|
@@ -3063,7 +3295,7 @@ const getFunnelChartTooltip = (data) => {
|
|
|
3063
3295
|
const { page, getTextPrice } = data;
|
|
3064
3296
|
if (!page)
|
|
3065
3297
|
return [];
|
|
3066
|
-
page.metric;
|
|
3298
|
+
const metric = page.metric;
|
|
3067
3299
|
const totalContinuationSession = numberWithCommas((page.metric?.totalContinuationSession || 0).toString());
|
|
3068
3300
|
const baseInfo = [
|
|
3069
3301
|
{
|
|
@@ -3079,9 +3311,14 @@ const getFunnelChartTooltip = (data) => {
|
|
|
3079
3311
|
};
|
|
3080
3312
|
}
|
|
3081
3313
|
const metricKey = key;
|
|
3314
|
+
const value = getPAMetricValueV2(metric, metricKey);
|
|
3082
3315
|
return {
|
|
3083
3316
|
key: PAGE_ANALYTIC_MAPPING[metricKey].heading.title,
|
|
3084
|
-
value: formatMetricByFormatter(
|
|
3317
|
+
value: formatMetricByFormatter({
|
|
3318
|
+
value: value.value,
|
|
3319
|
+
formatter: value.formatter,
|
|
3320
|
+
getTextPrice,
|
|
3321
|
+
}),
|
|
3085
3322
|
};
|
|
3086
3323
|
});
|
|
3087
3324
|
return baseInfo.concat(metricInfo);
|
|
@@ -23635,16 +23872,12 @@ const MOCK_DATA_PATH_ANALYSIS = [
|
|
|
23635
23872
|
},
|
|
23636
23873
|
];
|
|
23637
23874
|
|
|
23638
|
-
const useConvertMoneyByCurrency = () => ({
|
|
23639
|
-
getTextPrice: () => '',
|
|
23640
|
-
});
|
|
23641
|
-
|
|
23642
23875
|
const FUNNEL_NAME = 'Conversion';
|
|
23643
23876
|
// Checkout pages don't support heatmap viewing
|
|
23644
23877
|
const NON_HEATMAP_PAGE_TYPES = new Set([TemplateType.CHECKOUT]);
|
|
23645
23878
|
const usePathAnalysisChart = () => {
|
|
23646
23879
|
const { t } = useTranslation();
|
|
23647
|
-
const { getTextPrice } =
|
|
23880
|
+
const { getTextPrice } = useConvertMoneyContext();
|
|
23648
23881
|
const { heatmap } = usePathAnalysisConfig();
|
|
23649
23882
|
const { shopifyPageType, pageWithMetric, nextLevelPages, dynamicLevels, previousPathAnalyticsMap, handleAddNextLevel, handleChangeLevel, getPagesByParentID, handleDeleteLevel, } = usePathAnalysisContext();
|
|
23650
23883
|
const orderedPages = useMemo(() => [pageWithMetric, ...dynamicLevels].filter(Boolean), [pageWithMetric, dynamicLevels]);
|