-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/metrics : removed conversion, added date display option #537
Changes from all commits
9afaac7
7392577
96ed9d1
e6b6f9f
888780b
9c04bd8
f6a34d8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@pinelab/vendure-plugin-metrics", | ||
"version": "1.5.0", | ||
"version": "1.6.0", | ||
"description": "Vendure plugin measuring and visualizing e-commerce metrics", | ||
"author": "Martijn van de Brug <[email protected]>", | ||
"homepage": "https://pinelab-plugins.com/", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,16 +48,18 @@ export class MetricsService { | |
); | ||
const today = endOfDay(new Date()); | ||
// Use start of month, because we'd like to see the full results of last years same month | ||
const oneYearAgo = startOfMonth(sub(today, { years: 1 })); | ||
const startDate = startOfMonth( | ||
sub(today, { months: this.pluginOptions.displayPastMonths }) | ||
); | ||
Comment on lines
+51
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add validation for Ensure that |
||
// For each metric strategy | ||
return Promise.all( | ||
this.metricStrategies.map(async (metricStrategy) => { | ||
const cacheKeyObject = { | ||
code: metricStrategy.code, | ||
from: today.toDateString(), | ||
to: oneYearAgo.toDateString(), | ||
from: startDate.toDateString(), | ||
to: today.toDateString(), | ||
channel: ctx.channel.token, | ||
variantIds: [] as string[], | ||
variantIds: [] as string[], // Set below if input is given | ||
}; | ||
if (metricStrategy.allowProductSelection) { | ||
// Only use variantIds for cache key if the strategy allows filtering by variants | ||
|
@@ -78,14 +80,14 @@ export class MetricsService { | |
const allEntities = await metricStrategy.loadEntities( | ||
ctx, | ||
new Injector(this.moduleRef), | ||
oneYearAgo, | ||
startDate, | ||
today, | ||
variants | ||
); | ||
const entitiesPerMonth = this.splitEntitiesInMonths( | ||
metricStrategy, | ||
allEntities, | ||
oneYearAgo, | ||
startDate, | ||
today | ||
); | ||
// Calculate datapoints per 'name', because we could be dealing with a multi line chart | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -9,10 +9,17 @@ import { PLUGIN_INIT_OPTIONS } from './constants'; | |||||||||||||||||||||||||
import { RevenuePerProduct } from './api/metrics/revenue-per-product'; | ||||||||||||||||||||||||||
import { AverageOrderValueMetric } from './api/metrics/average-order-value'; | ||||||||||||||||||||||||||
import { UnitsSoldMetric } from './api/metrics/units-sold-metric'; | ||||||||||||||||||||||||||
import { ConversionMetric } from './api/metrics/conversion'; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
export interface MetricsPluginOptions { | ||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||
* The enabled metrics shown in the widget. | ||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||
metrics: MetricStrategy<any>[]; | ||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||
* The number of past months to display in the metrics widget. | ||||||||||||||||||||||||||
* If your shop has a lot of orders, consider using only the last 3 months for example. | ||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||
displayPastMonths: number; | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
@VendurePlugin({ | ||||||||||||||||||||||||||
|
@@ -31,14 +38,17 @@ export class MetricsPlugin { | |||||||||||||||||||||||||
static options: MetricsPluginOptions = { | ||||||||||||||||||||||||||
metrics: [ | ||||||||||||||||||||||||||
new RevenuePerProduct(), | ||||||||||||||||||||||||||
new ConversionMetric(), | ||||||||||||||||||||||||||
new AverageOrderValueMetric(), | ||||||||||||||||||||||||||
new UnitsSoldMetric(), | ||||||||||||||||||||||||||
], | ||||||||||||||||||||||||||
displayPastMonths: 13, | ||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
static init(options: MetricsPluginOptions): typeof MetricsPlugin { | ||||||||||||||||||||||||||
this.options = options; | ||||||||||||||||||||||||||
static init(options: Partial<MetricsPluginOptions>): typeof MetricsPlugin { | ||||||||||||||||||||||||||
this.options = { | ||||||||||||||||||||||||||
...this.options, | ||||||||||||||||||||||||||
...options, | ||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||
Comment on lines
+47
to
+51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix use of 'this' in static context Using 'this' in static methods can be confusing. Consider using the class name directly. Apply this fix: static init(options: Partial<MetricsPluginOptions>): typeof MetricsPlugin {
- this.options = {
- ...this.options,
+ MetricsPlugin.options = {
+ ...MetricsPlugin.options,
...options,
};
return MetricsPlugin;
} 📝 Committable suggestion
Suggested change
🧰 Tools🪛 Biome[error] 48-48: Using this in a static context can be confusing. this refers to the class. (lint/complexity/noThisInStatic) [error] 49-49: Using this in a static context can be confusing. this refers to the class. (lint/complexity/noThisInStatic) |
||||||||||||||||||||||||||
return MetricsPlugin; | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix grammar in changelog entry
There's a grammar error in the conversion metric removal note.
📝 Committable suggestion
🧰 Tools
🪛 LanguageTool
[grammar] ~4-~4: It appears that only one verb is needed.
Context: ...ths. - Removed conversion metric, as it is can not be accurately calculated based on c...
(THIS_IS_HAVE)