@mastra/connect 0.6.0 → 0.7.0-alpha.0
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/dist/index.cjs +812 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +812 -0
- package/dist/index.js.map +1 -1
- package/dist/providers/google-analytics/index.d.ts +5 -0
- package/dist/providers/google-analytics/index.d.ts.map +1 -0
- package/dist/providers/google-analytics/tools/archive-conversion-event.d.ts +18 -0
- package/dist/providers/google-analytics/tools/archive-conversion-event.d.ts.map +1 -0
- package/dist/providers/google-analytics/tools/batch-run-reports.d.ts +137 -0
- package/dist/providers/google-analytics/tools/batch-run-reports.d.ts.map +1 -0
- package/dist/providers/google-analytics/tools/create-conversion-event.d.ts +44 -0
- package/dist/providers/google-analytics/tools/create-conversion-event.d.ts.map +1 -0
- package/dist/providers/google-analytics/tools/create-data-stream.d.ts +99 -0
- package/dist/providers/google-analytics/tools/create-data-stream.d.ts.map +1 -0
- package/dist/providers/google-analytics/tools/create-property.d.ts +46 -0
- package/dist/providers/google-analytics/tools/create-property.d.ts.map +1 -0
- package/dist/providers/google-analytics/tools/get-metadata.d.ts +44 -0
- package/dist/providers/google-analytics/tools/get-metadata.d.ts.map +1 -0
- package/dist/providers/google-analytics/tools/run-pivot-report.d.ts +51 -0
- package/dist/providers/google-analytics/tools/run-pivot-report.d.ts.map +1 -0
- package/dist/providers/google-analytics/tools/run-realtime-report.d.ts +150 -0
- package/dist/providers/google-analytics/tools/run-realtime-report.d.ts.map +1 -0
- package/dist/providers/google-analytics/tools/run-report.d.ts +140 -0
- package/dist/providers/google-analytics/tools/run-report.d.ts.map +1 -0
- package/dist/providers/google-analytics/tools/update-data-stream.d.ts +60 -0
- package/dist/providers/google-analytics/tools/update-data-stream.d.ts.map +1 -0
- package/dist/providers/google-analytics/tools/update-property.d.ts +34 -0
- package/dist/providers/google-analytics/tools/update-property.d.ts.map +1 -0
- package/dist/providers/google-analytics/tools.d.ts +3 -0
- package/dist/providers/google-analytics/tools.d.ts.map +1 -0
- package/dist/providers/index.d.ts.map +1 -1
- package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -13368,6 +13368,817 @@ const githubProvider = {
|
|
|
13368
13368
|
createTools: createGithubTools
|
|
13369
13369
|
};
|
|
13370
13370
|
//#endregion
|
|
13371
|
+
//#region src/providers/google-analytics/tools/archive-conversion-event.ts
|
|
13372
|
+
const archiveConversionEventInputSchema = zod.z.object({
|
|
13373
|
+
property_id: zod.z.string().describe("GA4 property numeric ID. Example: \"12345\""),
|
|
13374
|
+
conversion_event_id: zod.z.string().describe("Conversion event numeric ID. Example: \"67890\"")
|
|
13375
|
+
});
|
|
13376
|
+
const archiveConversionEventOutputSchema = zod.z.object({
|
|
13377
|
+
success: zod.z.boolean(),
|
|
13378
|
+
name: zod.z.string().describe("Resource name of the archived conversion event.")
|
|
13379
|
+
});
|
|
13380
|
+
function archiveConversionEventTool(proxy) {
|
|
13381
|
+
return (0, _mastra_core_tools.createTool)({
|
|
13382
|
+
id: "google_analytics_archive_conversion_event",
|
|
13383
|
+
description: "Archive a GA4 conversion event.",
|
|
13384
|
+
inputSchema: archiveConversionEventInputSchema,
|
|
13385
|
+
outputSchema: archiveConversionEventOutputSchema,
|
|
13386
|
+
execute: async (input, { requestContext }) => {
|
|
13387
|
+
const platformProxy = proxy.withRequestContext(requestContext);
|
|
13388
|
+
const name = `properties/${input.property_id}/conversionEvents/${input.conversion_event_id}`;
|
|
13389
|
+
await platformProxy.delete({
|
|
13390
|
+
endpoint: `/v1beta/properties/${encodeURIComponent(input.property_id)}/conversionEvents/${encodeURIComponent(input.conversion_event_id)}`,
|
|
13391
|
+
baseUrlOverride: "https://analyticsadmin.googleapis.com",
|
|
13392
|
+
retries: 3
|
|
13393
|
+
});
|
|
13394
|
+
return {
|
|
13395
|
+
success: true,
|
|
13396
|
+
name
|
|
13397
|
+
};
|
|
13398
|
+
}
|
|
13399
|
+
});
|
|
13400
|
+
}
|
|
13401
|
+
//#endregion
|
|
13402
|
+
//#region src/providers/google-analytics/tools/batch-run-reports.ts
|
|
13403
|
+
const DateRangeSchema$1 = zod.z.object({
|
|
13404
|
+
startDate: zod.z.string(),
|
|
13405
|
+
endDate: zod.z.string()
|
|
13406
|
+
});
|
|
13407
|
+
const DimensionSchema$9 = zod.z.object({ name: zod.z.string() });
|
|
13408
|
+
const MetricSchema$3 = zod.z.object({ name: zod.z.string() });
|
|
13409
|
+
const ReportRequestSchema = zod.z.object({
|
|
13410
|
+
dimensions: zod.z.array(DimensionSchema$9).optional(),
|
|
13411
|
+
metrics: zod.z.array(MetricSchema$3).optional(),
|
|
13412
|
+
dateRanges: zod.z.array(DateRangeSchema$1).optional(),
|
|
13413
|
+
offset: zod.z.string().optional(),
|
|
13414
|
+
limit: zod.z.string().optional(),
|
|
13415
|
+
keepEmptyRows: zod.z.boolean().optional(),
|
|
13416
|
+
returnPropertyQuota: zod.z.boolean().optional()
|
|
13417
|
+
}).passthrough();
|
|
13418
|
+
const batchRunReportsInputSchema = zod.z.object({
|
|
13419
|
+
property: zod.z.string().describe("Google Analytics property ID. Example: \"properties/123456789\""),
|
|
13420
|
+
requests: zod.z.array(ReportRequestSchema).min(1).max(5)
|
|
13421
|
+
});
|
|
13422
|
+
const DimensionValueSchema$2 = zod.z.object({ value: zod.z.string().optional() });
|
|
13423
|
+
const MetricValueSchema$2 = zod.z.object({ value: zod.z.string().optional() });
|
|
13424
|
+
const RowSchema$2 = zod.z.object({
|
|
13425
|
+
dimensionValues: zod.z.array(DimensionValueSchema$2).optional(),
|
|
13426
|
+
metricValues: zod.z.array(MetricValueSchema$2).optional()
|
|
13427
|
+
});
|
|
13428
|
+
const DimensionHeaderSchema$2 = zod.z.object({ name: zod.z.string().optional() });
|
|
13429
|
+
const MetricHeaderSchema$2 = zod.z.object({
|
|
13430
|
+
name: zod.z.string().optional(),
|
|
13431
|
+
type: zod.z.string().optional()
|
|
13432
|
+
});
|
|
13433
|
+
const RunReportResponseSchema = zod.z.object({
|
|
13434
|
+
dimensionHeaders: zod.z.array(DimensionHeaderSchema$2).optional(),
|
|
13435
|
+
metricHeaders: zod.z.array(MetricHeaderSchema$2).optional(),
|
|
13436
|
+
rows: zod.z.array(RowSchema$2).optional(),
|
|
13437
|
+
totals: zod.z.array(RowSchema$2).optional(),
|
|
13438
|
+
maximums: zod.z.array(RowSchema$2).optional(),
|
|
13439
|
+
minimums: zod.z.array(RowSchema$2).optional(),
|
|
13440
|
+
rowCount: zod.z.number().optional(),
|
|
13441
|
+
metadata: zod.z.record(zod.z.string(), zod.z.unknown()).optional(),
|
|
13442
|
+
propertyQuota: zod.z.record(zod.z.string(), zod.z.unknown()).optional(),
|
|
13443
|
+
kind: zod.z.string().optional()
|
|
13444
|
+
});
|
|
13445
|
+
const batchRunReportsOutputSchema = zod.z.object({
|
|
13446
|
+
reports: zod.z.array(RunReportResponseSchema),
|
|
13447
|
+
kind: zod.z.string().optional()
|
|
13448
|
+
});
|
|
13449
|
+
function batchRunReportsTool(proxy) {
|
|
13450
|
+
return (0, _mastra_core_tools.createTool)({
|
|
13451
|
+
id: "google_analytics_batch_run_reports",
|
|
13452
|
+
description: "Run multiple GA4 reports in one request.",
|
|
13453
|
+
inputSchema: batchRunReportsInputSchema,
|
|
13454
|
+
outputSchema: batchRunReportsOutputSchema,
|
|
13455
|
+
execute: async (input, { requestContext }) => {
|
|
13456
|
+
const platformProxy = proxy.withRequestContext(requestContext);
|
|
13457
|
+
const propertyId = input.property.replace(/^properties\//, "");
|
|
13458
|
+
const response = await platformProxy.post({
|
|
13459
|
+
endpoint: `/v1beta/properties/${encodeURIComponent(propertyId)}:batchRunReports`,
|
|
13460
|
+
baseUrlOverride: "https://analyticsdata.googleapis.com",
|
|
13461
|
+
data: { requests: input.requests },
|
|
13462
|
+
retries: 3
|
|
13463
|
+
});
|
|
13464
|
+
const providerResponse = zod.z.object({
|
|
13465
|
+
reports: zod.z.array(zod.z.unknown()).optional(),
|
|
13466
|
+
kind: zod.z.string().optional()
|
|
13467
|
+
}).parse(response.data);
|
|
13468
|
+
return {
|
|
13469
|
+
reports: providerResponse.reports?.map((report) => RunReportResponseSchema.parse(report)) ?? [],
|
|
13470
|
+
kind: providerResponse.kind
|
|
13471
|
+
};
|
|
13472
|
+
}
|
|
13473
|
+
});
|
|
13474
|
+
}
|
|
13475
|
+
//#endregion
|
|
13476
|
+
//#region src/providers/google-analytics/tools/create-conversion-event.ts
|
|
13477
|
+
const DefaultConversionValueInputSchema = zod.z.object({
|
|
13478
|
+
value: zod.z.number(),
|
|
13479
|
+
currencyCode: zod.z.string()
|
|
13480
|
+
});
|
|
13481
|
+
const createConversionEventInputSchema = zod.z.object({
|
|
13482
|
+
propertyId: zod.z.string().describe("GA4 property ID. Example: \"123456789\""),
|
|
13483
|
+
eventName: zod.z.string().describe("The event name for this conversion event. Example: \"click\""),
|
|
13484
|
+
countingMethod: zod.z.string().optional().describe("Optional. The method by which conversions will be counted. Example: \"ONCE_PER_EVENT\""),
|
|
13485
|
+
defaultConversionValue: DefaultConversionValueInputSchema.optional().describe("Optional. Defines a default value/currency for a conversion event.")
|
|
13486
|
+
});
|
|
13487
|
+
const ProviderDefaultConversionValueSchema = zod.z.object({
|
|
13488
|
+
value: zod.z.number(),
|
|
13489
|
+
currencyCode: zod.z.string()
|
|
13490
|
+
});
|
|
13491
|
+
const ProviderConversionEventSchema = zod.z.object({
|
|
13492
|
+
name: zod.z.string(),
|
|
13493
|
+
eventName: zod.z.string(),
|
|
13494
|
+
createTime: zod.z.string().optional(),
|
|
13495
|
+
deletable: zod.z.boolean().optional(),
|
|
13496
|
+
custom: zod.z.boolean().optional(),
|
|
13497
|
+
countingMethod: zod.z.string().optional(),
|
|
13498
|
+
defaultConversionValue: ProviderDefaultConversionValueSchema.optional()
|
|
13499
|
+
});
|
|
13500
|
+
const createConversionEventOutputSchema = zod.z.object({
|
|
13501
|
+
name: zod.z.string(),
|
|
13502
|
+
eventName: zod.z.string(),
|
|
13503
|
+
createTime: zod.z.string().optional(),
|
|
13504
|
+
deletable: zod.z.boolean().optional(),
|
|
13505
|
+
custom: zod.z.boolean().optional(),
|
|
13506
|
+
countingMethod: zod.z.string().optional(),
|
|
13507
|
+
defaultConversionValue: zod.z.object({
|
|
13508
|
+
value: zod.z.number(),
|
|
13509
|
+
currencyCode: zod.z.string()
|
|
13510
|
+
}).optional()
|
|
13511
|
+
});
|
|
13512
|
+
function createConversionEventTool(proxy) {
|
|
13513
|
+
return (0, _mastra_core_tools.createTool)({
|
|
13514
|
+
id: "google_analytics_create_conversion_event",
|
|
13515
|
+
description: "Create a conversion event for a GA4 property.",
|
|
13516
|
+
inputSchema: createConversionEventInputSchema,
|
|
13517
|
+
outputSchema: createConversionEventOutputSchema,
|
|
13518
|
+
execute: async (input, { requestContext }) => {
|
|
13519
|
+
const response = await proxy.withRequestContext(requestContext).post({
|
|
13520
|
+
endpoint: `/v1beta/properties/${encodeURIComponent(input.propertyId)}/conversionEvents`,
|
|
13521
|
+
data: {
|
|
13522
|
+
eventName: input.eventName,
|
|
13523
|
+
...input.countingMethod !== void 0 && { countingMethod: input.countingMethod },
|
|
13524
|
+
...input.defaultConversionValue !== void 0 && { defaultConversionValue: input.defaultConversionValue }
|
|
13525
|
+
},
|
|
13526
|
+
retries: 3,
|
|
13527
|
+
baseUrlOverride: "https://analyticsadmin.googleapis.com"
|
|
13528
|
+
});
|
|
13529
|
+
const providerEvent = ProviderConversionEventSchema.parse(response.data);
|
|
13530
|
+
return {
|
|
13531
|
+
name: providerEvent.name,
|
|
13532
|
+
eventName: providerEvent.eventName,
|
|
13533
|
+
...providerEvent.createTime !== void 0 && { createTime: providerEvent.createTime },
|
|
13534
|
+
...providerEvent.deletable !== void 0 && { deletable: providerEvent.deletable },
|
|
13535
|
+
...providerEvent.custom !== void 0 && { custom: providerEvent.custom },
|
|
13536
|
+
...providerEvent.countingMethod !== void 0 && { countingMethod: providerEvent.countingMethod },
|
|
13537
|
+
...providerEvent.defaultConversionValue !== void 0 && { defaultConversionValue: providerEvent.defaultConversionValue }
|
|
13538
|
+
};
|
|
13539
|
+
}
|
|
13540
|
+
});
|
|
13541
|
+
}
|
|
13542
|
+
//#endregion
|
|
13543
|
+
//#region src/providers/google-analytics/tools/create-data-stream.ts
|
|
13544
|
+
const DataStreamTypeSchema = zod.z.enum([
|
|
13545
|
+
"DATA_STREAM_TYPE_UNSPECIFIED",
|
|
13546
|
+
"WEB_DATA_STREAM",
|
|
13547
|
+
"ANDROID_APP_DATA_STREAM",
|
|
13548
|
+
"IOS_APP_DATA_STREAM"
|
|
13549
|
+
]).or(zod.z.string());
|
|
13550
|
+
const WebStreamDataInputSchema = zod.z.object({ default_uri: zod.z.string().describe("Domain name of the web app being measured. Example: \"https://www.example.com\"") });
|
|
13551
|
+
const AndroidAppStreamDataInputSchema = zod.z.object({ package_name: zod.z.string().describe("The package name for the app being measured. Example: \"com.example.myandroidapp\"") });
|
|
13552
|
+
const IosAppStreamDataInputSchema = zod.z.object({ bundle_id: zod.z.string().describe("The Apple App Store Bundle ID for the app. Example: \"com.example.myiosapp\"") });
|
|
13553
|
+
const CommonInputSchema = {
|
|
13554
|
+
property_id: zod.z.string().describe("GA4 property numeric ID. Example: \"1234\""),
|
|
13555
|
+
display_name: zod.z.string().describe("Human-readable display name for the Data Stream.")
|
|
13556
|
+
};
|
|
13557
|
+
const createDataStreamInputSchema = zod.z.discriminatedUnion("type", [
|
|
13558
|
+
zod.z.object({
|
|
13559
|
+
...CommonInputSchema,
|
|
13560
|
+
type: zod.z.literal("WEB_DATA_STREAM"),
|
|
13561
|
+
web_stream_data: WebStreamDataInputSchema.describe("Data specific to web streams. Required when type is WEB_DATA_STREAM.")
|
|
13562
|
+
}),
|
|
13563
|
+
zod.z.object({
|
|
13564
|
+
...CommonInputSchema,
|
|
13565
|
+
type: zod.z.literal("ANDROID_APP_DATA_STREAM"),
|
|
13566
|
+
android_app_stream_data: AndroidAppStreamDataInputSchema.describe("Data specific to Android app streams. Required when type is ANDROID_APP_DATA_STREAM.")
|
|
13567
|
+
}),
|
|
13568
|
+
zod.z.object({
|
|
13569
|
+
...CommonInputSchema,
|
|
13570
|
+
type: zod.z.literal("IOS_APP_DATA_STREAM"),
|
|
13571
|
+
ios_app_stream_data: IosAppStreamDataInputSchema.describe("Data specific to iOS app streams. Required when type is IOS_APP_DATA_STREAM.")
|
|
13572
|
+
}),
|
|
13573
|
+
zod.z.object({
|
|
13574
|
+
...CommonInputSchema,
|
|
13575
|
+
type: zod.z.literal("DATA_STREAM_TYPE_UNSPECIFIED")
|
|
13576
|
+
})
|
|
13577
|
+
]);
|
|
13578
|
+
const WebStreamDataSchema$1 = zod.z.object({
|
|
13579
|
+
measurementId: zod.z.string().optional(),
|
|
13580
|
+
firebaseAppId: zod.z.string().optional(),
|
|
13581
|
+
defaultUri: zod.z.string().optional()
|
|
13582
|
+
});
|
|
13583
|
+
const AndroidAppStreamDataSchema$1 = zod.z.object({
|
|
13584
|
+
firebaseAppId: zod.z.string().optional(),
|
|
13585
|
+
packageName: zod.z.string().optional()
|
|
13586
|
+
});
|
|
13587
|
+
const IosAppStreamDataSchema$1 = zod.z.object({
|
|
13588
|
+
firebaseAppId: zod.z.string().optional(),
|
|
13589
|
+
bundleId: zod.z.string().optional()
|
|
13590
|
+
});
|
|
13591
|
+
const DataStreamSchema$1 = zod.z.object({
|
|
13592
|
+
name: zod.z.string().optional(),
|
|
13593
|
+
type: DataStreamTypeSchema.optional(),
|
|
13594
|
+
displayName: zod.z.string().optional(),
|
|
13595
|
+
createTime: zod.z.string().optional(),
|
|
13596
|
+
updateTime: zod.z.string().optional(),
|
|
13597
|
+
webStreamData: WebStreamDataSchema$1.optional(),
|
|
13598
|
+
androidAppStreamData: AndroidAppStreamDataSchema$1.optional(),
|
|
13599
|
+
iosAppStreamData: IosAppStreamDataSchema$1.optional()
|
|
13600
|
+
});
|
|
13601
|
+
const createDataStreamOutputSchema = zod.z.object({
|
|
13602
|
+
name: zod.z.string().optional(),
|
|
13603
|
+
type: DataStreamTypeSchema.optional(),
|
|
13604
|
+
displayName: zod.z.string().optional(),
|
|
13605
|
+
createTime: zod.z.string().optional(),
|
|
13606
|
+
updateTime: zod.z.string().optional(),
|
|
13607
|
+
webStreamData: WebStreamDataSchema$1.optional(),
|
|
13608
|
+
androidAppStreamData: AndroidAppStreamDataSchema$1.optional(),
|
|
13609
|
+
iosAppStreamData: IosAppStreamDataSchema$1.optional()
|
|
13610
|
+
});
|
|
13611
|
+
function createDataStreamTool(proxy) {
|
|
13612
|
+
return (0, _mastra_core_tools.createTool)({
|
|
13613
|
+
id: "google_analytics_create_data_stream",
|
|
13614
|
+
description: "Create a data stream for a GA4 property.",
|
|
13615
|
+
inputSchema: createDataStreamInputSchema,
|
|
13616
|
+
outputSchema: createDataStreamOutputSchema,
|
|
13617
|
+
execute: async (input, { requestContext }) => {
|
|
13618
|
+
const platformProxy = proxy.withRequestContext(requestContext);
|
|
13619
|
+
const body = {
|
|
13620
|
+
type: input.type,
|
|
13621
|
+
displayName: input.display_name
|
|
13622
|
+
};
|
|
13623
|
+
if (input.type === "WEB_DATA_STREAM") body.webStreamData = { defaultUri: input.web_stream_data.default_uri };
|
|
13624
|
+
else if (input.type === "ANDROID_APP_DATA_STREAM") body.androidAppStreamData = { packageName: input.android_app_stream_data.package_name };
|
|
13625
|
+
else if (input.type === "IOS_APP_DATA_STREAM") body.iosAppStreamData = { bundleId: input.ios_app_stream_data.bundle_id };
|
|
13626
|
+
const response = await platformProxy.post({
|
|
13627
|
+
endpoint: `/v1beta/properties/${encodeURIComponent(input.property_id)}/dataStreams`,
|
|
13628
|
+
data: body,
|
|
13629
|
+
baseUrlOverride: "https://analyticsadmin.googleapis.com",
|
|
13630
|
+
retries: 3
|
|
13631
|
+
});
|
|
13632
|
+
const dataStream = DataStreamSchema$1.parse(response.data);
|
|
13633
|
+
return {
|
|
13634
|
+
...dataStream.name !== void 0 && { name: dataStream.name },
|
|
13635
|
+
...dataStream.type !== void 0 && { type: dataStream.type },
|
|
13636
|
+
...dataStream.displayName !== void 0 && { displayName: dataStream.displayName },
|
|
13637
|
+
...dataStream.createTime !== void 0 && { createTime: dataStream.createTime },
|
|
13638
|
+
...dataStream.updateTime !== void 0 && { updateTime: dataStream.updateTime },
|
|
13639
|
+
...dataStream.webStreamData !== void 0 && { webStreamData: dataStream.webStreamData },
|
|
13640
|
+
...dataStream.androidAppStreamData !== void 0 && { androidAppStreamData: dataStream.androidAppStreamData },
|
|
13641
|
+
...dataStream.iosAppStreamData !== void 0 && { iosAppStreamData: dataStream.iosAppStreamData }
|
|
13642
|
+
};
|
|
13643
|
+
}
|
|
13644
|
+
});
|
|
13645
|
+
}
|
|
13646
|
+
//#endregion
|
|
13647
|
+
//#region src/providers/google-analytics/tools/create-property.ts
|
|
13648
|
+
const createPropertyInputSchema$1 = zod.z.object({
|
|
13649
|
+
parent: zod.z.string().describe("The resource name of the account under which to create the property. Example: \"accounts/12345\""),
|
|
13650
|
+
displayName: zod.z.string().describe("Human-readable display name for the property. Max 100 UTF-16 code units."),
|
|
13651
|
+
timeZone: zod.z.string().describe("Reporting time zone for the property. Example: \"America/Los_Angeles\""),
|
|
13652
|
+
currencyCode: zod.z.string().optional().describe("Currency type used in reports. Example: \"USD\""),
|
|
13653
|
+
industryCategory: zod.z.string().optional().describe("Industry category for benchmarking. Example: \"TECHNOLOGY\""),
|
|
13654
|
+
serviceLevel: zod.z.string().optional().describe("Service level. Example: \"STANDARD\" or \"GOOGLE_ANALYTICS_360\""),
|
|
13655
|
+
propertyType: zod.z.string().optional().describe("Property type. Example: \"ORDINARY_PROPERTY\"")
|
|
13656
|
+
});
|
|
13657
|
+
const ProviderPropertySchema$1 = zod.z.object({
|
|
13658
|
+
name: zod.z.string(),
|
|
13659
|
+
parent: zod.z.string(),
|
|
13660
|
+
displayName: zod.z.string(),
|
|
13661
|
+
createTime: zod.z.string().optional(),
|
|
13662
|
+
updateTime: zod.z.string().optional(),
|
|
13663
|
+
timeZone: zod.z.string().optional(),
|
|
13664
|
+
currencyCode: zod.z.string().optional(),
|
|
13665
|
+
industryCategory: zod.z.string().optional(),
|
|
13666
|
+
serviceLevel: zod.z.string().optional(),
|
|
13667
|
+
propertyType: zod.z.string().optional(),
|
|
13668
|
+
account: zod.z.string().optional(),
|
|
13669
|
+
deleteTime: zod.z.string().optional(),
|
|
13670
|
+
expireTime: zod.z.string().optional()
|
|
13671
|
+
});
|
|
13672
|
+
const createPropertyOutputSchema$1 = zod.z.object({
|
|
13673
|
+
name: zod.z.string().describe("Resource name of the created property. Example: \"properties/12345\""),
|
|
13674
|
+
parent: zod.z.string().describe("Parent account name. Example: \"accounts/12345\""),
|
|
13675
|
+
displayName: zod.z.string(),
|
|
13676
|
+
createTime: zod.z.string().optional(),
|
|
13677
|
+
updateTime: zod.z.string().optional(),
|
|
13678
|
+
timeZone: zod.z.string().optional(),
|
|
13679
|
+
currencyCode: zod.z.string().optional(),
|
|
13680
|
+
industryCategory: zod.z.string().optional(),
|
|
13681
|
+
serviceLevel: zod.z.string().optional(),
|
|
13682
|
+
propertyType: zod.z.string().optional(),
|
|
13683
|
+
account: zod.z.string().optional()
|
|
13684
|
+
});
|
|
13685
|
+
function createPropertyTool$1(proxy) {
|
|
13686
|
+
return (0, _mastra_core_tools.createTool)({
|
|
13687
|
+
id: "google_analytics_create_property",
|
|
13688
|
+
description: "Create a GA4 property under an account.",
|
|
13689
|
+
inputSchema: createPropertyInputSchema$1,
|
|
13690
|
+
outputSchema: createPropertyOutputSchema$1,
|
|
13691
|
+
execute: async (input, { requestContext }) => {
|
|
13692
|
+
const platformProxy = proxy.withRequestContext(requestContext);
|
|
13693
|
+
const requestBody = {
|
|
13694
|
+
parent: input.parent,
|
|
13695
|
+
displayName: input.displayName
|
|
13696
|
+
};
|
|
13697
|
+
if (input.timeZone !== void 0) requestBody.timeZone = input.timeZone;
|
|
13698
|
+
if (input.currencyCode !== void 0) requestBody.currencyCode = input.currencyCode;
|
|
13699
|
+
if (input.industryCategory !== void 0) requestBody.industryCategory = input.industryCategory;
|
|
13700
|
+
if (input.serviceLevel !== void 0) requestBody.serviceLevel = input.serviceLevel;
|
|
13701
|
+
if (input.propertyType !== void 0) requestBody.propertyType = input.propertyType;
|
|
13702
|
+
const response = await platformProxy.post({
|
|
13703
|
+
baseUrlOverride: "https://analyticsadmin.googleapis.com",
|
|
13704
|
+
endpoint: "/v1beta/properties",
|
|
13705
|
+
data: requestBody,
|
|
13706
|
+
retries: 3
|
|
13707
|
+
});
|
|
13708
|
+
if (!response.data) throw new platformProxy.ActionError({
|
|
13709
|
+
type: "provider_error",
|
|
13710
|
+
message: "Empty response from Google Analytics Admin API when creating property."
|
|
13711
|
+
});
|
|
13712
|
+
const providerProperty = ProviderPropertySchema$1.parse(response.data);
|
|
13713
|
+
return {
|
|
13714
|
+
name: providerProperty.name,
|
|
13715
|
+
parent: providerProperty.parent,
|
|
13716
|
+
displayName: providerProperty.displayName,
|
|
13717
|
+
...providerProperty.createTime !== void 0 && { createTime: providerProperty.createTime },
|
|
13718
|
+
...providerProperty.updateTime !== void 0 && { updateTime: providerProperty.updateTime },
|
|
13719
|
+
...providerProperty.timeZone !== void 0 && { timeZone: providerProperty.timeZone },
|
|
13720
|
+
...providerProperty.currencyCode !== void 0 && { currencyCode: providerProperty.currencyCode },
|
|
13721
|
+
...providerProperty.industryCategory !== void 0 && { industryCategory: providerProperty.industryCategory },
|
|
13722
|
+
...providerProperty.serviceLevel !== void 0 && { serviceLevel: providerProperty.serviceLevel },
|
|
13723
|
+
...providerProperty.propertyType !== void 0 && { propertyType: providerProperty.propertyType },
|
|
13724
|
+
...providerProperty.account !== void 0 && { account: providerProperty.account }
|
|
13725
|
+
};
|
|
13726
|
+
}
|
|
13727
|
+
});
|
|
13728
|
+
}
|
|
13729
|
+
//#endregion
|
|
13730
|
+
//#region src/providers/google-analytics/tools/get-metadata.ts
|
|
13731
|
+
const getMetadataInputSchema = zod.z.object({ propertyId: zod.z.string().describe("GA4 property ID. Use \"0\" for universal metadata. Example: \"123456789\"") });
|
|
13732
|
+
const DimensionSchema$8 = zod.z.object({
|
|
13733
|
+
apiName: zod.z.string(),
|
|
13734
|
+
uiName: zod.z.string(),
|
|
13735
|
+
description: zod.z.string(),
|
|
13736
|
+
category: zod.z.string(),
|
|
13737
|
+
deprecatedApiNames: zod.z.array(zod.z.string()).optional()
|
|
13738
|
+
});
|
|
13739
|
+
const MetricSchema$2 = zod.z.object({
|
|
13740
|
+
apiName: zod.z.string(),
|
|
13741
|
+
uiName: zod.z.string(),
|
|
13742
|
+
description: zod.z.string(),
|
|
13743
|
+
type: zod.z.string(),
|
|
13744
|
+
category: zod.z.string(),
|
|
13745
|
+
deprecatedApiNames: zod.z.array(zod.z.string()).optional()
|
|
13746
|
+
});
|
|
13747
|
+
const getMetadataOutputSchema = zod.z.object({
|
|
13748
|
+
name: zod.z.string(),
|
|
13749
|
+
dimensions: zod.z.array(DimensionSchema$8),
|
|
13750
|
+
metrics: zod.z.array(MetricSchema$2)
|
|
13751
|
+
});
|
|
13752
|
+
function getMetadataTool(proxy) {
|
|
13753
|
+
return (0, _mastra_core_tools.createTool)({
|
|
13754
|
+
id: "google_analytics_get_metadata",
|
|
13755
|
+
description: "Retrieve GA4 dimensions and metrics metadata.",
|
|
13756
|
+
inputSchema: getMetadataInputSchema,
|
|
13757
|
+
outputSchema: getMetadataOutputSchema,
|
|
13758
|
+
execute: async (input, { requestContext }) => {
|
|
13759
|
+
const platformProxy = proxy.withRequestContext(requestContext);
|
|
13760
|
+
const config = {
|
|
13761
|
+
endpoint: `/v1beta/properties/${encodeURIComponent(input.propertyId)}/metadata`,
|
|
13762
|
+
retries: 3,
|
|
13763
|
+
baseUrlOverride: "https://analyticsdata.googleapis.com"
|
|
13764
|
+
};
|
|
13765
|
+
const response = await platformProxy.get(config);
|
|
13766
|
+
if (!response.data) throw new platformProxy.ActionError({
|
|
13767
|
+
type: "not_found",
|
|
13768
|
+
message: "Metadata not found for the specified property."
|
|
13769
|
+
});
|
|
13770
|
+
return getMetadataOutputSchema.parse(response.data);
|
|
13771
|
+
}
|
|
13772
|
+
});
|
|
13773
|
+
}
|
|
13774
|
+
//#endregion
|
|
13775
|
+
//#region src/providers/google-analytics/tools/run-pivot-report.ts
|
|
13776
|
+
const runPivotReportInputSchema = zod.z.object({
|
|
13777
|
+
property: zod.z.string().describe("Google Analytics property numeric ID. Example: 535258304"),
|
|
13778
|
+
dimensions: zod.z.array(zod.z.record(zod.z.string(), zod.z.unknown())).optional(),
|
|
13779
|
+
metrics: zod.z.array(zod.z.record(zod.z.string(), zod.z.unknown())).optional(),
|
|
13780
|
+
dateRanges: zod.z.array(zod.z.record(zod.z.string(), zod.z.unknown())).optional(),
|
|
13781
|
+
pivots: zod.z.array(zod.z.record(zod.z.string(), zod.z.unknown())).optional(),
|
|
13782
|
+
dimensionFilter: zod.z.record(zod.z.string(), zod.z.unknown()).optional(),
|
|
13783
|
+
metricFilter: zod.z.record(zod.z.string(), zod.z.unknown()).optional(),
|
|
13784
|
+
currencyCode: zod.z.string().optional(),
|
|
13785
|
+
cohortSpec: zod.z.record(zod.z.string(), zod.z.unknown()).optional(),
|
|
13786
|
+
keepEmptyRows: zod.z.boolean().optional(),
|
|
13787
|
+
returnPropertyQuota: zod.z.boolean().optional(),
|
|
13788
|
+
comparisons: zod.z.array(zod.z.record(zod.z.string(), zod.z.unknown())).optional()
|
|
13789
|
+
});
|
|
13790
|
+
const runPivotReportOutputSchema = zod.z.object({
|
|
13791
|
+
pivotHeaders: zod.z.array(zod.z.record(zod.z.string(), zod.z.unknown())).optional(),
|
|
13792
|
+
dimensionHeaders: zod.z.array(zod.z.record(zod.z.string(), zod.z.unknown())).optional(),
|
|
13793
|
+
metricHeaders: zod.z.array(zod.z.record(zod.z.string(), zod.z.unknown())).optional(),
|
|
13794
|
+
rows: zod.z.array(zod.z.record(zod.z.string(), zod.z.unknown())).optional(),
|
|
13795
|
+
aggregates: zod.z.array(zod.z.record(zod.z.string(), zod.z.unknown())).optional(),
|
|
13796
|
+
metadata: zod.z.record(zod.z.string(), zod.z.unknown()).optional(),
|
|
13797
|
+
propertyQuota: zod.z.record(zod.z.string(), zod.z.unknown()).optional(),
|
|
13798
|
+
kind: zod.z.string().optional()
|
|
13799
|
+
}).passthrough();
|
|
13800
|
+
function runPivotReportTool(proxy) {
|
|
13801
|
+
return (0, _mastra_core_tools.createTool)({
|
|
13802
|
+
id: "google_analytics_run_pivot_report",
|
|
13803
|
+
description: "Run a GA4 pivot report.",
|
|
13804
|
+
inputSchema: runPivotReportInputSchema,
|
|
13805
|
+
outputSchema: runPivotReportOutputSchema,
|
|
13806
|
+
execute: async (input, { requestContext }) => {
|
|
13807
|
+
const platformProxy = proxy.withRequestContext(requestContext);
|
|
13808
|
+
const { property, ...requestBody } = input;
|
|
13809
|
+
const response = await platformProxy.post({
|
|
13810
|
+
endpoint: `/v1beta/properties/${encodeURIComponent(property)}:runPivotReport`,
|
|
13811
|
+
data: requestBody,
|
|
13812
|
+
baseUrlOverride: "https://analyticsdata.googleapis.com",
|
|
13813
|
+
retries: 3
|
|
13814
|
+
});
|
|
13815
|
+
return runPivotReportOutputSchema.parse(response.data);
|
|
13816
|
+
}
|
|
13817
|
+
});
|
|
13818
|
+
}
|
|
13819
|
+
//#endregion
|
|
13820
|
+
//#region src/providers/google-analytics/tools/run-realtime-report.ts
|
|
13821
|
+
const DimensionSchema$7 = zod.z.object({ name: zod.z.string().optional() });
|
|
13822
|
+
const MetricSchema$1 = zod.z.object({
|
|
13823
|
+
name: zod.z.string().optional(),
|
|
13824
|
+
expression: zod.z.string().optional(),
|
|
13825
|
+
invisible: zod.z.boolean().optional()
|
|
13826
|
+
});
|
|
13827
|
+
const FilterExpressionSchema = zod.z.object({}).passthrough();
|
|
13828
|
+
const OrderBySchema$1 = zod.z.object({}).passthrough();
|
|
13829
|
+
const MinuteRangeSchema = zod.z.object({
|
|
13830
|
+
name: zod.z.string().optional(),
|
|
13831
|
+
startMinutesAgo: zod.z.number().optional(),
|
|
13832
|
+
endMinutesAgo: zod.z.number().optional()
|
|
13833
|
+
});
|
|
13834
|
+
const runRealtimeReportInputSchema = zod.z.object({
|
|
13835
|
+
property: zod.z.string().describe("A Google Analytics property identifier. Example: \"properties/1234\""),
|
|
13836
|
+
dimensions: zod.z.array(DimensionSchema$7).optional(),
|
|
13837
|
+
metrics: zod.z.array(MetricSchema$1).optional(),
|
|
13838
|
+
dimensionFilter: FilterExpressionSchema.optional(),
|
|
13839
|
+
metricFilter: FilterExpressionSchema.optional(),
|
|
13840
|
+
limit: zod.z.string().optional().describe("The number of rows to return. If unspecified, 10,000 rows are returned."),
|
|
13841
|
+
metricAggregations: zod.z.array(zod.z.string()).optional(),
|
|
13842
|
+
orderBys: zod.z.array(OrderBySchema$1).optional(),
|
|
13843
|
+
returnPropertyQuota: zod.z.boolean().optional(),
|
|
13844
|
+
minuteRanges: zod.z.array(MinuteRangeSchema).optional()
|
|
13845
|
+
});
|
|
13846
|
+
const DimensionHeaderSchema$1 = zod.z.object({ name: zod.z.string().optional() });
|
|
13847
|
+
const MetricHeaderSchema$1 = zod.z.object({
|
|
13848
|
+
name: zod.z.string().optional(),
|
|
13849
|
+
type: zod.z.string().optional()
|
|
13850
|
+
});
|
|
13851
|
+
const DimensionValueSchema$1 = zod.z.object({
|
|
13852
|
+
value: zod.z.string().optional(),
|
|
13853
|
+
oneValue: zod.z.string().optional()
|
|
13854
|
+
});
|
|
13855
|
+
const MetricValueSchema$1 = zod.z.object({ value: zod.z.string().optional() });
|
|
13856
|
+
const RowSchema$1 = zod.z.object({
|
|
13857
|
+
dimensionValues: zod.z.array(DimensionValueSchema$1).optional(),
|
|
13858
|
+
metricValues: zod.z.array(MetricValueSchema$1).optional()
|
|
13859
|
+
});
|
|
13860
|
+
const PropertyQuotaSchema = zod.z.object({}).passthrough();
|
|
13861
|
+
const runRealtimeReportOutputSchema = zod.z.object({
|
|
13862
|
+
dimensionHeaders: zod.z.array(DimensionHeaderSchema$1).optional(),
|
|
13863
|
+
metricHeaders: zod.z.array(MetricHeaderSchema$1).optional(),
|
|
13864
|
+
rows: zod.z.array(RowSchema$1).optional(),
|
|
13865
|
+
totals: zod.z.array(RowSchema$1).optional(),
|
|
13866
|
+
maximums: zod.z.array(RowSchema$1).optional(),
|
|
13867
|
+
minimums: zod.z.array(RowSchema$1).optional(),
|
|
13868
|
+
rowCount: zod.z.number().optional(),
|
|
13869
|
+
propertyQuota: PropertyQuotaSchema.optional(),
|
|
13870
|
+
kind: zod.z.string().optional()
|
|
13871
|
+
});
|
|
13872
|
+
function runRealtimeReportTool(proxy) {
|
|
13873
|
+
return (0, _mastra_core_tools.createTool)({
|
|
13874
|
+
id: "google_analytics_run_realtime_report",
|
|
13875
|
+
description: "Run a realtime GA4 report.",
|
|
13876
|
+
inputSchema: runRealtimeReportInputSchema,
|
|
13877
|
+
outputSchema: runRealtimeReportOutputSchema,
|
|
13878
|
+
execute: async (input, { requestContext }) => {
|
|
13879
|
+
const platformProxy = proxy.withRequestContext(requestContext);
|
|
13880
|
+
const propertyParts = input.property.split("/");
|
|
13881
|
+
if (propertyParts.length !== 2 || propertyParts[0] !== "properties" || !propertyParts[1]) throw new platformProxy.ActionError({
|
|
13882
|
+
type: "invalid_property",
|
|
13883
|
+
message: "Property must be in the format \"properties/{propertyId}\". Example: \"properties/1234\""
|
|
13884
|
+
});
|
|
13885
|
+
const propertyId = encodeURIComponent(propertyParts[1]);
|
|
13886
|
+
const requestBody = {
|
|
13887
|
+
...input.dimensions !== void 0 && { dimensions: input.dimensions },
|
|
13888
|
+
...input.metrics !== void 0 && { metrics: input.metrics },
|
|
13889
|
+
...input.dimensionFilter !== void 0 && { dimensionFilter: input.dimensionFilter },
|
|
13890
|
+
...input.metricFilter !== void 0 && { metricFilter: input.metricFilter },
|
|
13891
|
+
...input.limit !== void 0 && { limit: input.limit },
|
|
13892
|
+
...input.metricAggregations !== void 0 && { metricAggregations: input.metricAggregations },
|
|
13893
|
+
...input.orderBys !== void 0 && { orderBys: input.orderBys },
|
|
13894
|
+
...input.returnPropertyQuota !== void 0 && { returnPropertyQuota: input.returnPropertyQuota },
|
|
13895
|
+
...input.minuteRanges !== void 0 && { minuteRanges: input.minuteRanges }
|
|
13896
|
+
};
|
|
13897
|
+
const response = await platformProxy.post({
|
|
13898
|
+
endpoint: `/v1beta/properties/${propertyId}:runRealtimeReport`,
|
|
13899
|
+
baseUrlOverride: "https://analyticsdata.googleapis.com",
|
|
13900
|
+
data: requestBody,
|
|
13901
|
+
retries: 3
|
|
13902
|
+
});
|
|
13903
|
+
return runRealtimeReportOutputSchema.parse(response.data);
|
|
13904
|
+
}
|
|
13905
|
+
});
|
|
13906
|
+
}
|
|
13907
|
+
//#endregion
|
|
13908
|
+
//#region src/providers/google-analytics/tools/run-report.ts
|
|
13909
|
+
const DimensionSchema$6 = zod.z.object({ name: zod.z.string() });
|
|
13910
|
+
const MetricSchema = zod.z.object({ name: zod.z.string() });
|
|
13911
|
+
const DateRangeSchema = zod.z.object({
|
|
13912
|
+
startDate: zod.z.string(),
|
|
13913
|
+
endDate: zod.z.string()
|
|
13914
|
+
});
|
|
13915
|
+
const OrderBySchema = zod.z.object({
|
|
13916
|
+
dimension: zod.z.object({ dimensionName: zod.z.string() }).optional(),
|
|
13917
|
+
metric: zod.z.object({ metricName: zod.z.string() }).optional(),
|
|
13918
|
+
desc: zod.z.boolean().optional()
|
|
13919
|
+
});
|
|
13920
|
+
const runReportInputSchema = zod.z.object({
|
|
13921
|
+
property: zod.z.string().describe("GA4 property ID. Example: \"properties/123456789\" or \"123456789\""),
|
|
13922
|
+
dimensions: zod.z.array(DimensionSchema$6).optional(),
|
|
13923
|
+
metrics: zod.z.array(MetricSchema).optional(),
|
|
13924
|
+
dateRanges: zod.z.array(DateRangeSchema).optional(),
|
|
13925
|
+
dimensionFilter: zod.z.object({}).passthrough().optional(),
|
|
13926
|
+
metricFilter: zod.z.object({}).passthrough().optional(),
|
|
13927
|
+
ordering: zod.z.array(OrderBySchema).optional(),
|
|
13928
|
+
limit: zod.z.number().optional()
|
|
13929
|
+
});
|
|
13930
|
+
const DimensionHeaderSchema = zod.z.object({ name: zod.z.string().optional() });
|
|
13931
|
+
const MetricHeaderSchema = zod.z.object({
|
|
13932
|
+
name: zod.z.string().optional(),
|
|
13933
|
+
type: zod.z.string().optional()
|
|
13934
|
+
});
|
|
13935
|
+
const DimensionValueSchema = zod.z.object({ value: zod.z.string().optional() });
|
|
13936
|
+
const MetricValueSchema = zod.z.object({ value: zod.z.string().optional() });
|
|
13937
|
+
const RowSchema = zod.z.object({
|
|
13938
|
+
dimensionValues: zod.z.array(DimensionValueSchema).optional(),
|
|
13939
|
+
metricValues: zod.z.array(MetricValueSchema).optional()
|
|
13940
|
+
});
|
|
13941
|
+
const runReportOutputSchema = zod.z.object({
|
|
13942
|
+
dimensionHeaders: zod.z.array(DimensionHeaderSchema).optional(),
|
|
13943
|
+
metricHeaders: zod.z.array(MetricHeaderSchema).optional(),
|
|
13944
|
+
rows: zod.z.array(RowSchema).optional(),
|
|
13945
|
+
rowCount: zod.z.number().optional(),
|
|
13946
|
+
totals: zod.z.array(RowSchema).optional(),
|
|
13947
|
+
maximums: zod.z.array(RowSchema).optional(),
|
|
13948
|
+
minimums: zod.z.array(RowSchema).optional()
|
|
13949
|
+
});
|
|
13950
|
+
function runReportTool(proxy) {
|
|
13951
|
+
return (0, _mastra_core_tools.createTool)({
|
|
13952
|
+
id: "google_analytics_run_report",
|
|
13953
|
+
description: "Run a GA4 report for a property",
|
|
13954
|
+
inputSchema: runReportInputSchema,
|
|
13955
|
+
outputSchema: runReportOutputSchema,
|
|
13956
|
+
execute: async (input, { requestContext }) => {
|
|
13957
|
+
const platformProxy = proxy.withRequestContext(requestContext);
|
|
13958
|
+
const propertyNumericId = input.property.replace(/^properties\//, "");
|
|
13959
|
+
const response = await platformProxy.post({
|
|
13960
|
+
endpoint: `/v1beta/properties/${encodeURIComponent(propertyNumericId)}:runReport`,
|
|
13961
|
+
baseUrlOverride: "https://analyticsdata.googleapis.com",
|
|
13962
|
+
data: {
|
|
13963
|
+
...input.dimensions !== void 0 && { dimensions: input.dimensions },
|
|
13964
|
+
...input.metrics !== void 0 && { metrics: input.metrics },
|
|
13965
|
+
...input.dateRanges !== void 0 && { dateRanges: input.dateRanges },
|
|
13966
|
+
...input.dimensionFilter !== void 0 && { dimensionFilter: input.dimensionFilter },
|
|
13967
|
+
...input.metricFilter !== void 0 && { metricFilter: input.metricFilter },
|
|
13968
|
+
...input.ordering !== void 0 && { orderBys: input.ordering },
|
|
13969
|
+
...input.limit !== void 0 && { limit: input.limit }
|
|
13970
|
+
},
|
|
13971
|
+
retries: 3
|
|
13972
|
+
});
|
|
13973
|
+
const providerResponse = zod.z.object({
|
|
13974
|
+
dimensionHeaders: zod.z.array(zod.z.object({ name: zod.z.string().optional() })).optional(),
|
|
13975
|
+
metricHeaders: zod.z.array(zod.z.object({
|
|
13976
|
+
name: zod.z.string().optional(),
|
|
13977
|
+
type: zod.z.string().optional()
|
|
13978
|
+
})).optional(),
|
|
13979
|
+
rows: zod.z.array(zod.z.object({
|
|
13980
|
+
dimensionValues: zod.z.array(zod.z.object({ value: zod.z.string().optional() })).optional(),
|
|
13981
|
+
metricValues: zod.z.array(zod.z.object({ value: zod.z.string().optional() })).optional()
|
|
13982
|
+
})).optional(),
|
|
13983
|
+
rowCount: zod.z.number().optional(),
|
|
13984
|
+
totals: zod.z.array(zod.z.object({
|
|
13985
|
+
dimensionValues: zod.z.array(zod.z.object({ value: zod.z.string().optional() })).optional(),
|
|
13986
|
+
metricValues: zod.z.array(zod.z.object({ value: zod.z.string().optional() })).optional()
|
|
13987
|
+
})).optional(),
|
|
13988
|
+
maximums: zod.z.array(zod.z.object({
|
|
13989
|
+
dimensionValues: zod.z.array(zod.z.object({ value: zod.z.string().optional() })).optional(),
|
|
13990
|
+
metricValues: zod.z.array(zod.z.object({ value: zod.z.string().optional() })).optional()
|
|
13991
|
+
})).optional(),
|
|
13992
|
+
minimums: zod.z.array(zod.z.object({
|
|
13993
|
+
dimensionValues: zod.z.array(zod.z.object({ value: zod.z.string().optional() })).optional(),
|
|
13994
|
+
metricValues: zod.z.array(zod.z.object({ value: zod.z.string().optional() })).optional()
|
|
13995
|
+
})).optional()
|
|
13996
|
+
}).parse(response.data);
|
|
13997
|
+
return {
|
|
13998
|
+
dimensionHeaders: providerResponse.dimensionHeaders,
|
|
13999
|
+
metricHeaders: providerResponse.metricHeaders,
|
|
14000
|
+
rows: providerResponse.rows,
|
|
14001
|
+
rowCount: providerResponse.rowCount,
|
|
14002
|
+
totals: providerResponse.totals,
|
|
14003
|
+
maximums: providerResponse.maximums,
|
|
14004
|
+
minimums: providerResponse.minimums
|
|
14005
|
+
};
|
|
14006
|
+
}
|
|
14007
|
+
});
|
|
14008
|
+
}
|
|
14009
|
+
//#endregion
|
|
14010
|
+
//#region src/providers/google-analytics/tools/update-data-stream.ts
|
|
14011
|
+
const updateDataStreamInputSchema = zod.z.object({
|
|
14012
|
+
propertyId: zod.z.string().describe("GA4 property ID."),
|
|
14013
|
+
dataStreamId: zod.z.string().describe("Data stream ID to update."),
|
|
14014
|
+
displayName: zod.z.string().optional().describe("Human-readable display name for the Data Stream."),
|
|
14015
|
+
webStreamData: zod.z.object({ defaultUri: zod.z.string().optional().describe("Domain name of the web app being measured.") }).optional().describe("Data specific to web streams."),
|
|
14016
|
+
updateMask: zod.z.string().optional().describe("The list of fields to be updated. If omitted, it will be computed from provided fields.")
|
|
14017
|
+
});
|
|
14018
|
+
const WebStreamDataSchema = zod.z.object({
|
|
14019
|
+
defaultUri: zod.z.string().optional(),
|
|
14020
|
+
measurementId: zod.z.string().optional(),
|
|
14021
|
+
firebaseAppId: zod.z.string().optional()
|
|
14022
|
+
});
|
|
14023
|
+
const AndroidAppStreamDataSchema = zod.z.object({
|
|
14024
|
+
packageName: zod.z.string().optional(),
|
|
14025
|
+
firebaseAppId: zod.z.string().optional()
|
|
14026
|
+
});
|
|
14027
|
+
const IosAppStreamDataSchema = zod.z.object({
|
|
14028
|
+
bundleId: zod.z.string().optional(),
|
|
14029
|
+
firebaseAppId: zod.z.string().optional()
|
|
14030
|
+
});
|
|
14031
|
+
const DataStreamSchema = zod.z.object({
|
|
14032
|
+
name: zod.z.string(),
|
|
14033
|
+
type: zod.z.string().optional(),
|
|
14034
|
+
displayName: zod.z.string().optional(),
|
|
14035
|
+
createTime: zod.z.string().optional(),
|
|
14036
|
+
updateTime: zod.z.string().optional(),
|
|
14037
|
+
webStreamData: WebStreamDataSchema.optional(),
|
|
14038
|
+
androidAppStreamData: AndroidAppStreamDataSchema.optional(),
|
|
14039
|
+
iosAppStreamData: IosAppStreamDataSchema.optional()
|
|
14040
|
+
});
|
|
14041
|
+
const updateDataStreamOutputSchema = DataStreamSchema;
|
|
14042
|
+
function updateDataStreamTool(proxy) {
|
|
14043
|
+
return (0, _mastra_core_tools.createTool)({
|
|
14044
|
+
id: "google_analytics_update_data_stream",
|
|
14045
|
+
description: "Update a GA4 data stream.",
|
|
14046
|
+
inputSchema: updateDataStreamInputSchema,
|
|
14047
|
+
outputSchema: updateDataStreamOutputSchema,
|
|
14048
|
+
execute: async (input, { requestContext }) => {
|
|
14049
|
+
const platformProxy = proxy.withRequestContext(requestContext);
|
|
14050
|
+
const updateMaskParts = [];
|
|
14051
|
+
if (input.displayName !== void 0) updateMaskParts.push("displayName");
|
|
14052
|
+
if (input.webStreamData?.defaultUri !== void 0) updateMaskParts.push("webStreamData.defaultUri");
|
|
14053
|
+
const updateMask = input.updateMask || updateMaskParts.join(",");
|
|
14054
|
+
if (!updateMask) throw new platformProxy.ActionError({
|
|
14055
|
+
type: "invalid_input",
|
|
14056
|
+
message: "No fields to update. Provide at least one of displayName or webStreamData.defaultUri, or specify updateMask explicitly."
|
|
14057
|
+
});
|
|
14058
|
+
const requestBody = {};
|
|
14059
|
+
if (input.displayName !== void 0) requestBody.displayName = input.displayName;
|
|
14060
|
+
if (input.webStreamData?.defaultUri !== void 0) requestBody.webStreamData = { defaultUri: input.webStreamData.defaultUri };
|
|
14061
|
+
const response = await platformProxy.patch({
|
|
14062
|
+
endpoint: `/v1beta/properties/${encodeURIComponent(input.propertyId)}/dataStreams/${encodeURIComponent(input.dataStreamId)}`,
|
|
14063
|
+
params: { updateMask },
|
|
14064
|
+
data: requestBody,
|
|
14065
|
+
retries: 3,
|
|
14066
|
+
baseUrlOverride: "https://analyticsadmin.googleapis.com"
|
|
14067
|
+
});
|
|
14068
|
+
return DataStreamSchema.parse(response.data);
|
|
14069
|
+
}
|
|
14070
|
+
});
|
|
14071
|
+
}
|
|
14072
|
+
//#endregion
|
|
14073
|
+
//#region src/providers/google-analytics/tools/update-property.ts
|
|
14074
|
+
const updatePropertyInputSchema = zod.z.object({
|
|
14075
|
+
name: zod.z.string().describe("Property resource name. Example: \"properties/123456789\""),
|
|
14076
|
+
displayName: zod.z.string().optional().describe("Human-readable display name for the property."),
|
|
14077
|
+
timeZone: zod.z.string().optional().describe("The reporting time zone for the property. Example: \"America/Los_Angeles\"."),
|
|
14078
|
+
currencyCode: zod.z.string().optional().describe("The currency type used in reports. Example: \"USD\"."),
|
|
14079
|
+
industryCategory: zod.z.string().optional().describe("Industry category. Example: \"TECHNOLOGY\".")
|
|
14080
|
+
});
|
|
14081
|
+
const ProviderPropertySchema = zod.z.object({
|
|
14082
|
+
name: zod.z.string(),
|
|
14083
|
+
createTime: zod.z.string().optional(),
|
|
14084
|
+
updateTime: zod.z.string().optional(),
|
|
14085
|
+
parent: zod.z.string().optional(),
|
|
14086
|
+
displayName: zod.z.string().optional(),
|
|
14087
|
+
industryCategory: zod.z.string().optional(),
|
|
14088
|
+
timeZone: zod.z.string().optional(),
|
|
14089
|
+
currencyCode: zod.z.string().optional(),
|
|
14090
|
+
serviceLevel: zod.z.string().optional(),
|
|
14091
|
+
account: zod.z.string().optional(),
|
|
14092
|
+
propertyType: zod.z.string().optional()
|
|
14093
|
+
});
|
|
14094
|
+
const updatePropertyOutputSchema = zod.z.object({
|
|
14095
|
+
name: zod.z.string(),
|
|
14096
|
+
displayName: zod.z.string().optional(),
|
|
14097
|
+
industryCategory: zod.z.string().optional(),
|
|
14098
|
+
timeZone: zod.z.string().optional(),
|
|
14099
|
+
currencyCode: zod.z.string().optional(),
|
|
14100
|
+
serviceLevel: zod.z.string().optional(),
|
|
14101
|
+
account: zod.z.string().optional()
|
|
14102
|
+
});
|
|
14103
|
+
function updatePropertyTool(proxy) {
|
|
14104
|
+
return (0, _mastra_core_tools.createTool)({
|
|
14105
|
+
id: "google_analytics_update_property",
|
|
14106
|
+
description: "Update a GA4 property.",
|
|
14107
|
+
inputSchema: updatePropertyInputSchema,
|
|
14108
|
+
outputSchema: updatePropertyOutputSchema,
|
|
14109
|
+
execute: async (input, { requestContext }) => {
|
|
14110
|
+
const platformProxy = proxy.withRequestContext(requestContext);
|
|
14111
|
+
const propertyId = input.name.replace(/^properties\//, "");
|
|
14112
|
+
if (!propertyId || propertyId.includes("/")) throw new platformProxy.ActionError({
|
|
14113
|
+
type: "invalid_input",
|
|
14114
|
+
message: "name must be a valid property resource name in the format \"properties/{propertyId}\"."
|
|
14115
|
+
});
|
|
14116
|
+
const updateMaskFields = [];
|
|
14117
|
+
if (input.displayName !== void 0) updateMaskFields.push("displayName");
|
|
14118
|
+
if (input.timeZone !== void 0) updateMaskFields.push("timeZone");
|
|
14119
|
+
if (input.currencyCode !== void 0) updateMaskFields.push("currencyCode");
|
|
14120
|
+
if (input.industryCategory !== void 0) updateMaskFields.push("industryCategory");
|
|
14121
|
+
if (updateMaskFields.length === 0) throw new platformProxy.ActionError({
|
|
14122
|
+
type: "invalid_input",
|
|
14123
|
+
message: "At least one field to update must be provided."
|
|
14124
|
+
});
|
|
14125
|
+
const response = await platformProxy.patch({
|
|
14126
|
+
endpoint: `/v1beta/properties/${encodeURIComponent(propertyId)}`,
|
|
14127
|
+
params: { updateMask: updateMaskFields.join(",") },
|
|
14128
|
+
data: {
|
|
14129
|
+
...input.displayName !== void 0 && { displayName: input.displayName },
|
|
14130
|
+
...input.timeZone !== void 0 && { timeZone: input.timeZone },
|
|
14131
|
+
...input.currencyCode !== void 0 && { currencyCode: input.currencyCode },
|
|
14132
|
+
...input.industryCategory !== void 0 && { industryCategory: input.industryCategory }
|
|
14133
|
+
},
|
|
14134
|
+
retries: 3,
|
|
14135
|
+
baseUrlOverride: "https://analyticsadmin.googleapis.com"
|
|
14136
|
+
});
|
|
14137
|
+
const providerProperty = ProviderPropertySchema.parse(response.data);
|
|
14138
|
+
return {
|
|
14139
|
+
name: providerProperty.name,
|
|
14140
|
+
...providerProperty.displayName !== void 0 && { displayName: providerProperty.displayName },
|
|
14141
|
+
...providerProperty.industryCategory !== void 0 && { industryCategory: providerProperty.industryCategory },
|
|
14142
|
+
...providerProperty.timeZone !== void 0 && { timeZone: providerProperty.timeZone },
|
|
14143
|
+
...providerProperty.currencyCode !== void 0 && { currencyCode: providerProperty.currencyCode },
|
|
14144
|
+
...providerProperty.serviceLevel !== void 0 && { serviceLevel: providerProperty.serviceLevel },
|
|
14145
|
+
...providerProperty.account !== void 0 && { account: providerProperty.account }
|
|
14146
|
+
};
|
|
14147
|
+
}
|
|
14148
|
+
});
|
|
14149
|
+
}
|
|
14150
|
+
//#endregion
|
|
14151
|
+
//#region src/providers/google-analytics/tools.ts
|
|
14152
|
+
function createGoogleAnalyticsTools(options) {
|
|
14153
|
+
const platformProxy = createPlatformProxy({
|
|
14154
|
+
connectionId: options?.connectionId,
|
|
14155
|
+
client: options?.client
|
|
14156
|
+
});
|
|
14157
|
+
return applyToolFilter({
|
|
14158
|
+
google_analytics_archive_conversion_event: archiveConversionEventTool(platformProxy),
|
|
14159
|
+
google_analytics_batch_run_reports: batchRunReportsTool(platformProxy),
|
|
14160
|
+
google_analytics_create_conversion_event: createConversionEventTool(platformProxy),
|
|
14161
|
+
google_analytics_create_data_stream: createDataStreamTool(platformProxy),
|
|
14162
|
+
google_analytics_create_property: createPropertyTool$1(platformProxy),
|
|
14163
|
+
google_analytics_get_metadata: getMetadataTool(platformProxy),
|
|
14164
|
+
google_analytics_run_pivot_report: runPivotReportTool(platformProxy),
|
|
14165
|
+
google_analytics_run_realtime_report: runRealtimeReportTool(platformProxy),
|
|
14166
|
+
google_analytics_run_report: runReportTool(platformProxy),
|
|
14167
|
+
google_analytics_update_data_stream: updateDataStreamTool(platformProxy),
|
|
14168
|
+
google_analytics_update_property: updatePropertyTool(platformProxy)
|
|
14169
|
+
}, {
|
|
14170
|
+
allowTools: options?.allowTools,
|
|
14171
|
+
disallowTools: options?.disallowTools
|
|
14172
|
+
});
|
|
14173
|
+
}
|
|
14174
|
+
//#endregion
|
|
14175
|
+
//#region src/providers/google-analytics/index.ts
|
|
14176
|
+
const googleAnalyticsProvider = {
|
|
14177
|
+
integrationId: "google-analytics",
|
|
14178
|
+
envVar: "MASTRA_GOOGLE_ANALYTICS_CONNECTION_ID",
|
|
14179
|
+
createTools: createGoogleAnalyticsTools
|
|
14180
|
+
};
|
|
14181
|
+
//#endregion
|
|
13371
14182
|
//#region src/providers/google-calendar/tools/add-attendee.ts
|
|
13372
14183
|
const addAttendeeInputSchema = zod.z.object({
|
|
13373
14184
|
calendarId: zod.z.string().describe("Calendar identifier. Use \"primary\" for the primary calendar. Example: \"primary\""),
|
|
@@ -73287,6 +74098,7 @@ const TOOLS = [
|
|
|
73287
74098
|
discordProvider,
|
|
73288
74099
|
firefliesProvider,
|
|
73289
74100
|
githubProvider,
|
|
74101
|
+
googleAnalyticsProvider,
|
|
73290
74102
|
googleCalendarProvider,
|
|
73291
74103
|
googleDocsProvider,
|
|
73292
74104
|
googleDriveProvider,
|