UNPKG

@pinelab/vendure-plugin-metrics

Version:

Vendure plugin measuring and visualizing e-commerce metrics

39 lines (38 loc) 1.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SessionsMetric = void 0; const graphql_1 = require("../ui/generated/graphql"); /** * Number of sessions and device type */ class SessionsMetric { constructor() { this.metricType = graphql_1.AdvancedMetricType.Number; this.code = 'sessions'; this.allowProductSelection = false; } getTitle(ctx) { return `Sessions`; } calculateDataPoints(ctx, orders, sessions = []) { const totalSessions = sessions.length; const dataPoints = [ { legendLabel: 'Total sessions', value: totalSessions, }, { legendLabel: 'Mobile', value: sessions.filter(({ deviceType }) => deviceType === 'mobile') .length, }, { legendLabel: 'Other', value: sessions.filter(({ deviceType }) => deviceType === 'other') .length, }, ]; return dataPoints; } } exports.SessionsMetric = SessionsMetric;