Skip to content

Commit edb0bb7

Browse files
committed
changed trends data
1 parent 463a66d commit edb0bb7

5 files changed

Lines changed: 144 additions & 127 deletions

File tree

scripts/fetch-data.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ async function main() {
158158
console.warn('⚠️ Google Trends data not available')
159159
}
160160

161-
// If both failed, exit with error
162-
if (!analyticsData && !jiraData) {
161+
// If both failed, exit with error (but allow trends-only data)
162+
if (!analyticsData && !jiraData && !trendsData) {
163163
console.error('\n❌ Failed to fetch any data:')
164164
errors.forEach(e => console.error(` - ${e}`))
165165
process.exit(1)

scripts/fetch-trends.js

Lines changed: 90 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -3,120 +3,110 @@ import googleTrends from 'google-trends-api'
33
// Disable SSL verification for this module (temporary workaround)
44
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0'
55

6-
export async function fetchTrendsData() {
7-
console.log('🔍 Fetching Google Trends data...')
6+
async function fetchTrendsForKeyword(keyword) {
7+
console.log(` 🔍 Fetching trends for "${keyword}"...`)
88

9-
try {
10-
const keyword = 'couchbase'
11-
const endDate = new Date()
12-
const startDate = new Date()
13-
startDate.setFullYear(startDate.getFullYear() - 1) // Last 12 months
9+
const endDate = new Date()
10+
const startDate = new Date()
11+
startDate.setFullYear(startDate.getFullYear() - 1) // Last 12 months
1412

15-
// Fetch interest over time
16-
console.log(' 📈 Fetching interest over time...')
17-
const interestOverTimeResponse = await googleTrends.interestOverTime({
18-
keyword: keyword,
19-
startTime: startDate,
20-
endTime: endDate,
21-
geo: 'US', // Focus on US market
22-
granularTimeResolution: true
23-
})
13+
// Fetch interest over time
14+
const interestOverTimeResponse = await googleTrends.interestOverTime({
15+
keyword: keyword,
16+
startTime: startDate,
17+
endTime: endDate,
18+
geo: 'US',
19+
granularTimeResolution: true
20+
})
2421

25-
console.log(' 📊 Parsing interest over time response...')
26-
const interestData = JSON.parse(interestOverTimeResponse)
27-
console.log(' 📊 Interest data keys:', Object.keys(interestData))
28-
console.log(' 📊 Default keys:', interestData.default ? Object.keys(interestData.default) : 'No default key')
29-
30-
if (!interestData.default) {
31-
console.log(' 📊 Full response structure:', JSON.stringify(interestData, null, 2))
32-
throw new Error('Invalid response structure: missing default')
33-
}
34-
35-
if (!interestData.default.timelineData) {
36-
console.log(' 📊 Default content:', JSON.stringify(interestData.default, null, 2))
37-
throw new Error('Invalid response structure: missing default.timelineData')
38-
}
39-
40-
console.log(' 📊 Timeline data sample:', interestData.default.timelineData[0])
41-
42-
const timelineData = interestData.default.timelineData.map(item => ({
43-
date: item.time,
44-
value: item.value ? item.value[0] : 0,
45-
formattedTime: item.formattedTime
46-
}))
22+
const interestData = JSON.parse(interestOverTimeResponse)
23+
const timelineData = interestData.default.timelineData.map(item => ({
24+
date: item.time,
25+
value: item.value ? item.value[0] : 0,
26+
formattedTime: item.formattedTime
27+
}))
4728

48-
// Fetch related queries (top and rising)
49-
console.log(' 🔍 Fetching related queries...')
50-
const relatedQueriesResponse = await googleTrends.relatedQueries({
51-
keyword: keyword,
52-
startTime: startDate,
53-
endTime: endDate,
54-
geo: 'US'
55-
})
29+
// Fetch related queries (top and rising)
30+
const relatedQueriesResponse = await googleTrends.relatedQueries({
31+
keyword: keyword,
32+
startTime: startDate,
33+
endTime: endDate,
34+
geo: 'US'
35+
})
5636

57-
console.log(' 📊 Parsing related queries response...')
58-
const queriesData = JSON.parse(relatedQueriesResponse)
59-
console.log(' 📊 Queries data keys:', Object.keys(queriesData))
60-
console.log(' 📊 Has default:', !!queriesData.default)
61-
console.log(' 📊 Has rankedListList:', !!queriesData.default?.rankedListList)
62-
63-
if (!queriesData.default || !queriesData.default.rankedList) {
64-
console.log(' 📊 Full response structure:', JSON.stringify(queriesData, null, 2).substring(0, 500) + '...')
65-
throw new Error('Invalid queries response structure')
66-
}
67-
68-
// The structure is: rankedList[0].rankedKeyword is an array
69-
const topQueries = queriesData.default.rankedList[0]?.rankedKeyword?.map(item => ({
70-
query: item.query,
71-
value: item.formattedValue || item.traffic,
72-
hasData: item.hasData
73-
})).slice(0, 10) || []
37+
const queriesData = JSON.parse(relatedQueriesResponse)
38+
39+
const topQueries = queriesData.default.rankedList[0]?.rankedKeyword?.map(item => ({
40+
query: item.query,
41+
value: item.formattedValue || item.traffic,
42+
hasData: item.hasData
43+
})).slice(0, 10) || []
7444

75-
const risingQueries = queriesData.default.rankedList[1]?.rankedKeyword?.map(item => ({
76-
query: item.query,
77-
value: item.formattedValue || item.traffic,
78-
hasData: item.hasData
79-
})).slice(0, 10) || []
45+
const risingQueries = queriesData.default.rankedList[1]?.rankedKeyword?.map(item => ({
46+
query: item.query,
47+
value: item.formattedValue || item.traffic,
48+
hasData: item.hasData
49+
})).slice(0, 10) || []
8050

81-
console.log(` ✅ Parsed ${topQueries.length} top queries and ${risingQueries.length} rising queries`)
51+
console.log(` ✅ Fetched ${timelineData.length} timeline points, ${topQueries.length} top queries, ${risingQueries.length} rising queries`)
8252

83-
// Fetch interest by region
84-
console.log(' 🗺️ Fetching interest by region...')
85-
const interestByRegionResponse = await googleTrends.interestByRegion({
86-
keyword: keyword,
87-
startTime: startDate,
88-
endTime: endDate,
89-
geo: 'US',
90-
resolution: 'REGION'
91-
})
53+
return {
54+
keyword,
55+
timelineData,
56+
topQueries,
57+
risingQueries,
58+
summary: {
59+
avgInterest: timelineData.reduce((sum, item) => sum + item.value, 0) / timelineData.length,
60+
peakInterest: Math.max(...timelineData.map(item => item.value)),
61+
currentInterest: timelineData[timelineData.length - 1]?.value || 0,
62+
trendDirection: timelineData.length > 1
63+
? (timelineData[timelineData.length - 1].value > timelineData[timelineData.length - 2].value ? 'up' : 'down')
64+
: 'stable'
65+
}
66+
}
67+
}
9268

93-
const regionData = JSON.parse(interestByRegionResponse)
94-
const regionalInterest = regionData.default.geoMapData.map(item => ({
95-
region: item.geoName,
96-
value: item.value[0],
97-
hasData: item.hasData
98-
})).filter(item => item.hasData)
69+
export async function fetchTrendsData() {
70+
console.log('🔍 Fetching Google Trends data...')
71+
72+
try {
73+
// Fetch data for both keywords
74+
const [couchbaseData, couchbaseServerData] = await Promise.all([
75+
fetchTrendsForKeyword('couchbase'),
76+
fetchTrendsForKeyword('couchbase server')
77+
])
78+
79+
// Combine timeline data for comparison
80+
const combinedTimeline = couchbaseData.timelineData.map((item, index) => ({
81+
date: item.date,
82+
formattedTime: item.formattedTime,
83+
couchbase: item.value,
84+
couchbaseServer: couchbaseServerData.timelineData[index]?.value || 0
85+
}))
9986

100-
console.log(` ✅ Successfully fetched trends data for "${keyword}"`)
101-
console.log(` 📊 Timeline points: ${timelineData.length}`)
102-
console.log(` 🔍 Top queries: ${topQueries.length}`)
103-
console.log(` 📈 Rising queries: ${risingQueries.length}`)
104-
console.log(` 🗺️ Regions: ${regionalInterest.length}`)
87+
console.log(` ✅ Successfully fetched trends data for both keywords`)
88+
console.log(` 📊 Combined timeline points: ${combinedTimeline.length}`)
10589

10690
return {
107-
keyword,
10891
lastUpdated: new Date().toISOString(),
109-
interestOverTime: timelineData,
110-
topQueries: topQueries.slice(0, 10), // Top 10
111-
risingQueries: risingQueries.slice(0, 10), // Top 10 rising
112-
regionalInterest: regionalInterest,
92+
couchbase: {
93+
keyword: couchbaseData.keyword,
94+
topQueries: couchbaseData.topQueries,
95+
risingQueries: couchbaseData.risingQueries,
96+
summary: couchbaseData.summary
97+
},
98+
couchbaseServer: {
99+
keyword: couchbaseServerData.keyword,
100+
topQueries: couchbaseServerData.topQueries,
101+
risingQueries: couchbaseServerData.risingQueries,
102+
summary: couchbaseServerData.summary
103+
},
104+
interestOverTime: combinedTimeline,
113105
summary: {
114-
avgInterest: timelineData.reduce((sum, item) => sum + item.value, 0) / timelineData.length,
115-
peakInterest: Math.max(...timelineData.map(item => item.value)),
116-
currentInterest: timelineData[timelineData.length - 1]?.value || 0,
117-
trendDirection: timelineData.length > 1
118-
? (timelineData[timelineData.length - 1].value > timelineData[timelineData.length - 2].value ? 'up' : 'down')
119-
: 'stable'
106+
avgInterest: couchbaseData.summary.avgInterest,
107+
peakInterest: couchbaseData.summary.peakInterest,
108+
currentInterest: couchbaseData.summary.currentInterest,
109+
trendDirection: couchbaseData.summary.trendDirection
120110
}
121111
}
122112

src/App.jsx

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -286,29 +286,36 @@ function App() {
286286
{/* SEO Summary Metrics */}
287287
<SEOSummary data={trends} />
288288

289-
{/* Trends and Queries Row */}
290-
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
291-
<TrendsChart data={trends.interestOverTime} />
292-
<RegionalInterestChart data={trends.regionalInterest} />
293-
</div>
289+
{/* Full-width Trends Chart */}
290+
<TrendsChart data={trends.interestOverTime} />
294291

295-
{/* Queries Tables */}
292+
{/* Queries Tables - 2x2 Grid */}
296293
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
297294
<QueriesTable
298-
title="Top Queries"
299-
data={trends.topQueries}
295+
title="Top Queries - Couchbase"
296+
data={trends.couchbase.topQueries}
297+
type="top"
298+
/>
299+
<QueriesTable
300+
title="Rising Queries - Couchbase"
301+
data={trends.couchbase.risingQueries}
302+
type="rising"
303+
/>
304+
<QueriesTable
305+
title="Top Queries - Couchbase Server"
306+
data={trends.couchbaseServer.topQueries}
300307
type="top"
301308
/>
302309
<QueriesTable
303-
title="Rising Queries"
304-
data={trends.risingQueries}
310+
title="Rising Queries - Couchbase Server"
311+
data={trends.couchbaseServer.risingQueries}
305312
type="rising"
306313
/>
307314
</div>
308315

309316
{/* Last Updated */}
310317
<div className="text-center text-xs text-slate-500">
311-
Google Trends data for "{trends.keyword}" updated on {new Date(trends.lastUpdated).toLocaleString()}
318+
Google Trends data updated on {new Date(trends.lastUpdated).toLocaleString()}
312319
</div>
313320
</>
314321
) : (

src/components/charts/SEOSummary.jsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react'
2-
import { TrendingUp, TrendingDown, Minus, Search, MapPin, BarChart3 } from 'lucide-react'
2+
import { TrendingUp, TrendingDown, Minus, Search, BarChart3, Activity } from 'lucide-react'
33

44
export function SEOSummary({ data }) {
55
if (!data) {
@@ -41,7 +41,7 @@ export function SEOSummary({ data }) {
4141

4242
return (
4343
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4">
44-
{/* Current Interest */}
44+
{/* Current Interest - Couchbase */}
4545
<div className="bg-white rounded-xl shadow-sm border border-slate-200 p-6">
4646
<div className="flex items-center justify-between mb-2">
4747
<div className="p-2 bg-blue-100 rounded-lg">
@@ -54,7 +54,7 @@ export function SEOSummary({ data }) {
5454
<div className="text-2xl font-bold text-slate-900">
5555
{data.summary?.currentInterest || 0}
5656
</div>
57-
<div className="text-sm text-slate-600">Current Interest</div>
57+
<div className="text-sm text-slate-600">Couchbase Interest</div>
5858
<div className={`text-xs mt-1 ${getTrendColor(data.summary?.trendDirection)}`}>
5959
{data.summary?.trendDirection === 'up' ? 'Rising' :
6060
data.summary?.trendDirection === 'down' ? 'Declining' : 'Stable'}
@@ -93,19 +93,19 @@ export function SEOSummary({ data }) {
9393
</div>
9494
</div>
9595

96-
{/* Regional Coverage */}
96+
{/* Comparison Metric */}
9797
<div className="bg-white rounded-xl shadow-sm border border-slate-200 p-6">
9898
<div className="flex items-center justify-between mb-2">
9999
<div className="p-2 bg-green-100 rounded-lg">
100-
<MapPin className="w-5 h-5 text-green-600" />
100+
<Activity className="w-5 h-5 text-green-600" />
101101
</div>
102102
</div>
103103
<div className="text-2xl font-bold text-slate-900">
104-
{data.regionalInterest?.length || 0}
104+
2
105105
</div>
106-
<div className="text-sm text-slate-600">Regions</div>
106+
<div className="text-sm text-slate-600">Keywords Tracked</div>
107107
<div className="text-xs mt-1 text-slate-500">
108-
US states tracked
108+
Couchbase & Server
109109
</div>
110110
</div>
111111
</div>

src/components/charts/TrendsChart.jsx

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react'
2-
import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer } from 'recharts'
2+
import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer } from 'recharts'
33

44
export function TrendsChart({ data }) {
55
if (!data || data.length === 0) {
@@ -19,13 +19,14 @@ export function TrendsChart({ data }) {
1919
month: 'short',
2020
day: 'numeric'
2121
}),
22-
value: item.value,
22+
couchbase: item.couchbase,
23+
couchbaseServer: item.couchbaseServer,
2324
fullDate: item.formattedTime || item.date
2425
}))
2526

2627
return (
27-
<div className="bg-white rounded-xl shadow-sm border border-slate-200 p-6">
28-
<h3 className="text-lg font-semibold text-slate-900 mb-4">Interest Over Time</h3>
28+
<div className="bg-white rounded-xl shadow-sm border border-slate-200 p-6 lg:col-span-2">
29+
<h3 className="text-lg font-semibold text-slate-900 mb-4">Interest Over Time - Comparison</h3>
2930
<div className="h-64">
3031
<ResponsiveContainer width="100%" height="100%">
3132
<LineChart data={chartData}>
@@ -51,14 +52,19 @@ export function TrendsChart({ data }) {
5152
borderRadius: '8px',
5253
padding: '8px 12px'
5354
}}
54-
formatter={(value) => [`${value}`, 'Interest']}
55+
formatter={(value, name) => [
56+
value,
57+
name === 'couchbase' ? 'Couchbase' : 'Couchbase Server'
58+
]}
5559
labelFormatter={(label) => `Date: ${label}`}
5660
/>
61+
<Legend />
5762
<Line
5863
type="monotone"
59-
dataKey="value"
64+
dataKey="couchbase"
6065
stroke="#3b82f6"
6166
strokeWidth={2}
67+
name="Couchbase"
6268
dot={false}
6369
activeDot={{
6470
r: 4,
@@ -67,6 +73,20 @@ export function TrendsChart({ data }) {
6773
strokeWidth: 2
6874
}}
6975
/>
76+
<Line
77+
type="monotone"
78+
dataKey="couchbaseServer"
79+
stroke="#10b981"
80+
strokeWidth={2}
81+
name="Couchbase Server"
82+
dot={false}
83+
activeDot={{
84+
r: 4,
85+
fill: '#10b981',
86+
stroke: 'white',
87+
strokeWidth: 2
88+
}}
89+
/>
7090
</LineChart>
7191
</ResponsiveContainer>
7292
</div>

0 commit comments

Comments
 (0)