@fluid-topics/ft-analytics-sessions-chart 0.0.88
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/README.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
Display sessions
|
|
2
|
+
|
|
3
|
+
## Install
|
|
4
|
+
|
|
5
|
+
```shell
|
|
6
|
+
npm install @fluid-topics/ft-analytics-sessions-chart
|
|
7
|
+
yarn add @fluid-topics/ft-analytics-sessions-chart
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
import {html} from "lit"
|
|
14
|
+
import "@fluid-topics/ft-analytics-sessions-chart"
|
|
15
|
+
|
|
16
|
+
function render() {
|
|
17
|
+
return html` <ft-analytics-sessions-chart
|
|
18
|
+
baseUrl="https://my.fluidtopics.com/myTenant"
|
|
19
|
+
period="MONTH"
|
|
20
|
+
startDate="2021-01-01"
|
|
21
|
+
endDate="2022-01-01">
|
|
22
|
+
</ft-analytics-sessions-chart> `
|
|
23
|
+
}
|
|
24
|
+
```
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { PropertyValues } from 'lit';
|
|
2
|
+
import { FtLitElement } from '@fluid-topics/ft-wc-utils';
|
|
3
|
+
import { Period } from '@fluid-topics/ft-chart';
|
|
4
|
+
export interface FtAnalyticsSessionsChartProperties {
|
|
5
|
+
baseUrl: string;
|
|
6
|
+
period: Period;
|
|
7
|
+
startDate: string;
|
|
8
|
+
endDate: string;
|
|
9
|
+
}
|
|
10
|
+
export declare class FtAnalyticsSessionsChart extends FtLitElement implements FtAnalyticsSessionsChartProperties {
|
|
11
|
+
getStyles(): import("lit").CSSResult;
|
|
12
|
+
baseUrl: string;
|
|
13
|
+
period: Period;
|
|
14
|
+
startDate: string;
|
|
15
|
+
endDate: string;
|
|
16
|
+
private data;
|
|
17
|
+
getTemplate(): import("lit-html").TemplateResult<1>;
|
|
18
|
+
protected updated(props: PropertyValues): void;
|
|
19
|
+
private fetchSessions;
|
|
20
|
+
private getData;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=ft-analytics-sessions-chart.d.ts.map
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { css, html } from 'lit';
|
|
8
|
+
import { property, state } from 'lit/decorators.js';
|
|
9
|
+
import { customElement, FtLitElement } from '@fluid-topics/ft-wc-utils';
|
|
10
|
+
import * as moment from 'moment';
|
|
11
|
+
import { Period } from '@fluid-topics/ft-chart';
|
|
12
|
+
let FtAnalyticsSessionsChart = class FtAnalyticsSessionsChart extends FtLitElement {
|
|
13
|
+
constructor() {
|
|
14
|
+
super(...arguments);
|
|
15
|
+
this.baseUrl = '';
|
|
16
|
+
this.period = Period.MONTH;
|
|
17
|
+
this.startDate = moment.utc().startOf('month').add(-3, 'months').format('YYYY-MM-DD');
|
|
18
|
+
this.endDate = moment.utc().startOf('month').format('YYYY-MM-DD');
|
|
19
|
+
this.data = [];
|
|
20
|
+
}
|
|
21
|
+
getStyles() {
|
|
22
|
+
// language=CSS
|
|
23
|
+
return css `
|
|
24
|
+
.session-chart {
|
|
25
|
+
width: 100%;
|
|
26
|
+
height: 400px;
|
|
27
|
+
}
|
|
28
|
+
`;
|
|
29
|
+
}
|
|
30
|
+
getTemplate() {
|
|
31
|
+
return html `
|
|
32
|
+
<div class="session-chart">
|
|
33
|
+
<ft-chart
|
|
34
|
+
xAxisName="date"
|
|
35
|
+
yAxisName="sessions"
|
|
36
|
+
valueLabels="${JSON.stringify(['sessions opened'])}"
|
|
37
|
+
valueLabelsSingular="${JSON.stringify(['session opened'])}"
|
|
38
|
+
barChart
|
|
39
|
+
period="${this.period}"
|
|
40
|
+
data="${JSON.stringify(this.data)}"
|
|
41
|
+
></ft-chart>
|
|
42
|
+
</div>
|
|
43
|
+
`;
|
|
44
|
+
}
|
|
45
|
+
updated(props) {
|
|
46
|
+
super.updated(props);
|
|
47
|
+
if (props.has('baseUrl')) {
|
|
48
|
+
this.fetchSessions();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async fetchSessions() {
|
|
52
|
+
if (this.baseUrl) {
|
|
53
|
+
let response = await fetch(this.baseUrl + `/analytics/api/v2/traffic/sessions`, {
|
|
54
|
+
method: 'POST',
|
|
55
|
+
headers: {
|
|
56
|
+
'Content-Type': 'application/json'
|
|
57
|
+
},
|
|
58
|
+
body: JSON.stringify({
|
|
59
|
+
endDate: this.endDate,
|
|
60
|
+
groupByPeriod: this.period.toLowerCase(),
|
|
61
|
+
startDate: this.startDate
|
|
62
|
+
})
|
|
63
|
+
});
|
|
64
|
+
if (response.ok) {
|
|
65
|
+
let results = (await response.json()).results;
|
|
66
|
+
this.data = this.getData(results);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
console.log((await response.json()).message);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
getData(results) {
|
|
74
|
+
return results.map(dot => [moment.utc(dot.periodStartDate, 'YYYY-MM-DD').unix(), dot.sessionCount]);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
__decorate([
|
|
78
|
+
property({ type: String })
|
|
79
|
+
], FtAnalyticsSessionsChart.prototype, "baseUrl", void 0);
|
|
80
|
+
__decorate([
|
|
81
|
+
property({ type: String })
|
|
82
|
+
], FtAnalyticsSessionsChart.prototype, "period", void 0);
|
|
83
|
+
__decorate([
|
|
84
|
+
property({ type: String })
|
|
85
|
+
], FtAnalyticsSessionsChart.prototype, "startDate", void 0);
|
|
86
|
+
__decorate([
|
|
87
|
+
property({ type: String })
|
|
88
|
+
], FtAnalyticsSessionsChart.prototype, "endDate", void 0);
|
|
89
|
+
__decorate([
|
|
90
|
+
state()
|
|
91
|
+
], FtAnalyticsSessionsChart.prototype, "data", void 0);
|
|
92
|
+
FtAnalyticsSessionsChart = __decorate([
|
|
93
|
+
customElement('ft-analytics-sessions-chart')
|
|
94
|
+
], FtAnalyticsSessionsChart);
|
|
95
|
+
export { FtAnalyticsSessionsChart };
|
|
96
|
+
//# sourceMappingURL=ft-analytics-sessions-chart.js.map
|