@nuxtseo/pro-search 0.0.0-stage → 0.1.11
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 +7 -2
- package/app/components/BingSearchPerformance.vue +201 -0
- package/app/components/RankedSearchRow.vue +46 -0
- package/app/components/RankedSearchTable.vue +94 -0
- package/app/components/SearchConsoleTrend.vue +669 -0
- package/app/components/search-trend.ts +52 -0
- package/nuxt.config.ts +6 -0
- package/package.json +45 -3
- package/shared/bing-performance.ts +31 -0
- package/shared/compare-align.ts +123 -0
- package/shared/navigation.ts +14 -0
- package/shared/ranked-search.ts +7 -0
- package/shared/search-console-trend.ts +44 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { formatPercent } from '@nuxtseo/design-system/app/composables/formatting'
|
|
2
|
+
|
|
3
|
+
export type GscTrendDisplay
|
|
4
|
+
= | { _tag: 'none' }
|
|
5
|
+
| { _tag: 'from_zero', label: string, title: string }
|
|
6
|
+
| { _tag: 'low_volume', label: string, title: string }
|
|
7
|
+
| { _tag: 'percent', label: string, title: string }
|
|
8
|
+
|
|
9
|
+
interface GscTrendInput {
|
|
10
|
+
current: number
|
|
11
|
+
previous: number | null
|
|
12
|
+
changePercent: number | null
|
|
13
|
+
volumeFloor?: number
|
|
14
|
+
volumeLabel?: string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function resolveGscTrendDisplay({
|
|
18
|
+
current,
|
|
19
|
+
previous,
|
|
20
|
+
changePercent,
|
|
21
|
+
volumeFloor = 0,
|
|
22
|
+
volumeLabel = 'clicks',
|
|
23
|
+
}: GscTrendInput): GscTrendDisplay {
|
|
24
|
+
if (previous == null)
|
|
25
|
+
return { _tag: 'none' }
|
|
26
|
+
|
|
27
|
+
if (previous === 0 && current > 0) {
|
|
28
|
+
return {
|
|
29
|
+
_tag: 'from_zero',
|
|
30
|
+
label: 'from 0',
|
|
31
|
+
title: 'No comparison value in the previous period',
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (changePercent == null || changePercent === 0)
|
|
36
|
+
return { _tag: 'none' }
|
|
37
|
+
|
|
38
|
+
if (volumeFloor > 0 && Math.max(Math.abs(current), Math.abs(previous)) < volumeFloor) {
|
|
39
|
+
return {
|
|
40
|
+
_tag: 'low_volume',
|
|
41
|
+
label: 'low volume',
|
|
42
|
+
title: `Percentage hidden below ${volumeFloor} ${volumeLabel}`,
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const label = formatPercent(changePercent)
|
|
47
|
+
return {
|
|
48
|
+
_tag: 'percent',
|
|
49
|
+
label,
|
|
50
|
+
title: `${changePercent > 0 ? 'Up' : 'Down'} ${formatPercent(Math.abs(changePercent)).replace('+', '')} from the previous period`,
|
|
51
|
+
}
|
|
52
|
+
}
|
package/nuxt.config.ts
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,48 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxtseo/pro-search",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.1.11",
|
|
5
|
+
"description": "Shared Search Console and Webmaster Tools views for Nuxt dashboards.",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./nuxt.config.ts",
|
|
9
|
+
"./components/*.vue": "./app/components/*.vue",
|
|
10
|
+
"./components/*": "./app/components/*.ts",
|
|
11
|
+
"./shared/*": "./shared/*.ts",
|
|
12
|
+
"./package.json": "./package.json"
|
|
13
|
+
},
|
|
14
|
+
"main": "./nuxt.config.ts",
|
|
15
|
+
"files": [
|
|
16
|
+
"app",
|
|
17
|
+
"nuxt.config.ts",
|
|
18
|
+
"shared"
|
|
19
|
+
],
|
|
20
|
+
"peerDependencies": {
|
|
21
|
+
"@gscdump/contracts": "^7.16.0",
|
|
22
|
+
"@gscdump/sdk": "^7.16.0",
|
|
23
|
+
"@nuxtseo/design-system": "^0.1.11",
|
|
24
|
+
"@vueuse/core": "^14.0.0 || ^15.0.0",
|
|
25
|
+
"nuxt": "^4.6.0",
|
|
26
|
+
"vue": "^3.5.0"
|
|
27
|
+
},
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@unovis/ts": "^1.6.7",
|
|
33
|
+
"@unovis/vue": "^1.6.7"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@gscdump/contracts": "7.18.0",
|
|
37
|
+
"@gscdump/sdk": "7.18.0",
|
|
38
|
+
"@nuxtseo/design-system": "0.1.11",
|
|
39
|
+
"@vueuse/core": "^14.4.0",
|
|
40
|
+
"nuxt": "4.6.1",
|
|
41
|
+
"site-typecheck": "0.0.0",
|
|
42
|
+
"vue": "^3.5.43"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"nuxt:prepare": "nuxt prepare",
|
|
46
|
+
"typecheck": "nuxt prepare && site-typecheck -b --noEmit --force"
|
|
47
|
+
}
|
|
6
48
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { BingDataV1 } from '@gscdump/contracts/v1/http'
|
|
2
|
+
|
|
3
|
+
export type BingEntityKind = 'pages' | 'keywords'
|
|
4
|
+
export const BING_PERFORMANCE_PAGE_SIZE = 10
|
|
5
|
+
|
|
6
|
+
const bingNumberFormat = new Intl.NumberFormat('en-US', { notation: 'compact', maximumFractionDigits: 1 })
|
|
7
|
+
const bingCtrFormat = new Intl.NumberFormat('en-US', { style: 'percent', minimumFractionDigits: 1, maximumFractionDigits: 1 })
|
|
8
|
+
const bingReportingDayFormat = new Intl.DateTimeFormat('en-US', { month: 'short', day: 'numeric', timeZone: 'UTC' })
|
|
9
|
+
|
|
10
|
+
export function formatBingNumber(value: number): string {
|
|
11
|
+
return bingNumberFormat.format(value)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function formatBingCtr(value: number): string {
|
|
15
|
+
return bingCtrFormat.format(value)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function formatBingReportingDay(day: string): string {
|
|
19
|
+
return bingReportingDayFormat.format(new Date(`${day}T00:00:00Z`))
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function bingTrafficTotals(rows: Extract<BingDataV1, { dataset: 'traffic' }>['rows']) {
|
|
23
|
+
const totals = rows.reduce((sum, row) => ({
|
|
24
|
+
clicks: sum.clicks + row.clicks,
|
|
25
|
+
impressions: sum.impressions + row.impressions,
|
|
26
|
+
}), { clicks: 0, impressions: 0 })
|
|
27
|
+
return {
|
|
28
|
+
...totals,
|
|
29
|
+
ctr: totals.impressions === 0 ? 0 : totals.clicks / totals.impressions,
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import type { CompareMode } from '@gscdump/sdk/period'
|
|
2
|
+
|
|
3
|
+
// Aligning a comparison overlay means pairing each current-period day with its
|
|
4
|
+
// counterpart in the compare window. The right counterpart depends on the
|
|
5
|
+
// compare mode:
|
|
6
|
+
// - 'previous' → the SAME ordinal day of the preceding window, i.e. a fixed
|
|
7
|
+
// whole-day offset back (period length). Calendar-day matching is wrong here
|
|
8
|
+
// (the prev window is days, not a year, away).
|
|
9
|
+
// - 'year' → the SAME calendar day one year earlier (Feb 15 → Feb 15), which a
|
|
10
|
+
// fixed day offset can't express exactly across a leap boundary.
|
|
11
|
+
// Deriving the offset from the WINDOW DEFINITION (not the data) keeps alignment
|
|
12
|
+
// correct even when the compare window's most recent day has no rows.
|
|
13
|
+
|
|
14
|
+
const DAY_MS = 86_400_000
|
|
15
|
+
|
|
16
|
+
export function toUtcDay(s: string): number {
|
|
17
|
+
const [y = 0, m = 1, d = 1] = s.split('-').map(Number)
|
|
18
|
+
return Date.UTC(y, m - 1, d)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function fromUtcDay(ms: number): string {
|
|
22
|
+
const dt = new Date(ms)
|
|
23
|
+
return `${dt.getUTCFullYear()}-${String(dt.getUTCMonth() + 1).padStart(2, '0')}-${String(dt.getUTCDate()).padStart(2, '0')}`
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Maps a current ISO date (`YYYY-MM-DD`) to its compare-period counterpart. */
|
|
27
|
+
export type CompareAligner = (currentDate: string) => string
|
|
28
|
+
|
|
29
|
+
/** Same calendar day one year earlier — exact for year-over-year (no leap drift). */
|
|
30
|
+
export function calendarYearAligner(): CompareAligner {
|
|
31
|
+
return (date) => {
|
|
32
|
+
const [y, m, d] = date.split('-')
|
|
33
|
+
return `${Number(y) - 1}-${m}-${d}`
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Fixed whole-day shift back — correct for the immediately-preceding period. */
|
|
38
|
+
export function offsetAligner(offsetDays: number): CompareAligner {
|
|
39
|
+
return date => fromUtcDay(toUtcDay(date) - offsetDays * DAY_MS)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Pick the aligner for a compare mode. `'year'` uses calendar matching;
|
|
44
|
+
* everything else uses the fixed `offsetDays`. Returns `null` when there is no
|
|
45
|
+
* usable strategy (no comparison, or `'previous'` with an unknown offset), in
|
|
46
|
+
* which case `alignPrev` leaves rows un-paired.
|
|
47
|
+
*/
|
|
48
|
+
export function resolveCompareAligner(mode: CompareMode | undefined, offsetDays: number | null): CompareAligner | null {
|
|
49
|
+
if (mode === 'year')
|
|
50
|
+
return calendarYearAligner()
|
|
51
|
+
if (offsetDays != null)
|
|
52
|
+
return offsetAligner(offsetDays)
|
|
53
|
+
return null
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Fallback offset when no window definition is available: anchor on the most
|
|
58
|
+
* recent day of each series (most likely populated; `stableData` lands the end
|
|
59
|
+
* on a complete day). Less robust than the window-derived offset — a compare
|
|
60
|
+
* window whose last day has no rows skews it — so prefer `computeCompareOffsetDays`.
|
|
61
|
+
*/
|
|
62
|
+
export function anchorOffsetDays(current: { date: string }[], prev: { date: string }[]): number | null {
|
|
63
|
+
const lastCur = current.at(-1)
|
|
64
|
+
const lastPrev = prev.at(-1)
|
|
65
|
+
if (!lastCur || !lastPrev)
|
|
66
|
+
return null
|
|
67
|
+
return Math.round((toUtcDay(lastCur.date) - toUtcDay(lastPrev.date)) / DAY_MS)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Merge prev rows onto current rows by date, using `aligner` to find each
|
|
72
|
+
* current day's counterpart. A current day with no matching prev row is left
|
|
73
|
+
* un-paired (the overlay simply has no point there — correct for gaps).
|
|
74
|
+
*/
|
|
75
|
+
export function alignPrev<C extends { date: string }, P extends { date: string }>(
|
|
76
|
+
current: C[],
|
|
77
|
+
prev: P[] | null | undefined,
|
|
78
|
+
aligner: CompareAligner | null,
|
|
79
|
+
): Array<C & { prev?: P }> {
|
|
80
|
+
if (!current.length)
|
|
81
|
+
return []
|
|
82
|
+
if (!prev?.length || !aligner)
|
|
83
|
+
return current.slice()
|
|
84
|
+
const byDate = new Map<string, P>()
|
|
85
|
+
for (const row of prev) byDate.set(row.date, row)
|
|
86
|
+
return current.map((row) => {
|
|
87
|
+
const match = byDate.get(aligner(row.date))
|
|
88
|
+
return match ? { ...row, prev: match } : row
|
|
89
|
+
})
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
interface CalendarChartRow {
|
|
93
|
+
date: string
|
|
94
|
+
clicks: number
|
|
95
|
+
impressions: number
|
|
96
|
+
position: number
|
|
97
|
+
ctr: number
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Keep elapsed reporting days without inventing observations. */
|
|
101
|
+
export function calendarChartRows(rows: readonly CalendarChartRow[], dateRange?: { start: string, end: string }): CalendarChartRow[] {
|
|
102
|
+
if (!rows.length)
|
|
103
|
+
return []
|
|
104
|
+
const byDate = new Map(rows.map(row => [row.date, row]))
|
|
105
|
+
const dates = [...byDate.keys()].sort()
|
|
106
|
+
const start = toUtcDay(dateRange?.start ?? dates[0]!)
|
|
107
|
+
const end = toUtcDay(dateRange?.end ?? dates.at(-1)!)
|
|
108
|
+
const days = Math.round((end - start) / DAY_MS) + 1
|
|
109
|
+
return Array.from({ length: days }, (_, index) => {
|
|
110
|
+
const date = fromUtcDay(start + index * DAY_MS)
|
|
111
|
+
return byDate.get(date) ?? { date, clicks: Number.NaN, impressions: Number.NaN, position: Number.NaN, ctr: Number.NaN }
|
|
112
|
+
})
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Scatter accessors receive a series index, so identify isolated days by date. */
|
|
116
|
+
export function isolatedChartValue<T extends { date: string }>(rows: readonly T[], value: (row: T) => number): (row: T) => number {
|
|
117
|
+
const values = rows.map(value)
|
|
118
|
+
const dates = new Set(rows.flatMap((row, index) => Number.isFinite(values[index])
|
|
119
|
+
&& !Number.isFinite(values[index - 1]) && !Number.isFinite(values[index + 1])
|
|
120
|
+
? [row.date]
|
|
121
|
+
: []))
|
|
122
|
+
return row => dates.has(row.date) ? value(row) : Number.NaN
|
|
123
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const SEARCH_CONSOLE = {
|
|
2
|
+
label: 'Search Console',
|
|
3
|
+
icon: 'google',
|
|
4
|
+
} as const
|
|
5
|
+
|
|
6
|
+
export const WEBMASTER_TOOLS = {
|
|
7
|
+
label: 'Webmaster Tools',
|
|
8
|
+
icon: 'bing',
|
|
9
|
+
} as const
|
|
10
|
+
|
|
11
|
+
export const WEBMASTER_TOOLS_TABS = [
|
|
12
|
+
{ label: 'Performance', path: '' },
|
|
13
|
+
{ label: 'Crawl', path: '/crawl' },
|
|
14
|
+
] as const
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { CompareMode } from '@gscdump/sdk/period'
|
|
2
|
+
|
|
3
|
+
export interface SearchConsoleTrendDay {
|
|
4
|
+
date: string
|
|
5
|
+
clicks: number
|
|
6
|
+
impressions: number
|
|
7
|
+
position: number
|
|
8
|
+
ctr: number
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type SearchConsoleTrendFailure
|
|
12
|
+
= | { _tag: 'property-unavailable' }
|
|
13
|
+
| { _tag: 'read-failed', message: string }
|
|
14
|
+
|
|
15
|
+
export interface SearchConsoleTrendProps {
|
|
16
|
+
value: SearchConsoleTrendDay[]
|
|
17
|
+
/** Requested reporting days, including unknown days at either edge. */
|
|
18
|
+
dateRange?: { start: string, end: string }
|
|
19
|
+
prevValue: SearchConsoleTrendDay[] | null
|
|
20
|
+
columns?: string[]
|
|
21
|
+
height?: number | string
|
|
22
|
+
/** Show loading skeleton */
|
|
23
|
+
loading?: boolean
|
|
24
|
+
/**
|
|
25
|
+
* Full (unzoomed) current series. When provided, y-domains are computed against this
|
|
26
|
+
* so zoomed views stay anchored to the full period's scale.
|
|
27
|
+
*/
|
|
28
|
+
fullValue?: SearchConsoleTrendDay[]
|
|
29
|
+
/** Full (unzoomed) previous series, paired with fullValue. */
|
|
30
|
+
fullPrevValue?: SearchConsoleTrendDay[] | null
|
|
31
|
+
/**
|
|
32
|
+
* Compare mode driving overlay alignment — `'year'` matches by calendar day,
|
|
33
|
+
* everything else by `compareOffsetDays`.
|
|
34
|
+
*/
|
|
35
|
+
compareMode?: CompareMode
|
|
36
|
+
/**
|
|
37
|
+
* Whole-day offset between the current and compare windows (authoritative,
|
|
38
|
+
* window-derived). When omitted, the overlay anchors on the most recent day of
|
|
39
|
+
* each series instead.
|
|
40
|
+
*/
|
|
41
|
+
compareOffsetDays?: number | null
|
|
42
|
+
failure?: SearchConsoleTrendFailure | null
|
|
43
|
+
connectionTo?: string
|
|
44
|
+
}
|