@@ -82,6 +82,24 @@ export async function fetchGoogleAnalyticsData() {
8282 '/couchbase-edge-server/' ,
8383 ]
8484
85+ // SDK paths for comparison
86+ const sdkPaths = [
87+ '/dotnet-sdk/' ,
88+ '/efcore-provider/' ,
89+ '/c-sdk/' ,
90+ '/cxx-sdk/' ,
91+ '/go-sdk/' ,
92+ '/java-sdk/' ,
93+ '/quarkus-extension/' ,
94+ '/kotlin-sdk/' ,
95+ '/nodejs-sdk/' ,
96+ '/php-sdk/' ,
97+ '/python-sdk/' ,
98+ '/ruby-sdk/' ,
99+ '/rust-sdk/' ,
100+ '/scala-sdk/' ,
101+ ]
102+
85103 const topPagesByPath = await Promise . all (
86104 documentationPaths . map ( async ( path ) => {
87105 try {
@@ -354,6 +372,93 @@ export async function fetchGoogleAnalyticsData() {
354372
355373 console . log ( ` ✅ Fetched metrics for ${ pathMetrics . length } documentation paths` )
356374
375+ // Fetch metrics for each SDK path
376+ const sdkMetrics = await Promise . all (
377+ sdkPaths . map ( async ( path ) => {
378+ try {
379+ // Fetch page views for this SDK path
380+ const [ pathViewsResponse ] = await analyticsDataClient . runReport ( {
381+ property : `properties/${ propertyId } ` ,
382+ dateRanges : [ { startDate : '30daysAgo' , endDate : 'today' } ] ,
383+ dimensions : [ { name : 'pagePath' } ] ,
384+ metrics : [ { name : 'screenPageViews' } ] ,
385+ dimensionFilter : {
386+ filter : {
387+ fieldName : 'pagePath' ,
388+ stringFilter : { matchType : 'BEGINS_WITH' , value : path } ,
389+ } ,
390+ } ,
391+ } )
392+
393+ // Fetch session metrics for this SDK path
394+ const [ pathSessionResponse ] = await analyticsDataClient . runReport ( {
395+ property : `properties/${ propertyId } ` ,
396+ dateRanges : [ { startDate : '30daysAgo' , endDate : 'today' } ] ,
397+ metrics : [
398+ { name : 'sessions' } ,
399+ { name : 'bounceRate' } ,
400+ { name : 'averageSessionDuration' } ,
401+ ] ,
402+ dimensionFilter : {
403+ filter : {
404+ fieldName : 'pagePath' ,
405+ stringFilter : { matchType : 'BEGINS_WITH' , value : path } ,
406+ } ,
407+ } ,
408+ } )
409+
410+ // Fetch traffic sources for this SDK path
411+ const [ pathTrafficResponse ] = await analyticsDataClient . runReport ( {
412+ property : `properties/${ propertyId } ` ,
413+ dateRanges : [ { startDate : '30daysAgo' , endDate : 'today' } ] ,
414+ dimensions : [ { name : 'sessionDefaultChannelGroup' } ] ,
415+ metrics : [ { name : 'sessions' } ] ,
416+ dimensionFilter : {
417+ filter : {
418+ fieldName : 'pagePath' ,
419+ stringFilter : { matchType : 'BEGINS_WITH' , value : path } ,
420+ } ,
421+ } ,
422+ } )
423+
424+ const totalViews = pathViewsResponse . rows ?. reduce ( ( sum , row ) => sum + parseInt ( row . metricValues [ 0 ] . value ) , 0 ) || 0
425+ const bounceRate = pathSessionResponse . rows ?. [ 0 ] ?. metricValues [ 1 ] ?. value || '0'
426+ const avgSessionDuration = pathSessionResponse . rows ?. [ 0 ] ?. metricValues [ 2 ] ?. value || '0'
427+
428+ // Calculate traffic balance
429+ const trafficData = pathTrafficResponse . rows || [ ]
430+ const totalSessions = trafficData . reduce ( ( sum , row ) => sum + parseInt ( row . metricValues [ 0 ] . value ) , 0 )
431+ const directSessions = trafficData . find ( row => row . dimensionValues [ 0 ] . value === 'Direct' ) ?. metricValues [ 0 ] ?. value || 0
432+ const searchSessions = trafficData . find ( row => row . dimensionValues [ 0 ] . value === 'Organic Search' ) ?. metricValues [ 0 ] ?. value || 0
433+
434+ const directPercentage = totalSessions > 0 ? Math . round ( ( directSessions / totalSessions ) * 100 ) : 0
435+ const searchPercentage = totalSessions > 0 ? Math . round ( ( searchSessions / totalSessions ) * 100 ) : 0
436+
437+ return {
438+ displayPath : path ,
439+ totalViews,
440+ bounceRate : parseFloat ( bounceRate ) . toFixed ( 1 ) ,
441+ avgSessionDuration : formatDuration ( parseFloat ( avgSessionDuration ) ) ,
442+ trafficBalance : {
443+ direct : directPercentage ,
444+ search : searchPercentage ,
445+ } ,
446+ }
447+ } catch ( error ) {
448+ console . warn ( ` ⚠️ Failed to fetch metrics for ${ path } :` , error . message )
449+ return {
450+ displayPath : path ,
451+ totalViews : 0 ,
452+ bounceRate : 0 ,
453+ avgSessionDuration : '0:00' ,
454+ trafficBalance : { direct : 0 , search : 0 } ,
455+ }
456+ }
457+ } )
458+ )
459+
460+ console . log ( ` ✅ Fetched metrics for ${ sdkMetrics . length } SDK paths` )
461+
357462 // Process responses into dashboard format
358463 const daily = pageViewsResponse . rows . map ( row => ( {
359464 date : row . dimensionValues [ 0 ] . value . replace ( / ( \d { 4 } ) ( \d { 2 } ) ( \d { 2 } ) / , '$1-$2-$3' ) ,
@@ -410,6 +515,7 @@ export async function fetchGoogleAnalyticsData() {
410515 { device : 'Tablet' , percentage : 6 } ,
411516 ] , // Requires additional query
412517 pathComparison : pathMetrics ,
518+ sdkComparison : sdkMetrics ,
413519 }
414520 } catch ( error ) {
415521 console . error ( '❌ Error fetching GA data:' , error . message )
0 commit comments