Skip to content

Commit

Permalink
Added graph to stats page for os (#22291)
Browse files Browse the repository at this point in the history
ref https://linear.app/ghost/issue/ANAL-128/
- added a chart for OS to the technical section on the stats page
  • Loading branch information
9larsons authored Feb 26, 2025
1 parent b0cb64b commit 41ccf1e
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 14 deletions.
20 changes: 15 additions & 5 deletions ghost/admin/app/components/stats/charts/technical.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@ export default class TechnicalComponent extends Component {
updateQueryParams(params) {
const currentRoute = this.router.currentRoute;
const newQueryParams = {...currentRoute.queryParams, ...params};

this.router.transitionTo({queryParams: newQueryParams});
}

ReactComponent = (props) => {
const {selected} = props;
const {selected, apiVersion} = props;

// If OS is selected but not available, switch to devices
let effectiveSelected = selected;
if (selected === 'os' && (!apiVersion || apiVersion < 1)) {
effectiveSelected = 'devices';
}

const colorPalette = statsStaticColors.slice(0, 5);

Expand All @@ -41,14 +46,19 @@ export default class TechnicalComponent extends Component {
let indexBy;
let tableHead;

switch (selected) {
switch (effectiveSelected) {
case 'browsers':
endpoint = `${this.config.stats.endpoint}/v0/pipes/top_browsers__v${props.apiVersion || TB_VERSION}.json`;
endpoint = `${this.config.stats.endpoint}/v0/pipes/top_browsers__v${apiVersion || TB_VERSION}.json`;
indexBy = 'browser';
tableHead = 'Browser';
break;
case 'os':
endpoint = `${this.config.stats.endpoint}/v0/pipes/top_os__v${apiVersion || TB_VERSION}.json`;
indexBy = 'os';
tableHead = 'OS';
break;
default:
endpoint = `${this.config.stats.endpoint}/v0/pipes/top_devices__v${props.apiVersion || TB_VERSION}.json`;
endpoint = `${this.config.stats.endpoint}/v0/pipes/top_devices__v${apiVersion || TB_VERSION}.json`;
indexBy = 'device';
tableHead = 'Device';
}
Expand Down
10 changes: 6 additions & 4 deletions ghost/admin/app/components/stats/technical-overview.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
@label="Browsers" />
</button>

{{!-- <button type="button" class="gh-stats-tab {{if this.osTabSelected 'is-selected'}}" {{on "click" this.changeTabToOSs}}>
<Stats::Parts::Metric
@label="Operating systems" />
</button> --}}
{{#if (gt @apiVersion 0)}}
<button type="button" class="gh-stats-tab {{if this.osTabSelected 'is-selected'}}" {{on "click" this.changeTabToOSs}}>
<Stats::Parts::Metric
@label="OS" />
</button>
{{/if}}
</div>
</div>

Expand Down
6 changes: 3 additions & 3 deletions ghost/admin/app/components/stats/technical-overview.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ export default class TechnicalOverview extends Component {
}

get devicesTabSelected() {
return (this.selected === 'devices');
return this.selected === 'devices';
}

get browsersTabSelected() {
return (this.selected === 'browsers');
return this.selected === 'browsers';
}

get osTabSelected() {
return (this.selected === 'os');
return this.selected === 'os';
}
}
4 changes: 3 additions & 1 deletion ghost/admin/app/controllers/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import {tracked} from '@glimmer/tracking';
countries.registerLocale(enLocale);

export default class StatsController extends Controller {
queryParams = ['device', 'browser', 'location', 'source', 'pathname', 'apiVersion'];
queryParams = ['device', 'browser', 'location', 'source', 'pathname', 'os'];

@tracked device = null;
@tracked browser = null;
@tracked location = null;
@tracked source = null;
@tracked pathname = null;
@tracked os = null;
@tracked apiVersion = 0;

rangeOptions = RANGE_OPTIONS;
Expand Down Expand Up @@ -74,6 +75,7 @@ export default class StatsController extends Controller {
this.location = null;
this.source = null;
this.pathname = null;
this.os = null;
}

get selectedRangeOption() {
Expand Down
5 changes: 5 additions & 0 deletions ghost/admin/app/templates/stats.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
@location={{this.location}}
@source={{this.source}}
@pathname={{this.pathname}}
@os={{this.os}}
@apiVersion={{this.apiVersion}}
/>
</section>
Expand All @@ -101,6 +102,7 @@
@location={{this.location}}
@source={{this.source}}
@pathname={{this.pathname}}
@os={{this.os}}
@apiVersion={{this.apiVersion}}
/>
</div>
Expand All @@ -113,6 +115,7 @@
@location={{this.location}}
@source={{this.source}}
@pathname={{this.pathname}}
@os={{this.os}}
@apiVersion={{this.apiVersion}}
/>
</div>
Expand All @@ -128,6 +131,7 @@
@location={{this.location}}
@source={{this.source}}
@pathname={{this.pathname}}
@os={{this.os}}
@apiVersion={{this.apiVersion}}
/>
</div>
Expand All @@ -140,6 +144,7 @@
@location={{this.location}}
@source={{this.source}}
@pathname={{this.pathname}}
@os={{this.os}}
@apiVersion={{this.apiVersion}}
/>
</div>
Expand Down
6 changes: 5 additions & 1 deletion ghost/admin/app/utils/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export function getDateRange(chartRange) {
}

export function getStatsParams(config, props, additionalParams = {}) {
const {chartRange, audience, device, browser, location, source, pathname} = props;
const {chartRange, audience, device, browser, location, source, pathname, os} = props;
const {startDate, endDate} = getDateRange(chartRange);

const params = {
Expand Down Expand Up @@ -179,5 +179,9 @@ export function getStatsParams(config, props, additionalParams = {}) {
params.pathname = pathname;
}

if (os) {
params.os = os;
}

return params;
}

0 comments on commit 41ccf1e

Please sign in to comment.