11import {
22 extractGoogleApiError ,
3+ type GoogleAnalyticsDimensionMetadata ,
34 type GoogleAnalyticsGetMetadataParams ,
45 type GoogleAnalyticsGetMetadataResponse ,
5- type GoogleAnalyticsMetadataField ,
6+ type GoogleAnalyticsMetricMetadata ,
67 normalizePropertyName ,
78 toBooleanParam ,
89} from '@/tools/google_analytics/types'
@@ -12,27 +13,39 @@ interface RawMetadataField {
1213 apiName ?: string
1314 uiName ?: string
1415 description ?: string
15- type ?: string
16- dataType ?: string
16+ category ?: string
1717 customDefinition ?: boolean
1818 deprecatedApiNames ?: string [ ]
1919}
2020
21- /**
22- * Normalizes a DimensionMetadata or MetricMetadata entry. Dimensions expose their
23- * value type as `dataType`, metrics as `type`; both land on a single `type` field.
24- */
25- function toMetadataField ( raw : RawMetadataField ) : GoogleAnalyticsMetadataField {
21+ interface RawMetricMetadata extends RawMetadataField {
22+ type ?: string
23+ expression ?: string
24+ }
25+
26+ function toBaseField ( raw : RawMetadataField ) {
2627 return {
2728 apiName : raw . apiName ?? '' ,
2829 uiName : raw . uiName ?? null ,
2930 description : raw . description ?? null ,
30- type : raw . type ?? raw . dataType ?? null ,
31+ category : raw . category ?? null ,
3132 customDefinition : raw . customDefinition ?? false ,
3233 deprecatedApiNames : raw . deprecatedApiNames ?? [ ] ,
3334 }
3435}
3536
37+ function toDimensionMetadata ( raw : RawMetadataField ) : GoogleAnalyticsDimensionMetadata {
38+ return toBaseField ( raw )
39+ }
40+
41+ function toMetricMetadata ( raw : RawMetricMetadata ) : GoogleAnalyticsMetricMetadata {
42+ return {
43+ ...toBaseField ( raw ) ,
44+ type : raw . type ?? null ,
45+ expression : raw . expression ?? null ,
46+ }
47+ }
48+
3649export const googleAnalyticsGetMetadataTool : ToolConfig <
3750 GoogleAnalyticsGetMetadataParams ,
3851 GoogleAnalyticsGetMetadataResponse
@@ -102,14 +115,14 @@ export const googleAnalyticsGetMetadataTool: ToolConfig<
102115 }
103116 }
104117
105- let dimensions = ( data . dimensions ?? [ ] ) . map ( toMetadataField )
106- let metrics = ( data . metrics ?? [ ] ) . map ( toMetadataField )
118+ let dimensions : GoogleAnalyticsDimensionMetadata [ ] = ( data . dimensions ?? [ ] ) . map (
119+ toDimensionMetadata
120+ )
121+ let metrics : GoogleAnalyticsMetricMetadata [ ] = ( data . metrics ?? [ ] ) . map ( toMetricMetadata )
107122
108123 if ( toBooleanParam ( params ?. customOnly ) ) {
109- dimensions = dimensions . filter (
110- ( field : GoogleAnalyticsMetadataField ) => field . customDefinition
111- )
112- metrics = metrics . filter ( ( field : GoogleAnalyticsMetadataField ) => field . customDefinition )
124+ dimensions = dimensions . filter ( ( field ) => field . customDefinition )
125+ metrics = metrics . filter ( ( field ) => field . customDefinition )
113126 }
114127
115128 return {
@@ -144,7 +157,11 @@ export const googleAnalyticsGetMetadataTool: ToolConfig<
144157 description : 'What the dimension measures' ,
145158 nullable : true ,
146159 } ,
147- type : { type : 'string' , description : 'Value data type' , nullable : true } ,
160+ category : {
161+ type : 'string' ,
162+ description : 'Grouping the dimension belongs to, e.g. Page / Screen' ,
163+ nullable : true ,
164+ } ,
148165 customDefinition : {
149166 type : 'boolean' ,
150167 description : 'Whether this is a property-specific custom dimension' ,
@@ -167,7 +184,17 @@ export const googleAnalyticsGetMetadataTool: ToolConfig<
167184 apiName : { type : 'string' , description : 'Name used in report requests' } ,
168185 uiName : { type : 'string' , description : 'Name shown in the GA4 UI' , nullable : true } ,
169186 description : { type : 'string' , description : 'What the metric measures' , nullable : true } ,
170- type : { type : 'string' , description : 'Value data type' , nullable : true } ,
187+ type : { type : 'string' , description : 'Metric value type' , nullable : true } ,
188+ expression : {
189+ type : 'string' ,
190+ description : 'Formula for a derived metric' ,
191+ nullable : true ,
192+ } ,
193+ category : {
194+ type : 'string' ,
195+ description : 'Grouping the metric belongs to, e.g. Session' ,
196+ nullable : true ,
197+ } ,
171198 customDefinition : {
172199 type : 'boolean' ,
173200 description : 'Whether this is a property-specific custom metric' ,
0 commit comments