@yoryoboy/bi-mcp 1.5.0 → 1.5.2
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 +1 -2
- package/dist/.tsbuildinfo +1 -1
- package/dist/mcp-use.json +2 -2
- package/dist/src/analytics/ga4-report-utils.js +20 -47
- package/dist/src/analytics/ga4-report-utils.js.map +2 -2
- package/dist/src/config/google-store.js +96 -0
- package/dist/src/config/google-store.js.map +7 -0
- package/dist/src/config/google.js +4 -15
- package/dist/src/config/google.js.map +2 -2
- package/dist/src/services/analytics/oauth.js +20 -7
- package/dist/src/services/analytics/oauth.js.map +2 -2
- package/dist/src/services/search-console/search-console-utils.js +49 -170
- package/dist/src/services/search-console/search-console-utils.js.map +2 -2
- package/dist/src/tools/analytics/attribution-gaps.js +3 -2
- package/dist/src/tools/analytics/attribution-gaps.js.map +2 -2
- package/dist/src/tools/analytics/channel-mix.js +3 -2
- package/dist/src/tools/analytics/channel-mix.js.map +2 -2
- package/dist/src/tools/analytics/ecommerce-tracking-health.js +3 -2
- package/dist/src/tools/analytics/ecommerce-tracking-health.js.map +2 -2
- package/dist/src/tools/analytics/engagement-overview.js +3 -2
- package/dist/src/tools/analytics/engagement-overview.js.map +2 -2
- package/dist/src/tools/analytics/property-info.js +3 -2
- package/dist/src/tools/analytics/property-info.js.map +2 -2
- package/dist/src/tools/analytics/revenue-by-channel.js +3 -2
- package/dist/src/tools/analytics/revenue-by-channel.js.map +2 -2
- package/dist/src/tools/analytics/revenue-overview.js +3 -2
- package/dist/src/tools/analytics/revenue-overview.js.map +2 -2
- package/dist/src/tools/analytics/revenue-trend.js +3 -2
- package/dist/src/tools/analytics/revenue-trend.js.map +2 -2
- package/dist/src/tools/analytics/source-medium-breakdown.js +3 -2
- package/dist/src/tools/analytics/source-medium-breakdown.js.map +2 -2
- package/dist/src/tools/analytics/top-landing-pages.js +3 -2
- package/dist/src/tools/analytics/top-landing-pages.js.map +2 -2
- package/dist/src/tools/config/list-profiles.js +23 -8
- package/dist/src/tools/config/list-profiles.js.map +2 -2
- package/dist/src/tools/google-ads/account-overview.js +3 -2
- package/dist/src/tools/google-ads/account-overview.js.map +2 -2
- package/dist/src/tools/google-ads/account-risks.js +3 -2
- package/dist/src/tools/google-ads/account-risks.js.map +2 -2
- package/dist/src/tools/google-ads/break-even-analysis.js +3 -2
- package/dist/src/tools/google-ads/break-even-analysis.js.map +2 -2
- package/dist/src/tools/google-ads/campaign-performance.js +3 -2
- package/dist/src/tools/google-ads/campaign-performance.js.map +2 -2
- package/dist/src/tools/google-ads/channel-mix.js +3 -2
- package/dist/src/tools/google-ads/channel-mix.js.map +2 -2
- package/dist/src/tools/google-ads/compare-accounts.js +1 -1
- package/dist/src/tools/google-ads/compare-accounts.js.map +2 -2
- package/dist/src/tools/google-ads/customer-clients.js +3 -2
- package/dist/src/tools/google-ads/customer-clients.js.map +2 -2
- package/dist/src/tools/google-ads/customer-info.js +3 -2
- package/dist/src/tools/google-ads/customer-info.js.map +2 -2
- package/dist/src/tools/google-ads/scaling-health.js +3 -2
- package/dist/src/tools/google-ads/scaling-health.js.map +2 -2
- package/dist/src/tools/google-ads/search-terms-summary.js +3 -2
- package/dist/src/tools/google-ads/search-terms-summary.js.map +2 -2
- package/dist/src/tools/google-ads/time-series.js +3 -2
- package/dist/src/tools/google-ads/time-series.js.map +2 -2
- package/dist/src/tools/search-console/country-breakdown.js +1 -1
- package/dist/src/tools/search-console/country-breakdown.js.map +2 -2
- package/dist/src/tools/search-console/device-breakdown.js +1 -1
- package/dist/src/tools/search-console/device-breakdown.js.map +2 -2
- package/dist/src/tools/search-console/high-impression-low-click-queries.js +1 -1
- package/dist/src/tools/search-console/high-impression-low-click-queries.js.map +2 -2
- package/dist/src/tools/search-console/low-ctr-opportunities.js +1 -1
- package/dist/src/tools/search-console/low-ctr-opportunities.js.map +2 -2
- package/dist/src/tools/search-console/page-performance.js +1 -1
- package/dist/src/tools/search-console/page-performance.js.map +2 -2
- package/dist/src/tools/search-console/product-demand-low-capture-queries.js +1 -1
- package/dist/src/tools/search-console/product-demand-low-capture-queries.js.map +2 -2
- package/dist/src/tools/search-console/query-page-matrix.js +1 -1
- package/dist/src/tools/search-console/query-page-matrix.js.map +2 -2
- package/dist/src/tools/search-console/query-performance.js +1 -1
- package/dist/src/tools/search-console/query-performance.js.map +2 -2
- package/dist/src/tools/search-console/quick-win-opportunities.js +1 -1
- package/dist/src/tools/search-console/quick-win-opportunities.js.map +2 -2
- package/dist/src/tools/search-console/rising-non-brand-queries.js +1 -1
- package/dist/src/tools/search-console/rising-non-brand-queries.js.map +2 -2
- package/dist/src/tools/search-console/search-performance.js +1 -1
- package/dist/src/tools/search-console/search-performance.js.map +2 -2
- package/dist/src/tools/search-console/site-context.js +2 -2
- package/dist/src/tools/search-console/site-context.js.map +2 -2
- package/dist/src/tools/search-console/visibility-declines.js +1 -1
- package/dist/src/tools/search-console/visibility-declines.js.map +2 -2
- package/dist/src/utils/google-ads.js +15 -26
- package/dist/src/utils/google-ads.js.map +2 -2
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/tools/analytics/engagement-overview.ts"],
|
|
4
|
-
"sourcesContent": ["import { error, object } from \"mcp-use/server\";\nimport { z } from \"zod\";\n\nimport {\n extractQuotaSnapshot,\n getMetricValueByName,\n resolveGa4PropertyId,\n round,\n} from \"../../analytics/ga4-report-utils.js\";\nimport { runReport } from \"../../services/analytics/ga4-client.js\";\nimport { stripNulls } from \"../../utils/strip-payload.js\";\n\nconst dateRegex = /^\\d{4}-\\d{2}-\\d{2}$/;\n\nexport const engagementOverviewSchema = z.object({\n startDate: z.string().regex(dateRegex).describe(\"Start date in YYYY-MM-DD format\"),\n endDate: z.string().regex(dateRegex).describe(\"End date in YYYY-MM-DD format\"),\n propertyId: z.string().optional().describe(\"GA4 property ID. If omitted,
|
|
5
|
-
"mappings": "AAAA,SAAS,OAAO,cAAc;AAC9B,SAAS,SAAS;AAElB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB;AAE3B,MAAM,YAAY;AAEX,MAAM,2BAA2B,EAAE,OAAO;AAAA,EAC/C,WAAW,EAAE,OAAO,EAAE,MAAM,SAAS,EAAE,SAAS,iCAAiC;AAAA,EACjF,SAAS,EAAE,OAAO,EAAE,MAAM,SAAS,EAAE,SAAS,+BAA+B;AAAA,EAC7E,YAAY,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,
|
|
4
|
+
"sourcesContent": ["import { error, object } from \"mcp-use/server\";\nimport { z } from \"zod\";\n\nimport {\n extractQuotaSnapshot,\n getMetricValueByName,\n resolveGa4PropertyId,\n round,\n} from \"../../analytics/ga4-report-utils.js\";\nimport { runReport } from \"../../services/analytics/ga4-client.js\";\nimport { stripNulls } from \"../../utils/strip-payload.js\";\n\nconst dateRegex = /^\\d{4}-\\d{2}-\\d{2}$/;\n\nexport const engagementOverviewSchema = z.object({\n startDate: z.string().regex(dateRegex).describe(\"Start date in YYYY-MM-DD format\"),\n endDate: z.string().regex(dateRegex).describe(\"End date in YYYY-MM-DD format\"),\n propertyId: z.string().optional().describe(\"GA4 property ID. If omitted, resolves profileId mapping first and then GA4_PROPERTY_ID.\"),\n profileId: z.string().optional().describe(\"Optional business profile ID used to resolve the mapped GA4 property.\"),\n});\n\nexport async function engagementOverviewHandler(params: z.infer<typeof engagementOverviewSchema>) {\n try {\n const propertyId = await resolveGa4PropertyId(params.propertyId, params.profileId);\n const report = await runReport(propertyId, {\n dateRanges: [{ startDate: params.startDate, endDate: params.endDate }],\n metrics: [\n { name: \"sessions\" },\n { name: \"engagedSessions\" },\n { name: \"engagementRate\" },\n { name: \"averageSessionDuration\" },\n { name: \"screenPageViews\" },\n { name: \"screenPageViewsPerSession\" },\n { name: \"bounceRate\" },\n { name: \"userEngagementDuration\" },\n ],\n returnPropertyQuota: true,\n });\n\n const row = report.rows?.[0] ?? {};\n\n return object(\n stripNulls({\n property_id: propertyId,\n date_range: {\n start_date: params.startDate,\n end_date: params.endDate,\n },\n overview: {\n sessions: getMetricValueByName(row, report.metricHeaders, \"sessions\"),\n engaged_sessions: getMetricValueByName(row, report.metricHeaders, \"engagedSessions\"),\n engagement_rate_percent: round(\n getMetricValueByName(row, report.metricHeaders, \"engagementRate\") * 100\n ),\n bounce_rate_percent: round(getMetricValueByName(row, report.metricHeaders, \"bounceRate\") * 100),\n average_session_duration_seconds: round(\n getMetricValueByName(row, report.metricHeaders, \"averageSessionDuration\")\n ),\n views: getMetricValueByName(row, report.metricHeaders, \"screenPageViews\"),\n views_per_session: round(\n getMetricValueByName(row, report.metricHeaders, \"screenPageViewsPerSession\")\n ),\n user_engagement_duration_seconds: round(\n getMetricValueByName(row, report.metricHeaders, \"userEngagementDuration\")\n ),\n },\n quota: extractQuotaSnapshot(report),\n })\n );\n } catch (err) {\n return error(err instanceof Error ? err.message : \"Failed to fetch GA4 engagement overview\");\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,OAAO,cAAc;AAC9B,SAAS,SAAS;AAElB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB;AAE3B,MAAM,YAAY;AAEX,MAAM,2BAA2B,EAAE,OAAO;AAAA,EAC/C,WAAW,EAAE,OAAO,EAAE,MAAM,SAAS,EAAE,SAAS,iCAAiC;AAAA,EACjF,SAAS,EAAE,OAAO,EAAE,MAAM,SAAS,EAAE,SAAS,+BAA+B;AAAA,EAC7E,YAAY,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,yFAAyF;AAAA,EACpI,WAAW,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,uEAAuE;AACnH,CAAC;AAED,eAAsB,0BAA0B,QAAkD;AAChG,MAAI;AACF,UAAM,aAAa,MAAM,qBAAqB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B,MAAM;AAAA,MACpC,CAAC;AAAA,IACH;AAAA,EACF,SAAS,KAAK;AACZ,WAAO,MAAM,eAAe,QAAQ,IAAI,UAAU,yCAAyC;AAAA,EAC7F;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -4,11 +4,12 @@ import { findPropertySummary, resolveGa4PropertyId } from "../../analytics/ga4-r
|
|
|
4
4
|
import { getMetadata, listAccountSummaries } from "../../services/analytics/ga4-client.js";
|
|
5
5
|
import { stripNulls } from "../../utils/strip-payload.js";
|
|
6
6
|
const propertyInfoSchema = z.object({
|
|
7
|
-
propertyId: z.string().optional().describe("GA4 property ID. If omitted,
|
|
7
|
+
propertyId: z.string().optional().describe("GA4 property ID. If omitted, resolves profileId mapping first and then GA4_PROPERTY_ID."),
|
|
8
|
+
profileId: z.string().optional().describe("Optional business profile ID used to resolve the mapped GA4 property.")
|
|
8
9
|
});
|
|
9
10
|
async function propertyInfoHandler(params) {
|
|
10
11
|
try {
|
|
11
|
-
const propertyId = resolveGa4PropertyId(params.propertyId);
|
|
12
|
+
const propertyId = await resolveGa4PropertyId(params.propertyId, params.profileId);
|
|
12
13
|
const [{ accountSummaries }, metadata] = await Promise.all([
|
|
13
14
|
listAccountSummaries(),
|
|
14
15
|
getMetadata(propertyId)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/tools/analytics/property-info.ts"],
|
|
4
|
-
"sourcesContent": ["import { error, object } from \"mcp-use/server\";\nimport { z } from \"zod\";\n\nimport { findPropertySummary, resolveGa4PropertyId } from \"../../analytics/ga4-report-utils.js\";\nimport { getMetadata, listAccountSummaries } from \"../../services/analytics/ga4-client.js\";\nimport { stripNulls } from \"../../utils/strip-payload.js\";\n\nexport const propertyInfoSchema = z.object({\n propertyId: z.string().optional().describe(\"GA4 property ID. If omitted,
|
|
5
|
-
"mappings": "AAAA,SAAS,OAAO,cAAc;AAC9B,SAAS,SAAS;AAElB,SAAS,qBAAqB,4BAA4B;AAC1D,SAAS,aAAa,4BAA4B;AAClD,SAAS,kBAAkB;AAEpB,MAAM,qBAAqB,EAAE,OAAO;AAAA,EACzC,YAAY,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,
|
|
4
|
+
"sourcesContent": ["import { error, object } from \"mcp-use/server\";\nimport { z } from \"zod\";\n\nimport { findPropertySummary, resolveGa4PropertyId } from \"../../analytics/ga4-report-utils.js\";\nimport { getMetadata, listAccountSummaries } from \"../../services/analytics/ga4-client.js\";\nimport { stripNulls } from \"../../utils/strip-payload.js\";\n\nexport const propertyInfoSchema = z.object({\n propertyId: z.string().optional().describe(\"GA4 property ID. If omitted, resolves profileId mapping first and then GA4_PROPERTY_ID.\"),\n profileId: z.string().optional().describe(\"Optional business profile ID used to resolve the mapped GA4 property.\"),\n});\n\nexport async function propertyInfoHandler(params: z.infer<typeof propertyInfoSchema>) {\n try {\n const propertyId = await resolveGa4PropertyId(params.propertyId, params.profileId);\n\n const [{ accountSummaries }, metadata] = await Promise.all([\n listAccountSummaries(),\n getMetadata(propertyId),\n ]);\n\n const propertySummary = findPropertySummary(accountSummaries, propertyId);\n const dimensions = metadata.dimensions ?? [];\n const metrics = metadata.metrics ?? [];\n\n return object(\n stripNulls({\n property: {\n property_id: propertyId,\n property_name: propertySummary?.propertyName,\n property_type: propertySummary?.propertyType,\n account_id: propertySummary?.accountId,\n account_name: propertySummary?.accountName,\n },\n capabilities: {\n supports_ecommerce:\n metrics.some((metric) => metric.apiName === \"purchaseRevenue\") &&\n metrics.some((metric) => metric.apiName === \"transactions\"),\n supports_google_ads_dimensions: dimensions.some((dimension) =>\n dimension.apiName.startsWith(\"sessionGoogleAds\")\n ),\n supports_search_console_metrics: metrics.some((metric) =>\n metric.apiName.startsWith(\"organicGoogleSearch\")\n ),\n custom_channel_groups: dimensions\n .filter((dimension) => dimension.apiName.includes(\"CustomChannelGroup\"))\n .map((dimension) => dimension.apiName),\n },\n metadata_summary: {\n total_dimensions: dimensions.length,\n total_metrics: metrics.length,\n sample_dimensions: dimensions.slice(0, 12).map((dimension) => dimension.apiName),\n sample_metrics: metrics.slice(0, 12).map((metric) => metric.apiName),\n },\n })\n );\n } catch (err) {\n return error(err instanceof Error ? err.message : \"Failed to fetch GA4 property info\");\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,OAAO,cAAc;AAC9B,SAAS,SAAS;AAElB,SAAS,qBAAqB,4BAA4B;AAC1D,SAAS,aAAa,4BAA4B;AAClD,SAAS,kBAAkB;AAEpB,MAAM,qBAAqB,EAAE,OAAO;AAAA,EACzC,YAAY,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,yFAAyF;AAAA,EACpI,WAAW,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,uEAAuE;AACnH,CAAC;AAED,eAAsB,oBAAoB,QAA4C;AACpF,MAAI;AACF,UAAM,aAAa,MAAM,qBAAqB,OAAO,YAAY,OAAO,SAAS;AAEjF,UAAM,CAAC,EAAE,iBAAiB,GAAG,QAAQ,IAAI,MAAM,QAAQ,IAAI;AAAA,MACzD,qBAAqB;AAAA,MACrB,YAAY,UAAU;AAAA,IACxB,CAAC;AAED,UAAM,kBAAkB,oBAAoB,kBAAkB,UAAU;AACxE,UAAM,aAAa,SAAS,cAAc,CAAC;AAC3C,UAAM,UAAU,SAAS,WAAW,CAAC;AAErC,WAAO;AAAA,MACL,WAAW;AAAA,QACT,UAAU;AAAA,UACR,aAAa;AAAA,UACb,eAAe,iBAAiB;AAAA,UAChC,eAAe,iBAAiB;AAAA,UAChC,YAAY,iBAAiB;AAAA,UAC7B,cAAc,iBAAiB;AAAA,QACjC;AAAA,QACA,cAAc;AAAA,UACZ,oBACE,QAAQ,KAAK,CAAC,WAAW,OAAO,YAAY,iBAAiB,KAC7D,QAAQ,KAAK,CAAC,WAAW,OAAO,YAAY,cAAc;AAAA,UAC5D,gCAAgC,WAAW;AAAA,YAAK,CAAC,cAC/C,UAAU,QAAQ,WAAW,kBAAkB;AAAA,UACjD;AAAA,UACA,iCAAiC,QAAQ;AAAA,YAAK,CAAC,WAC7C,OAAO,QAAQ,WAAW,qBAAqB;AAAA,UACjD;AAAA,UACA,uBAAuB,WACpB,OAAO,CAAC,cAAc,UAAU,QAAQ,SAAS,oBAAoB,CAAC,EACtE,IAAI,CAAC,cAAc,UAAU,OAAO;AAAA,QACzC;AAAA,QACA,kBAAkB;AAAA,UAChB,kBAAkB,WAAW;AAAA,UAC7B,eAAe,QAAQ;AAAA,UACvB,mBAAmB,WAAW,MAAM,GAAG,EAAE,EAAE,IAAI,CAAC,cAAc,UAAU,OAAO;AAAA,UAC/E,gBAAgB,QAAQ,MAAM,GAAG,EAAE,EAAE,IAAI,CAAC,WAAW,OAAO,OAAO;AAAA,QACrE;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF,SAAS,KAAK;AACZ,WAAO,MAAM,eAAe,QAAQ,IAAI,UAAU,mCAAmC;AAAA,EACvF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -15,11 +15,12 @@ const dateRegex = /^\d{4}-\d{2}-\d{2}$/;
|
|
|
15
15
|
const revenueByChannelSchema = z.object({
|
|
16
16
|
startDate: z.string().regex(dateRegex).describe("Start date in YYYY-MM-DD format"),
|
|
17
17
|
endDate: z.string().regex(dateRegex).describe("End date in YYYY-MM-DD format"),
|
|
18
|
-
propertyId: z.string().optional().describe("GA4 property ID. If omitted,
|
|
18
|
+
propertyId: z.string().optional().describe("GA4 property ID. If omitted, resolves profileId mapping first and then GA4_PROPERTY_ID."),
|
|
19
|
+
profileId: z.string().optional().describe("Optional business profile ID used to resolve the mapped GA4 property.")
|
|
19
20
|
});
|
|
20
21
|
async function revenueByChannelHandler(params) {
|
|
21
22
|
try {
|
|
22
|
-
const propertyId = resolveGa4PropertyId(params.propertyId);
|
|
23
|
+
const propertyId = await resolveGa4PropertyId(params.propertyId, params.profileId);
|
|
23
24
|
const report = await runReport(propertyId, {
|
|
24
25
|
dateRanges: [{ startDate: params.startDate, endDate: params.endDate }],
|
|
25
26
|
dimensions: [{ name: "sessionDefaultChannelGroup" }],
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/tools/analytics/revenue-by-channel.ts"],
|
|
4
|
-
"sourcesContent": ["import { error, object } from \"mcp-use/server\";\nimport { z } from \"zod\";\n\nimport {\n extractQuotaSnapshot,\n getDimensionValue,\n getMetricValueByName,\n resolveGa4PropertyId,\n round,\n sumMetricValues,\n toPercent,\n} from \"../../analytics/ga4-report-utils.js\";\nimport { runReport } from \"../../services/analytics/ga4-client.js\";\nimport { stripNulls } from \"../../utils/strip-payload.js\";\n\nconst dateRegex = /^\\d{4}-\\d{2}-\\d{2}$/;\n\nexport const revenueByChannelSchema = z.object({\n startDate: z.string().regex(dateRegex).describe(\"Start date in YYYY-MM-DD format\"),\n endDate: z.string().regex(dateRegex).describe(\"End date in YYYY-MM-DD format\"),\n propertyId: z.string().optional().describe(\"GA4 property ID. If omitted,
|
|
5
|
-
"mappings": "AAAA,SAAS,OAAO,cAAc;AAC9B,SAAS,SAAS;AAElB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB;AAE3B,MAAM,YAAY;AAEX,MAAM,yBAAyB,EAAE,OAAO;AAAA,EAC7C,WAAW,EAAE,OAAO,EAAE,MAAM,SAAS,EAAE,SAAS,iCAAiC;AAAA,EACjF,SAAS,EAAE,OAAO,EAAE,MAAM,SAAS,EAAE,SAAS,+BAA+B;AAAA,EAC7E,YAAY,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,
|
|
4
|
+
"sourcesContent": ["import { error, object } from \"mcp-use/server\";\nimport { z } from \"zod\";\n\nimport {\n extractQuotaSnapshot,\n getDimensionValue,\n getMetricValueByName,\n resolveGa4PropertyId,\n round,\n sumMetricValues,\n toPercent,\n} from \"../../analytics/ga4-report-utils.js\";\nimport { runReport } from \"../../services/analytics/ga4-client.js\";\nimport { stripNulls } from \"../../utils/strip-payload.js\";\n\nconst dateRegex = /^\\d{4}-\\d{2}-\\d{2}$/;\n\nexport const revenueByChannelSchema = z.object({\n startDate: z.string().regex(dateRegex).describe(\"Start date in YYYY-MM-DD format\"),\n endDate: z.string().regex(dateRegex).describe(\"End date in YYYY-MM-DD format\"),\n propertyId: z.string().optional().describe(\"GA4 property ID. If omitted, resolves profileId mapping first and then GA4_PROPERTY_ID.\"),\n profileId: z.string().optional().describe(\"Optional business profile ID used to resolve the mapped GA4 property.\"),\n});\n\nexport async function revenueByChannelHandler(params: z.infer<typeof revenueByChannelSchema>) {\n try {\n const propertyId = await resolveGa4PropertyId(params.propertyId, params.profileId);\n const report = await runReport(propertyId, {\n dateRanges: [{ startDate: params.startDate, endDate: params.endDate }],\n dimensions: [{ name: \"sessionDefaultChannelGroup\" }],\n metrics: [{ name: \"transactions\" }, { name: \"purchaseRevenue\" }, { name: \"sessions\" }],\n orderBys: [{ metric: { metricName: \"purchaseRevenue\" }, desc: true }],\n returnPropertyQuota: true,\n });\n\n const totalRevenue = sumMetricValues(report.rows, report.metricHeaders, \"purchaseRevenue\");\n const totalTransactions = sumMetricValues(report.rows, report.metricHeaders, \"transactions\");\n\n const channels = (report.rows ?? []).map((row) => {\n const revenue = getMetricValueByName(row, report.metricHeaders, \"purchaseRevenue\");\n const transactions = getMetricValueByName(row, report.metricHeaders, \"transactions\");\n const sessions = getMetricValueByName(row, report.metricHeaders, \"sessions\");\n\n return {\n channel: getDimensionValue(row),\n sessions,\n transactions,\n purchase_revenue: round(revenue),\n revenue_share_percent: round(toPercent(revenue, totalRevenue)),\n transaction_share_percent: round(toPercent(transactions, totalTransactions)),\n };\n });\n\n return object(\n stripNulls({\n property_id: propertyId,\n date_range: {\n start_date: params.startDate,\n end_date: params.endDate,\n },\n currency_code: report.metadata?.currencyCode,\n overview: {\n total_purchase_revenue: round(totalRevenue),\n total_transactions: totalTransactions,\n top_revenue_channel: channels[0]?.channel,\n },\n channels,\n quota: extractQuotaSnapshot(report),\n })\n );\n } catch (err) {\n return error(err instanceof Error ? err.message : \"Failed to fetch GA4 revenue by channel\");\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,OAAO,cAAc;AAC9B,SAAS,SAAS;AAElB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB;AAE3B,MAAM,YAAY;AAEX,MAAM,yBAAyB,EAAE,OAAO;AAAA,EAC7C,WAAW,EAAE,OAAO,EAAE,MAAM,SAAS,EAAE,SAAS,iCAAiC;AAAA,EACjF,SAAS,EAAE,OAAO,EAAE,MAAM,SAAS,EAAE,SAAS,+BAA+B;AAAA,EAC7E,YAAY,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,yFAAyF;AAAA,EACpI,WAAW,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,uEAAuE;AACnH,CAAC;AAED,eAAsB,wBAAwB,QAAgD;AAC5F,MAAI;AACF,UAAM,aAAa,MAAM,qBAAqB,OAAO,YAAY,OAAO,SAAS;AACjF,UAAM,SAAS,MAAM,UAAU,YAAY;AAAA,MACzC,YAAY,CAAC,EAAE,WAAW,OAAO,WAAW,SAAS,OAAO,QAAQ,CAAC;AAAA,MACrE,YAAY,CAAC,EAAE,MAAM,6BAA6B,CAAC;AAAA,MACnD,SAAS,CAAC,EAAE,MAAM,eAAe,GAAG,EAAE,MAAM,kBAAkB,GAAG,EAAE,MAAM,WAAW,CAAC;AAAA,MACrF,UAAU,CAAC,EAAE,QAAQ,EAAE,YAAY,kBAAkB,GAAG,MAAM,KAAK,CAAC;AAAA,MACpE,qBAAqB;AAAA,IACvB,CAAC;AAED,UAAM,eAAe,gBAAgB,OAAO,MAAM,OAAO,eAAe,iBAAiB;AACzF,UAAM,oBAAoB,gBAAgB,OAAO,MAAM,OAAO,eAAe,cAAc;AAE3F,UAAM,YAAY,OAAO,QAAQ,CAAC,GAAG,IAAI,CAAC,QAAQ;AAChD,YAAM,UAAU,qBAAqB,KAAK,OAAO,eAAe,iBAAiB;AACjF,YAAM,eAAe,qBAAqB,KAAK,OAAO,eAAe,cAAc;AACnF,YAAM,WAAW,qBAAqB,KAAK,OAAO,eAAe,UAAU;AAE3E,aAAO;AAAA,QACL,SAAS,kBAAkB,GAAG;AAAA,QAC9B;AAAA,QACA;AAAA,QACA,kBAAkB,MAAM,OAAO;AAAA,QAC/B,uBAAuB,MAAM,UAAU,SAAS,YAAY,CAAC;AAAA,QAC7D,2BAA2B,MAAM,UAAU,cAAc,iBAAiB,CAAC;AAAA,MAC7E;AAAA,IACF,CAAC;AAED,WAAO;AAAA,MACL,WAAW;AAAA,QACT,aAAa;AAAA,QACb,YAAY;AAAA,UACV,YAAY,OAAO;AAAA,UACnB,UAAU,OAAO;AAAA,QACnB;AAAA,QACA,eAAe,OAAO,UAAU;AAAA,QAChC,UAAU;AAAA,UACR,wBAAwB,MAAM,YAAY;AAAA,UAC1C,oBAAoB;AAAA,UACpB,qBAAqB,SAAS,CAAC,GAAG;AAAA,QACpC;AAAA,QACA;AAAA,QACA,OAAO,qBAAqB,MAAM;AAAA,MACpC,CAAC;AAAA,IACH;AAAA,EACF,SAAS,KAAK;AACZ,WAAO,MAAM,eAAe,QAAQ,IAAI,UAAU,wCAAwC;AAAA,EAC5F;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -13,11 +13,12 @@ const dateRegex = /^\d{4}-\d{2}-\d{2}$/;
|
|
|
13
13
|
const revenueOverviewSchema = z.object({
|
|
14
14
|
startDate: z.string().regex(dateRegex).describe("Start date in YYYY-MM-DD format"),
|
|
15
15
|
endDate: z.string().regex(dateRegex).describe("End date in YYYY-MM-DD format"),
|
|
16
|
-
propertyId: z.string().optional().describe("GA4 property ID. If omitted,
|
|
16
|
+
propertyId: z.string().optional().describe("GA4 property ID. If omitted, resolves profileId mapping first and then GA4_PROPERTY_ID."),
|
|
17
|
+
profileId: z.string().optional().describe("Optional business profile ID used to resolve the mapped GA4 property.")
|
|
17
18
|
});
|
|
18
19
|
async function revenueOverviewHandler(params) {
|
|
19
20
|
try {
|
|
20
|
-
const propertyId = resolveGa4PropertyId(params.propertyId);
|
|
21
|
+
const propertyId = await resolveGa4PropertyId(params.propertyId, params.profileId);
|
|
21
22
|
const report = await runReport(propertyId, {
|
|
22
23
|
dateRanges: [{ startDate: params.startDate, endDate: params.endDate }],
|
|
23
24
|
metrics: [
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/tools/analytics/revenue-overview.ts"],
|
|
4
|
-
"sourcesContent": ["import { error, object } from \"mcp-use/server\";\nimport { z } from \"zod\";\n\nimport {\n extractQuotaSnapshot,\n getMetricValueByName,\n resolveGa4PropertyId,\n round,\n toPercent,\n} from \"../../analytics/ga4-report-utils.js\";\nimport { runReport } from \"../../services/analytics/ga4-client.js\";\nimport { stripNulls } from \"../../utils/strip-payload.js\";\n\nconst dateRegex = /^\\d{4}-\\d{2}-\\d{2}$/;\n\nexport const revenueOverviewSchema = z.object({\n startDate: z.string().regex(dateRegex).describe(\"Start date in YYYY-MM-DD format\"),\n endDate: z.string().regex(dateRegex).describe(\"End date in YYYY-MM-DD format\"),\n propertyId: z.string().optional().describe(\"GA4 property ID. If omitted,
|
|
5
|
-
"mappings": "AAAA,SAAS,OAAO,cAAc;AAC9B,SAAS,SAAS;AAElB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB;AAE3B,MAAM,YAAY;AAEX,MAAM,wBAAwB,EAAE,OAAO;AAAA,EAC5C,WAAW,EAAE,OAAO,EAAE,MAAM,SAAS,EAAE,SAAS,iCAAiC;AAAA,EACjF,SAAS,EAAE,OAAO,EAAE,MAAM,SAAS,EAAE,SAAS,+BAA+B;AAAA,EAC7E,YAAY,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,
|
|
4
|
+
"sourcesContent": ["import { error, object } from \"mcp-use/server\";\nimport { z } from \"zod\";\n\nimport {\n extractQuotaSnapshot,\n getMetricValueByName,\n resolveGa4PropertyId,\n round,\n toPercent,\n} from \"../../analytics/ga4-report-utils.js\";\nimport { runReport } from \"../../services/analytics/ga4-client.js\";\nimport { stripNulls } from \"../../utils/strip-payload.js\";\n\nconst dateRegex = /^\\d{4}-\\d{2}-\\d{2}$/;\n\nexport const revenueOverviewSchema = z.object({\n startDate: z.string().regex(dateRegex).describe(\"Start date in YYYY-MM-DD format\"),\n endDate: z.string().regex(dateRegex).describe(\"End date in YYYY-MM-DD format\"),\n propertyId: z.string().optional().describe(\"GA4 property ID. If omitted, resolves profileId mapping first and then GA4_PROPERTY_ID.\"),\n profileId: z.string().optional().describe(\"Optional business profile ID used to resolve the mapped GA4 property.\"),\n});\n\nexport async function revenueOverviewHandler(params: z.infer<typeof revenueOverviewSchema>) {\n try {\n const propertyId = await resolveGa4PropertyId(params.propertyId, params.profileId);\n const report = await runReport(propertyId, {\n dateRanges: [{ startDate: params.startDate, endDate: params.endDate }],\n metrics: [\n { name: \"sessions\" },\n { name: \"totalUsers\" },\n { name: \"transactions\" },\n { name: \"purchaseRevenue\" },\n { name: \"averagePurchaseRevenue\" },\n { name: \"totalPurchasers\" },\n { name: \"purchaserRate\" },\n ],\n returnPropertyQuota: true,\n });\n\n const row = report.rows?.[0] ?? {};\n const sessions = getMetricValueByName(row, report.metricHeaders, \"sessions\");\n const totalUsers = getMetricValueByName(row, report.metricHeaders, \"totalUsers\");\n const transactions = getMetricValueByName(row, report.metricHeaders, \"transactions\");\n const purchaseRevenue = getMetricValueByName(row, report.metricHeaders, \"purchaseRevenue\");\n const averagePurchaseRevenue = getMetricValueByName(\n row,\n report.metricHeaders,\n \"averagePurchaseRevenue\"\n );\n const totalPurchasers = getMetricValueByName(row, report.metricHeaders, \"totalPurchasers\");\n const purchaserRate = getMetricValueByName(row, report.metricHeaders, \"purchaserRate\");\n\n return object(\n stripNulls({\n property_id: propertyId,\n date_range: {\n start_date: params.startDate,\n end_date: params.endDate,\n },\n currency_code: report.metadata?.currencyCode,\n overview: {\n sessions,\n total_users: totalUsers,\n transactions,\n total_purchasers: totalPurchasers,\n purchase_revenue: round(purchaseRevenue),\n average_purchase_revenue: round(averagePurchaseRevenue),\n purchaser_rate_percent: round(purchaserRate * 100),\n transactions_per_session_percent: round(toPercent(transactions, sessions)),\n transactions_per_user_percent: round(toPercent(transactions, totalUsers)),\n revenue_per_session: round(sessions > 0 ? purchaseRevenue / sessions : 0),\n },\n quota: extractQuotaSnapshot(report),\n })\n );\n } catch (err) {\n return error(err instanceof Error ? err.message : \"Failed to fetch GA4 revenue overview\");\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,OAAO,cAAc;AAC9B,SAAS,SAAS;AAElB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB;AAE3B,MAAM,YAAY;AAEX,MAAM,wBAAwB,EAAE,OAAO;AAAA,EAC5C,WAAW,EAAE,OAAO,EAAE,MAAM,SAAS,EAAE,SAAS,iCAAiC;AAAA,EACjF,SAAS,EAAE,OAAO,EAAE,MAAM,SAAS,EAAE,SAAS,+BAA+B;AAAA,EAC7E,YAAY,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,yFAAyF;AAAA,EACpI,WAAW,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,uEAAuE;AACnH,CAAC;AAED,eAAsB,uBAAuB,QAA+C;AAC1F,MAAI;AACF,UAAM,aAAa,MAAM,qBAAqB,OAAO,YAAY,OAAO,SAAS;AACjF,UAAM,SA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,UAAU,cAAc,UAAU,CAAC;AAAA,UACxE,qBAAqB,MAAM,WAAW,IAAI,kBAAkB,WAAW,CAAC;AAAA,QAC1E;AAAA,QACA,OAAO,qBAAqB,MAAM;AAAA,MACpC,CAAC;AAAA,IACH;AAAA,EACF,SAAS,KAAK;AACZ,WAAO,MAAM,eAAe,QAAQ,IAAI,UAAU,sCAAsC;AAAA,EAC1F;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -14,11 +14,12 @@ const dateRegex = /^\d{4}-\d{2}-\d{2}$/;
|
|
|
14
14
|
const revenueTrendSchema = z.object({
|
|
15
15
|
startDate: z.string().regex(dateRegex).describe("Start date in YYYY-MM-DD format"),
|
|
16
16
|
endDate: z.string().regex(dateRegex).describe("End date in YYYY-MM-DD format"),
|
|
17
|
-
propertyId: z.string().optional().describe("GA4 property ID. If omitted,
|
|
17
|
+
propertyId: z.string().optional().describe("GA4 property ID. If omitted, resolves profileId mapping first and then GA4_PROPERTY_ID."),
|
|
18
|
+
profileId: z.string().optional().describe("Optional business profile ID used to resolve the mapped GA4 property.")
|
|
18
19
|
});
|
|
19
20
|
async function revenueTrendHandler(params) {
|
|
20
21
|
try {
|
|
21
|
-
const propertyId = resolveGa4PropertyId(params.propertyId);
|
|
22
|
+
const propertyId = await resolveGa4PropertyId(params.propertyId, params.profileId);
|
|
22
23
|
const report = await runReport(propertyId, {
|
|
23
24
|
dateRanges: [{ startDate: params.startDate, endDate: params.endDate }],
|
|
24
25
|
dimensions: [{ name: "date" }],
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/tools/analytics/revenue-trend.ts"],
|
|
4
|
-
"sourcesContent": ["import { error, object } from \"mcp-use/server\";\nimport { z } from \"zod\";\n\nimport {\n extractQuotaSnapshot,\n formatGa4Date,\n getDimensionValue,\n getMetricValueByName,\n resolveGa4PropertyId,\n round,\n} from \"../../analytics/ga4-report-utils.js\";\nimport { runReport } from \"../../services/analytics/ga4-client.js\";\nimport { stripNulls } from \"../../utils/strip-payload.js\";\n\nconst dateRegex = /^\\d{4}-\\d{2}-\\d{2}$/;\n\nexport const revenueTrendSchema = z.object({\n startDate: z.string().regex(dateRegex).describe(\"Start date in YYYY-MM-DD format\"),\n endDate: z.string().regex(dateRegex).describe(\"End date in YYYY-MM-DD format\"),\n propertyId: z.string().optional().describe(\"GA4 property ID. If omitted,
|
|
5
|
-
"mappings": "AAAA,SAAS,OAAO,cAAc;AAC9B,SAAS,SAAS;AAElB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB;AAE3B,MAAM,YAAY;AAEX,MAAM,qBAAqB,EAAE,OAAO;AAAA,EACzC,WAAW,EAAE,OAAO,EAAE,MAAM,SAAS,EAAE,SAAS,iCAAiC;AAAA,EACjF,SAAS,EAAE,OAAO,EAAE,MAAM,SAAS,EAAE,SAAS,+BAA+B;AAAA,EAC7E,YAAY,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,
|
|
4
|
+
"sourcesContent": ["import { error, object } from \"mcp-use/server\";\nimport { z } from \"zod\";\n\nimport {\n extractQuotaSnapshot,\n formatGa4Date,\n getDimensionValue,\n getMetricValueByName,\n resolveGa4PropertyId,\n round,\n} from \"../../analytics/ga4-report-utils.js\";\nimport { runReport } from \"../../services/analytics/ga4-client.js\";\nimport { stripNulls } from \"../../utils/strip-payload.js\";\n\nconst dateRegex = /^\\d{4}-\\d{2}-\\d{2}$/;\n\nexport const revenueTrendSchema = z.object({\n startDate: z.string().regex(dateRegex).describe(\"Start date in YYYY-MM-DD format\"),\n endDate: z.string().regex(dateRegex).describe(\"End date in YYYY-MM-DD format\"),\n propertyId: z.string().optional().describe(\"GA4 property ID. If omitted, resolves profileId mapping first and then GA4_PROPERTY_ID.\"),\n profileId: z.string().optional().describe(\"Optional business profile ID used to resolve the mapped GA4 property.\"),\n});\n\nexport async function revenueTrendHandler(params: z.infer<typeof revenueTrendSchema>) {\n try {\n const propertyId = await resolveGa4PropertyId(params.propertyId, params.profileId);\n const report = await runReport(propertyId, {\n dateRanges: [{ startDate: params.startDate, endDate: params.endDate }],\n dimensions: [{ name: \"date\" }],\n metrics: [{ name: \"transactions\" }, { name: \"purchaseRevenue\" }],\n orderBys: [{ dimension: { dimensionName: \"date\" } }],\n returnPropertyQuota: true,\n });\n\n const daily = (report.rows ?? []).map((row) => ({\n date: formatGa4Date(getDimensionValue(row)),\n transactions: getMetricValueByName(row, report.metricHeaders, \"transactions\"),\n purchase_revenue: round(getMetricValueByName(row, report.metricHeaders, \"purchaseRevenue\")),\n }));\n\n const totalRevenue = daily.reduce((total, day) => total + day.purchase_revenue, 0);\n const totalTransactions = daily.reduce((total, day) => total + day.transactions, 0);\n const topRevenueDay = daily.reduce<(typeof daily)[number] | undefined>((currentTop, day) => {\n if (!currentTop || day.purchase_revenue > currentTop.purchase_revenue) {\n return day;\n }\n\n return currentTop;\n }, undefined);\n\n return object(\n stripNulls({\n property_id: propertyId,\n date_range: {\n start_date: params.startDate,\n end_date: params.endDate,\n },\n currency_code: report.metadata?.currencyCode,\n overview: {\n days: daily.length,\n total_transactions: totalTransactions,\n total_purchase_revenue: round(totalRevenue),\n average_daily_revenue: round(daily.length > 0 ? totalRevenue / daily.length : 0),\n top_revenue_day: topRevenueDay,\n },\n daily,\n quota: extractQuotaSnapshot(report),\n })\n );\n } catch (err) {\n return error(err instanceof Error ? err.message : \"Failed to fetch GA4 revenue trend\");\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,OAAO,cAAc;AAC9B,SAAS,SAAS;AAElB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB;AAE3B,MAAM,YAAY;AAEX,MAAM,qBAAqB,EAAE,OAA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AAA,MACT;AAEA,aAAO;AAAA,IACT,GAAG,MAAS;AAEZ,WAAO;AAAA,MACL,WAAW;AAAA,QACT,aAAa;AAAA,QACb,YAAY;AAAA,UACV,YAAY,OAAO;AAAA,UACnB,UAAU,OAAO;AAAA,QACnB;AAAA,QACA,eAAe,OAAO,UAAU;AAAA,QAChC,UAAU;AAAA,UACR,MAAM,MAAM;AAAA,UACZ,oBAAoB;AAAA,UACpB,wBAAwB,MAAM,YAAY;AAAA,UAC1C,uBAAuB,MAAM,MAAM,SAAS,IAAI,eAAe,MAAM,SAAS,CAAC;AAAA,UAC/E,iBAAiB;AAAA,QACnB;AAAA,QACA;AAAA,QACA,OAAO,qBAAqB,MAAM;AAAA,MACpC,CAAC;AAAA,IACH;AAAA,EACF,SAAS,KAAK;AACZ,WAAO,MAAM,eAAe,QAAQ,IAAI,UAAU,mCAAmC;AAAA,EACvF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -14,12 +14,13 @@ const dateRegex = /^\d{4}-\d{2}-\d{2}$/;
|
|
|
14
14
|
const sourceMediumBreakdownSchema = z.object({
|
|
15
15
|
startDate: z.string().regex(dateRegex).describe("Start date in YYYY-MM-DD format"),
|
|
16
16
|
endDate: z.string().regex(dateRegex).describe("End date in YYYY-MM-DD format"),
|
|
17
|
-
propertyId: z.string().optional().describe("GA4 property ID. If omitted,
|
|
17
|
+
propertyId: z.string().optional().describe("GA4 property ID. If omitted, resolves profileId mapping first and then GA4_PROPERTY_ID."),
|
|
18
|
+
profileId: z.string().optional().describe("Optional business profile ID used to resolve the mapped GA4 property."),
|
|
18
19
|
limit: z.number().int().min(1).max(100).optional().describe("Maximum rows to return")
|
|
19
20
|
});
|
|
20
21
|
async function sourceMediumBreakdownHandler(params) {
|
|
21
22
|
try {
|
|
22
|
-
const propertyId = resolveGa4PropertyId(params.propertyId);
|
|
23
|
+
const propertyId = await resolveGa4PropertyId(params.propertyId, params.profileId);
|
|
23
24
|
const limit = params.limit ?? 20;
|
|
24
25
|
const [breakdownReport, totalReport] = await Promise.all([
|
|
25
26
|
runReport(propertyId, {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/tools/analytics/source-medium-breakdown.ts"],
|
|
4
|
-
"sourcesContent": ["import { error, object } from \"mcp-use/server\";\nimport { z } from \"zod\";\n\nimport {\n extractQuotaSnapshot,\n getDimensionValue,\n getMetricValueByName,\n resolveGa4PropertyId,\n round,\n toPercent,\n} from \"../../analytics/ga4-report-utils.js\";\nimport { runReport } from \"../../services/analytics/ga4-client.js\";\nimport { stripNulls } from \"../../utils/strip-payload.js\";\n\nconst dateRegex = /^\\d{4}-\\d{2}-\\d{2}$/;\n\nexport const sourceMediumBreakdownSchema = z.object({\n startDate: z.string().regex(dateRegex).describe(\"Start date in YYYY-MM-DD format\"),\n endDate: z.string().regex(dateRegex).describe(\"End date in YYYY-MM-DD format\"),\n propertyId: z.string().optional().describe(\"GA4 property ID. If omitted,
|
|
5
|
-
"mappings": "AAAA,SAAS,OAAO,cAAc;AAC9B,SAAS,SAAS;AAElB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB;AAE3B,MAAM,YAAY;AAEX,MAAM,8BAA8B,EAAE,OAAO;AAAA,EAClD,WAAW,EAAE,OAAO,EAAE,MAAM,SAAS,EAAE,SAAS,iCAAiC;AAAA,EACjF,SAAS,EAAE,OAAO,EAAE,MAAM,SAAS,EAAE,SAAS,+BAA+B;AAAA,EAC7E,YAAY,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,
|
|
4
|
+
"sourcesContent": ["import { error, object } from \"mcp-use/server\";\nimport { z } from \"zod\";\n\nimport {\n extractQuotaSnapshot,\n getDimensionValue,\n getMetricValueByName,\n resolveGa4PropertyId,\n round,\n toPercent,\n} from \"../../analytics/ga4-report-utils.js\";\nimport { runReport } from \"../../services/analytics/ga4-client.js\";\nimport { stripNulls } from \"../../utils/strip-payload.js\";\n\nconst dateRegex = /^\\d{4}-\\d{2}-\\d{2}$/;\n\nexport const sourceMediumBreakdownSchema = z.object({\n startDate: z.string().regex(dateRegex).describe(\"Start date in YYYY-MM-DD format\"),\n endDate: z.string().regex(dateRegex).describe(\"End date in YYYY-MM-DD format\"),\n propertyId: z.string().optional().describe(\"GA4 property ID. If omitted, resolves profileId mapping first and then GA4_PROPERTY_ID.\"),\n profileId: z.string().optional().describe(\"Optional business profile ID used to resolve the mapped GA4 property.\"),\n limit: z.number().int().min(1).max(100).optional().describe(\"Maximum rows to return\"),\n});\n\nexport async function sourceMediumBreakdownHandler(\n params: z.infer<typeof sourceMediumBreakdownSchema>\n) {\n try {\n const propertyId = await resolveGa4PropertyId(params.propertyId, params.profileId);\n const limit = params.limit ?? 20;\n\n const [breakdownReport, totalReport] = await Promise.all([\n runReport(propertyId, {\n dateRanges: [{ startDate: params.startDate, endDate: params.endDate }],\n dimensions: [{ name: \"sessionSourceMedium\" }],\n metrics: [{ name: \"sessions\" }, { name: \"totalUsers\" }],\n orderBys: [{ metric: { metricName: \"sessions\" }, desc: true }],\n limit,\n returnPropertyQuota: true,\n }),\n runReport(propertyId, {\n dateRanges: [{ startDate: params.startDate, endDate: params.endDate }],\n metrics: [{ name: \"sessions\" }, { name: \"totalUsers\" }],\n }),\n ]);\n\n const totalSessions = getMetricValueByName(\n totalReport.rows?.[0] ?? {},\n totalReport.metricHeaders,\n \"sessions\"\n );\n const totalUsers = getMetricValueByName(\n totalReport.rows?.[0] ?? {},\n totalReport.metricHeaders,\n \"totalUsers\"\n );\n\n const rows = (breakdownReport.rows ?? []).map((row) => {\n const sessions = getMetricValueByName(row, breakdownReport.metricHeaders, \"sessions\");\n const users = getMetricValueByName(row, breakdownReport.metricHeaders, \"totalUsers\");\n\n return {\n source_medium: getDimensionValue(row),\n sessions,\n users,\n session_share_percent: round(toPercent(sessions, totalSessions)),\n user_share_percent: round(toPercent(users, totalUsers)),\n };\n });\n\n return object(\n stripNulls({\n property_id: propertyId,\n date_range: {\n start_date: params.startDate,\n end_date: params.endDate,\n },\n overview: {\n total_sessions: totalSessions,\n total_users: totalUsers,\n returned_rows: rows.length,\n available_rows: breakdownReport.rowCount,\n },\n source_mediums: rows,\n quota: extractQuotaSnapshot(breakdownReport),\n })\n );\n } catch (err) {\n return error(\n err instanceof Error ? err.message : \"Failed to fetch GA4 source / medium breakdown\"\n );\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,OAAO,cAAc;AAC9B,SAAS,SAAS;AAElB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB;AAE3B,MAAM,YAAY;AAEX,MAAM,8BAA8B,EAAE,OAAO;AAAA,EAClD,WAAW,EAAE,OAAO,EAAE,MAAM,SAAS,EAAE,SAAS,iCAAiC;AAAA,EACjF,SAAS,EAAE,OAAO,EAAE,MAAM,SAAS,EAAE,SAAS,+BAA+B;AAAA,EAC7E,YAAY,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,yFAAyF;AAAA,EACpI,WAAW,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,uEAAuE;AAAA,EACjH,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,IAAI,GAAG,EAAE,SAAS,EAAE,SAAS,wBAAwB;AACtF,CAAC;AAED,eAAsB,6BACpB,QACA;AACA,MAAI;AACF,UAAM,aAAa,MAAM,qBAAqB,OAAO,YAAY,OAAO,SAAS;AACjF,UAAM,QAAQ,OAAO,SAAS;AAE9B,UAAM,CAAC,iBAAiB,WAAW,IAAI,MAAM,QAAQ,IAAI;AAAA,MACvD,UAAU,YAAY;AAAA,QACpB,YAAY,CAAC,EAAE,WAAW,OAAO,WAAW,SAAS,OAAO,QAAQ,CAAC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AAA,UACpB,gBAAgB,gBAAgB;AAAA,QAClC;AAAA,QACA,gBAAgB;AAAA,QAChB,OAAO,qBAAqB,eAAe;AAAA,MAC7C,CAAC;AAAA,IACH;AAAA,EACF,SAAS,KAAK;AACZ,WAAO;AAAA,MACL,eAAe,QAAQ,IAAI,UAAU;AAAA,IACvC;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -14,12 +14,13 @@ const dateRegex = /^\d{4}-\d{2}-\d{2}$/;
|
|
|
14
14
|
const topLandingPagesSchema = z.object({
|
|
15
15
|
startDate: z.string().regex(dateRegex).describe("Start date in YYYY-MM-DD format"),
|
|
16
16
|
endDate: z.string().regex(dateRegex).describe("End date in YYYY-MM-DD format"),
|
|
17
|
-
propertyId: z.string().optional().describe("GA4 property ID. If omitted,
|
|
17
|
+
propertyId: z.string().optional().describe("GA4 property ID. If omitted, resolves profileId mapping first and then GA4_PROPERTY_ID."),
|
|
18
|
+
profileId: z.string().optional().describe("Optional business profile ID used to resolve the mapped GA4 property."),
|
|
18
19
|
limit: z.number().int().min(1).max(100).optional().describe("Maximum rows to return")
|
|
19
20
|
});
|
|
20
21
|
async function topLandingPagesHandler(params) {
|
|
21
22
|
try {
|
|
22
|
-
const propertyId = resolveGa4PropertyId(params.propertyId);
|
|
23
|
+
const propertyId = await resolveGa4PropertyId(params.propertyId, params.profileId);
|
|
23
24
|
const limit = params.limit ?? 20;
|
|
24
25
|
const [landingReport, totalReport] = await Promise.all([
|
|
25
26
|
runReport(propertyId, {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/tools/analytics/top-landing-pages.ts"],
|
|
4
|
-
"sourcesContent": ["import { error, object } from \"mcp-use/server\";\nimport { z } from \"zod\";\n\nimport {\n extractQuotaSnapshot,\n getDimensionValue,\n getMetricValueByName,\n resolveGa4PropertyId,\n round,\n toPercent,\n} from \"../../analytics/ga4-report-utils.js\";\nimport { runReport } from \"../../services/analytics/ga4-client.js\";\nimport { stripNulls } from \"../../utils/strip-payload.js\";\n\nconst dateRegex = /^\\d{4}-\\d{2}-\\d{2}$/;\n\nexport const topLandingPagesSchema = z.object({\n startDate: z.string().regex(dateRegex).describe(\"Start date in YYYY-MM-DD format\"),\n endDate: z.string().regex(dateRegex).describe(\"End date in YYYY-MM-DD format\"),\n propertyId: z.string().optional().describe(\"GA4 property ID. If omitted,
|
|
5
|
-
"mappings": "AAAA,SAAS,OAAO,cAAc;AAC9B,SAAS,SAAS;AAElB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB;AAE3B,MAAM,YAAY;AAEX,MAAM,wBAAwB,EAAE,OAAO;AAAA,EAC5C,WAAW,EAAE,OAAO,EAAE,MAAM,SAAS,EAAE,SAAS,iCAAiC;AAAA,EACjF,SAAS,EAAE,OAAO,EAAE,MAAM,SAAS,EAAE,SAAS,+BAA+B;AAAA,EAC7E,YAAY,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,
|
|
4
|
+
"sourcesContent": ["import { error, object } from \"mcp-use/server\";\nimport { z } from \"zod\";\n\nimport {\n extractQuotaSnapshot,\n getDimensionValue,\n getMetricValueByName,\n resolveGa4PropertyId,\n round,\n toPercent,\n} from \"../../analytics/ga4-report-utils.js\";\nimport { runReport } from \"../../services/analytics/ga4-client.js\";\nimport { stripNulls } from \"../../utils/strip-payload.js\";\n\nconst dateRegex = /^\\d{4}-\\d{2}-\\d{2}$/;\n\nexport const topLandingPagesSchema = z.object({\n startDate: z.string().regex(dateRegex).describe(\"Start date in YYYY-MM-DD format\"),\n endDate: z.string().regex(dateRegex).describe(\"End date in YYYY-MM-DD format\"),\n propertyId: z.string().optional().describe(\"GA4 property ID. If omitted, resolves profileId mapping first and then GA4_PROPERTY_ID.\"),\n profileId: z.string().optional().describe(\"Optional business profile ID used to resolve the mapped GA4 property.\"),\n limit: z.number().int().min(1).max(100).optional().describe(\"Maximum rows to return\"),\n});\n\nexport async function topLandingPagesHandler(params: z.infer<typeof topLandingPagesSchema>) {\n try {\n const propertyId = await resolveGa4PropertyId(params.propertyId, params.profileId);\n const limit = params.limit ?? 20;\n\n const [landingReport, totalReport] = await Promise.all([\n runReport(propertyId, {\n dateRanges: [{ startDate: params.startDate, endDate: params.endDate }],\n dimensions: [{ name: \"landingPage\" }],\n metrics: [{ name: \"sessions\" }, { name: \"totalUsers\" }],\n orderBys: [{ metric: { metricName: \"sessions\" }, desc: true }],\n limit,\n returnPropertyQuota: true,\n }),\n runReport(propertyId, {\n dateRanges: [{ startDate: params.startDate, endDate: params.endDate }],\n metrics: [{ name: \"sessions\" }, { name: \"totalUsers\" }],\n }),\n ]);\n\n const totalSessions = getMetricValueByName(\n totalReport.rows?.[0] ?? {},\n totalReport.metricHeaders,\n \"sessions\"\n );\n\n const landingPages = (landingReport.rows ?? []).map((row) => {\n const sessions = getMetricValueByName(row, landingReport.metricHeaders, \"sessions\");\n const users = getMetricValueByName(row, landingReport.metricHeaders, \"totalUsers\");\n\n return {\n landing_page: getDimensionValue(row),\n sessions,\n users,\n session_share_percent: round(toPercent(sessions, totalSessions)),\n is_not_set: getDimensionValue(row) === \"(not set)\",\n };\n });\n\n return object(\n stripNulls({\n property_id: propertyId,\n date_range: {\n start_date: params.startDate,\n end_date: params.endDate,\n },\n overview: {\n total_sessions: totalSessions,\n returned_rows: landingPages.length,\n available_rows: landingReport.rowCount,\n top_landing_page: landingPages[0]?.landing_page,\n },\n landing_pages: landingPages,\n quota: extractQuotaSnapshot(landingReport),\n })\n );\n } catch (err) {\n return error(err instanceof Error ? err.message : \"Failed to fetch GA4 top landing pages\");\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,OAAO,cAAc;AAC9B,SAAS,SAAS;AAElB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAA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;AAED,UAAM,gBAAgB;AAAA,MACpB,YAAY,OAAO,CAAC,KAAK,CAAC;AAAA,MAC1B,YAAY;AAAA,MACZ;AAAA,IACF;AAEA,UAAM,gBAAgB,cAAc,QAAQ,CAAC,GAAG,IAAI,CAAC,QAAQ;AAC3D,YAAM,WAAW,qBAAqB,KAAK,cAAc,eAAe,UAAU;AAClF,YAAM,QAAQ,qBAAqB,KAAK,cAAc,eAAe,YAAY;AAEjF,aAAO;AAAA,QACL,cAAc,kBAAkB,GAAG;AAAA,QACnC;AAAA,QACA;AAAA,QACA,uBAAuB,MAAM,UAAU,UAAU,aAAa,CAAC;AAAA,QAC/D,YAAY,kBAAkB,GAAG,MAAM;AAAA,MACzC;AAAA,IACF,CAAC;AAED,WAAO;AAAA,MACL,WAAW;AAAA,QACT,aAAa;AAAA,QACb,YAAY;AAAA,UACV,YAAY,OAAO;AAAA,UACnB,UAAU,OAAO;AAAA,QACnB;AAAA,QACA,UAAU;AAAA,UACR,gBAAgB;AAAA,UAChB,eAAe,aAAa;AAAA,UAC5B,gBAAgB,cAAc;AAAA,UAC9B,kBAAkB,aAAa,CAAC,GAAG;AAAA,QACrC;AAAA,QACA,eAAe;AAAA,QACf,OAAO,qBAAqB,aAAa;AAAA,MAC3C,CAAC;AAAA,IACH;AAAA,EACF,SAAS,KAAK;AACZ,WAAO,MAAM,eAAe,QAAQ,IAAI,UAAU,uCAAuC;AAAA,EAC3F;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,19 +1,34 @@
|
|
|
1
1
|
import { error, object } from "mcp-use/server";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
+
import { listProfileGoogleServiceMappings } from "../../config/google-store.js";
|
|
3
4
|
import { listProfiles } from "../../config/profile-store.js";
|
|
4
5
|
const listProfilesSchema = z.object({});
|
|
5
6
|
async function listProfilesHandler() {
|
|
6
7
|
try {
|
|
7
|
-
const profiles = await listProfiles({ activeOnly: true });
|
|
8
|
+
const [profiles, mappings] = await Promise.all([listProfiles({ activeOnly: true }), listProfileGoogleServiceMappings()]);
|
|
9
|
+
const mappingsByProfileId = new Map(mappings.map((mapping) => [mapping.profileId, mapping]));
|
|
8
10
|
return object({
|
|
9
11
|
total_profiles: profiles.length,
|
|
10
|
-
profiles: profiles.map((profile) =>
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
profiles: profiles.map((profile) => {
|
|
13
|
+
const mapping = mappingsByProfileId.get(profile.id);
|
|
14
|
+
return {
|
|
15
|
+
profile_id: profile.id,
|
|
16
|
+
name: profile.name,
|
|
17
|
+
is_active: profile.isActive,
|
|
18
|
+
created_at: profile.createdAt.toISOString(),
|
|
19
|
+
updated_at: profile.updatedAt.toISOString(),
|
|
20
|
+
google_services: {
|
|
21
|
+
has_google_ads: Boolean(mapping?.googleAdsCustomerId),
|
|
22
|
+
has_ga4: Boolean(mapping?.ga4PropertyId),
|
|
23
|
+
has_search_console: Boolean(mapping?.searchConsoleSiteUrl),
|
|
24
|
+
statuses: {
|
|
25
|
+
google_ads: mapping?.googleAdsCustomerId ? mapping.googleAdsStatus : "not_configured",
|
|
26
|
+
ga4: mapping?.ga4PropertyId ? mapping.ga4Status : "not_configured",
|
|
27
|
+
search_console: mapping?.searchConsoleSiteUrl ? mapping.searchConsoleStatus : "not_configured"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
})
|
|
17
32
|
});
|
|
18
33
|
} catch (err) {
|
|
19
34
|
return error(err instanceof Error ? err.message : "Failed to list profiles");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/tools/config/list-profiles.ts"],
|
|
4
|
-
"sourcesContent": ["import { error, object } from
|
|
5
|
-
"mappings": "AAAA,SAAS,OAAO,cAAc;AAC9B,SAAS,SAAS;
|
|
4
|
+
"sourcesContent": ["import { error, object } from 'mcp-use/server';\nimport { z } from 'zod';\nimport { listProfileGoogleServiceMappings } from '../../config/google-store.js';\nimport { listProfiles } from '../../config/profile-store.js';\n\nexport const listProfilesSchema = z.object({});\n\nexport async function listProfilesHandler() {\n try {\n const [profiles, mappings] = await Promise.all([listProfiles({ activeOnly: true }), listProfileGoogleServiceMappings()]);\n const mappingsByProfileId = new Map(mappings.map((mapping) => [mapping.profileId, mapping]));\n return object({\n total_profiles: profiles.length,\n profiles: profiles.map((profile) => {\n const mapping = mappingsByProfileId.get(profile.id);\n return {\n profile_id: profile.id,\n name: profile.name,\n is_active: profile.isActive,\n created_at: profile.createdAt.toISOString(),\n updated_at: profile.updatedAt.toISOString(),\n google_services: {\n has_google_ads: Boolean(mapping?.googleAdsCustomerId),\n has_ga4: Boolean(mapping?.ga4PropertyId),\n has_search_console: Boolean(mapping?.searchConsoleSiteUrl),\n statuses: {\n google_ads: mapping?.googleAdsCustomerId ? mapping.googleAdsStatus : 'not_configured',\n ga4: mapping?.ga4PropertyId ? mapping.ga4Status : 'not_configured',\n search_console: mapping?.searchConsoleSiteUrl ? mapping.searchConsoleStatus : 'not_configured',\n },\n },\n };\n }),\n });\n } catch (err) {\n return error(err instanceof Error ? err.message : 'Failed to list profiles');\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,OAAO,cAAc;AAC9B,SAAS,SAAS;AAClB,SAAS,wCAAwC;AACjD,SAAS,oBAAoB;AAEtB,MAAM,qBAAqB,EAAE,OAAO,CAAC,CAAC;AAE7C,eAAsB,sBAAsB;AAC1C,MAAI;AACF,UAAM,CAAC,UAAU,QAAQ,IAAI,MAAM,QAAQ,IAAI,CAAC,aAAa,EAAE,YAAY,KAAK,CAAC,GAAG,iCAAiC,CAAC,CAAC;AACvH,UAAM,sBAAsB,IAAI,IAAI,SAAS,IAAI,CAAC,YAAY,CAAC,QAAQ,WAAW,OAAO,CAAC,CAAC;AAC3F,WAAO,OAAO;AAAA,MACZ,gBAAgB,SAAS;AAAA,MACzB,UAAU,SAAS,IAAI,CAAC,YAAY;AAClC,cAAM,UAAU,oBAAoB,IAAI,QAAQ,EAAE;AAClD,eAAO;AAAA,UACL,YAAY,QAAQ;AAAA,UACpB,MAAM,QAAQ;AAAA,UACd,WAAW,QAAQ;AAAA,UACnB,YAAY,QAAQ,UAAU,YAAY;AAAA,UAC1C,YAAY,QAAQ,UAAU,YAAY;AAAA,UAC1C,iBAAiB;AAAA,YACf,gBAAgB,QAAQ,SAAS,mBAAmB;AAAA,YACpD,SAAS,QAAQ,SAAS,aAAa;AAAA,YACvC,oBAAoB,QAAQ,SAAS,oBAAoB;AAAA,YACzD,UAAU;AAAA,cACR,YAAY,SAAS,sBAAsB,QAAQ,kBAAkB;AAAA,cACrE,KAAK,SAAS,gBAAgB,QAAQ,YAAY;AAAA,cAClD,gBAAgB,SAAS,uBAAuB,QAAQ,sBAAsB;AAAA,YAChF;AAAA,UACF;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH,CAAC;AAAA,EACH,SAAS,KAAK;AACZ,WAAO,MAAM,eAAe,QAAQ,IAAI,UAAU,yBAAyB;AAAA,EAC7E;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -16,14 +16,15 @@ import { stripNulls } from "../../utils/strip-payload.js";
|
|
|
16
16
|
const googleAdsAccountOverviewSchema = z.object({
|
|
17
17
|
startDate: z.string().regex(dateRegex).describe("Start date in YYYY-MM-DD format."),
|
|
18
18
|
endDate: z.string().regex(dateRegex).describe("End date in YYYY-MM-DD format."),
|
|
19
|
-
customerId: z.string().describe("Google Ads customer ID to query. Accepts digits with or without hyphens."),
|
|
19
|
+
customerId: z.string().optional().describe("Google Ads customer ID to query. If omitted, resolves the profileId mapping. Accepts digits with or without hyphens."),
|
|
20
|
+
profileId: z.string().optional().describe("Optional business profile ID used to resolve the mapped Google Ads customer ID."),
|
|
20
21
|
loginCustomerId: z.string().optional().describe(
|
|
21
22
|
"Optional manager account ID used as login customer. If omitted, uses GOOGLE_ADS_LOGIN_CUSTOMER_ID when configured."
|
|
22
23
|
)
|
|
23
24
|
});
|
|
24
25
|
async function googleAdsAccountOverviewHandler(params) {
|
|
25
26
|
try {
|
|
26
|
-
const customerId = resolveGoogleAdsCustomerId(params.customerId);
|
|
27
|
+
const customerId = await resolveGoogleAdsCustomerId(params.customerId, params.profileId);
|
|
27
28
|
const loginCustomerId = resolveGoogleAdsLoginCustomerId(params.loginCustomerId);
|
|
28
29
|
const developerToken = resolveGoogleAdsDeveloperToken();
|
|
29
30
|
const result = await searchGoogleAds(
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/tools/google-ads/account-overview.ts"],
|
|
4
|
-
"sourcesContent": ["import { error, object } from \"mcp-use/server\";\nimport { z } from \"zod\";\n\nimport {\n dateRegex,\n getFieldValue,\n microsToCurrency,\n parseGoogleAdsMetricValue,\n resolveGoogleAdsCustomerId,\n resolveGoogleAdsDeveloperToken,\n resolveGoogleAdsLoginCustomerId,\n round,\n toPercent,\n} from \"../../utils/google-ads.js\";\nimport { searchGoogleAds } from \"../../services/google-ads/google-ads-client.js\";\nimport { stripNulls } from \"../../utils/strip-payload.js\";\n\nexport const googleAdsAccountOverviewSchema = z.object({\n startDate: z.string().regex(dateRegex).describe(\"Start date in YYYY-MM-DD format.\"),\n endDate: z.string().regex(dateRegex).describe(\"End date in YYYY-MM-DD format.\"),\n customerId: z.string().describe(\"Google Ads customer ID to query. Accepts digits with or without hyphens.\"),\n loginCustomerId: z\n .string()\n .optional()\n .describe(\n \"Optional manager account ID used as login customer. If omitted, uses GOOGLE_ADS_LOGIN_CUSTOMER_ID when configured.\"\n ),\n});\n\nexport async function googleAdsAccountOverviewHandler(\n params: z.infer<typeof googleAdsAccountOverviewSchema>\n) {\n try {\n const customerId = resolveGoogleAdsCustomerId(params.customerId);\n const loginCustomerId = resolveGoogleAdsLoginCustomerId(params.loginCustomerId);\n const developerToken = resolveGoogleAdsDeveloperToken();\n\n const result = await searchGoogleAds(\n customerId,\n [\n \"SELECT\",\n \"customer.id,\",\n \"customer.descriptive_name,\",\n \"customer.currency_code,\",\n \"customer.time_zone,\",\n \"metrics.impressions,\",\n \"metrics.clicks,\",\n \"metrics.cost_micros,\",\n \"metrics.conversions,\",\n \"metrics.conversions_value,\",\n \"metrics.ctr,\",\n \"metrics.average_cpc\",\n \"FROM customer\",\n `WHERE segments.date BETWEEN '${params.startDate}' AND '${params.endDate}'`,\n ].join(\" \"),\n developerToken,\n loginCustomerId\n );\n\n const row = result.rows[0] ?? {};\n const impressions = parseGoogleAdsMetricValue(getFieldValue(row, \"metrics.impressions\"));\n const clicks = parseGoogleAdsMetricValue(getFieldValue(row, \"metrics.clicks\"));\n const cost = microsToCurrency(getFieldValue(row, \"metrics.costMicros\"));\n const conversions = round(\n parseGoogleAdsMetricValue(getFieldValue(row, \"metrics.conversions\"))\n );\n const conversionValue = round(\n parseGoogleAdsMetricValue(getFieldValue(row, \"metrics.conversionsValue\"))\n );\n const ctrPercent = round(\n parseGoogleAdsMetricValue(getFieldValue(row, \"metrics.ctr\")) * 100\n );\n const averageCpc = microsToCurrency(getFieldValue(row, \"metrics.averageCpc\"));\n\n return object(\n stripNulls({\n customer_id: customerId,\n login_customer_id: loginCustomerId,\n date_range: {\n start_date: params.startDate,\n end_date: params.endDate,\n },\n currency_code: getFieldValue(row, \"customer.currencyCode\"),\n customer_name: getFieldValue(row, \"customer.descriptiveName\"),\n time_zone: getFieldValue(row, \"customer.timeZone\"),\n overview: {\n impressions,\n clicks,\n cost,\n conversions,\n conversion_value: conversionValue,\n ctr_percent: ctrPercent,\n average_cpc: averageCpc,\n cpa: round(cost / conversions),\n roas: round(conversionValue / cost),\n conversion_rate_percent: round(toPercent(conversions, clicks)),\n },\n metadata: {\n row_count: result.rows.length,\n request_id: result.requestId,\n },\n })\n );\n } catch (err) {\n return error(\n err instanceof Error ? err.message : \"Failed to fetch Google Ads account overview\"\n );\n }\n}\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,OAAO,cAAc;AAC9B,SAAS,SAAS;AAElB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,uBAAuB;AAChC,SAAS,kBAAkB;AAEpB,MAAM,iCAAiC,EAAE,OAAO;AAAA,EACrD,WAAW,EAAE,OAAO,EAAE,MAAM,SAAS,EAAE,SAAS,kCAAkC;AAAA,EAClF,SAAS,EAAE,OAAO,EAAE,MAAM,SAAS,EAAE,SAAS,gCAAgC;AAAA,EAC9E,YAAY,EAAE,OAAO,EAAE,SAAS,
|
|
4
|
+
"sourcesContent": ["import { error, object } from \"mcp-use/server\";\nimport { z } from \"zod\";\n\nimport {\n dateRegex,\n getFieldValue,\n microsToCurrency,\n parseGoogleAdsMetricValue,\n resolveGoogleAdsCustomerId,\n resolveGoogleAdsDeveloperToken,\n resolveGoogleAdsLoginCustomerId,\n round,\n toPercent,\n} from \"../../utils/google-ads.js\";\nimport { searchGoogleAds } from \"../../services/google-ads/google-ads-client.js\";\nimport { stripNulls } from \"../../utils/strip-payload.js\";\n\nexport const googleAdsAccountOverviewSchema = z.object({\n startDate: z.string().regex(dateRegex).describe(\"Start date in YYYY-MM-DD format.\"),\n endDate: z.string().regex(dateRegex).describe(\"End date in YYYY-MM-DD format.\"),\n customerId: z.string().optional().describe(\"Google Ads customer ID to query. If omitted, resolves the profileId mapping. Accepts digits with or without hyphens.\"),\n profileId: z.string().optional().describe(\"Optional business profile ID used to resolve the mapped Google Ads customer ID.\"),\n loginCustomerId: z\n .string()\n .optional()\n .describe(\n \"Optional manager account ID used as login customer. If omitted, uses GOOGLE_ADS_LOGIN_CUSTOMER_ID when configured.\"\n ),\n});\n\nexport async function googleAdsAccountOverviewHandler(\n params: z.infer<typeof googleAdsAccountOverviewSchema>\n) {\n try {\n const customerId = await resolveGoogleAdsCustomerId(params.customerId, params.profileId);\n const loginCustomerId = resolveGoogleAdsLoginCustomerId(params.loginCustomerId);\n const developerToken = resolveGoogleAdsDeveloperToken();\n\n const result = await searchGoogleAds(\n customerId,\n [\n \"SELECT\",\n \"customer.id,\",\n \"customer.descriptive_name,\",\n \"customer.currency_code,\",\n \"customer.time_zone,\",\n \"metrics.impressions,\",\n \"metrics.clicks,\",\n \"metrics.cost_micros,\",\n \"metrics.conversions,\",\n \"metrics.conversions_value,\",\n \"metrics.ctr,\",\n \"metrics.average_cpc\",\n \"FROM customer\",\n `WHERE segments.date BETWEEN '${params.startDate}' AND '${params.endDate}'`,\n ].join(\" \"),\n developerToken,\n loginCustomerId\n );\n\n const row = result.rows[0] ?? {};\n const impressions = parseGoogleAdsMetricValue(getFieldValue(row, \"metrics.impressions\"));\n const clicks = parseGoogleAdsMetricValue(getFieldValue(row, \"metrics.clicks\"));\n const cost = microsToCurrency(getFieldValue(row, \"metrics.costMicros\"));\n const conversions = round(\n parseGoogleAdsMetricValue(getFieldValue(row, \"metrics.conversions\"))\n );\n const conversionValue = round(\n parseGoogleAdsMetricValue(getFieldValue(row, \"metrics.conversionsValue\"))\n );\n const ctrPercent = round(\n parseGoogleAdsMetricValue(getFieldValue(row, \"metrics.ctr\")) * 100\n );\n const averageCpc = microsToCurrency(getFieldValue(row, \"metrics.averageCpc\"));\n\n return object(\n stripNulls({\n customer_id: customerId,\n login_customer_id: loginCustomerId,\n date_range: {\n start_date: params.startDate,\n end_date: params.endDate,\n },\n currency_code: getFieldValue(row, \"customer.currencyCode\"),\n customer_name: getFieldValue(row, \"customer.descriptiveName\"),\n time_zone: getFieldValue(row, \"customer.timeZone\"),\n overview: {\n impressions,\n clicks,\n cost,\n conversions,\n conversion_value: conversionValue,\n ctr_percent: ctrPercent,\n average_cpc: averageCpc,\n cpa: round(cost / conversions),\n roas: round(conversionValue / cost),\n conversion_rate_percent: round(toPercent(conversions, clicks)),\n },\n metadata: {\n row_count: result.rows.length,\n request_id: result.requestId,\n },\n })\n );\n } catch (err) {\n return error(\n err instanceof Error ? err.message : \"Failed to fetch Google Ads account overview\"\n );\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,OAAO,cAAc;AAC9B,SAAS,SAAS;AAElB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,uBAAuB;AAChC,SAAS,kBAAkB;AAEpB,MAAM,iCAAiC,EAAE,OAAO;AAAA,EACrD,WAAW,EAAE,OAAO,EAAE,MAAM,SAAS,EAAE,SAAS,kCAAkC;AAAA,EAClF,SAAS,EAAE,OAAO,EAAE,MAAM,SAAS,EAAE,SAAS,gCAAgC;AAAA,EAC9E,YAAY,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,sHAAsH;AAAA,EACjK,WAAW,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,iFAAiF;AAAA,EAC3H,iBAAiB,EACd,OAAO,EACP,SAAS,EACT;AAAA,IACC;AAAA,EACF;AACJ,CAAC;AAED,eAAsB,gCACpB,QACA;AACA,MAAI;AACF,UAAM,aAAa,MAAM,2BAA2B,OAAO,YAAY,OAAO,SAAS;AACvF,UAAM,kBAAkB,gCAAgC,OAAO,eAAe;AAC9E,UAAM,iBAAiB,+BAA+B;AAEtD,UAAM,SAAS,MAAM;AAAA,MACnB;AAAA,MACA;AAAA,QACE;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,gCAAgC,OAAO,SAAS,UAAU,OAAO,OAAO;AAAA,MAC1E,EAAE,KAAK,GAAG;AAAA,MACV;AAAA,MACA;AAAA,IACF;AAEA,UAAM,MAAM,OAAO,KAAK,CAAC,KAAK,CAAC;AAC/B,UAAM,cAAc,0BAA0B,cAAc,KAAK,qBAAqB,CAAC;AACvF,UAAM,SAAS,0BAA0B,cAAc,KAAK,gBAAgB,CAAC;AAC7E,UAAM,OAAO,iBAAiB,cAAc,KAAK,oBAAoB,CAAC;AACtE,UAAM,cAAc;AAAA,MAClB,0BAA0B,cAAc,KAAK,qBAAqB,CAAC;AAAA,IACrE;AACA,UAAM,kBAAkB;AAAA,MACtB,0BAA0B,cAAc,KAAK,0BAA0B,CAAC;AAAA,IAC1E;AACA,UAAM,aAAa;AAAA,MACjB,0BAA0B,cAAc,KAAK,aAAa,CAAC,IAAI;AAAA,IACjE;AACA,UAAM,aAAa,iBAAiB,cAAc,KAAK,oBAAoB,CAAC;AAE5E,WAAO;AAAA,MACL,WAAW;AAAA,QACT,aAAa;AAAA,QACb,mBAAmB;AAAA,QACnB,YAAY;AAAA,UACV,YAAY,OAAO;AAAA,UACnB,UAAU,OAAO;AAAA,QACnB;AAAA,QACA,eAAe,cAAc,KAAK,uBAAuB;AAAA,QACzD,eAAe,cAAc,KAAK,0BAA0B;AAAA,QAC5D,WAAW,cAAc,KAAK,mBAAmB;AAAA,QACjD,UAAU;AAAA,UACR;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA,kBAAkB;AAAA,UAClB,aAAa;AAAA,UACb,aAAa;AAAA,UACb,KAAK,MAAM,OAAO,WAAW;AAAA,UAC7B,MAAM,MAAM,kBAAkB,IAAI;AAAA,UAClC,yBAAyB,MAAM,UAAU,aAAa,MAAM,CAAC;AAAA,QAC/D;AAAA,QACA,UAAU;AAAA,UACR,WAAW,OAAO,KAAK;AAAA,UACvB,YAAY,OAAO;AAAA,QACrB;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF,SAAS,KAAK;AACZ,WAAO;AAAA,MACL,eAAe,QAAQ,IAAI,UAAU;AAAA,IACvC;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -25,14 +25,15 @@ function buildRisk(code, severity, title, detail, metricValue) {
|
|
|
25
25
|
const googleAdsAccountRisksSchema = z.object({
|
|
26
26
|
startDate: z.string().regex(dateRegex).describe("Start date in YYYY-MM-DD format."),
|
|
27
27
|
endDate: z.string().regex(dateRegex).describe("End date in YYYY-MM-DD format."),
|
|
28
|
-
customerId: z.string().describe("Google Ads customer ID to query. Accepts digits with or without hyphens."),
|
|
28
|
+
customerId: z.string().optional().describe("Google Ads customer ID to query. If omitted, resolves the profileId mapping. Accepts digits with or without hyphens."),
|
|
29
|
+
profileId: z.string().optional().describe("Optional business profile ID used to resolve the mapped Google Ads customer ID."),
|
|
29
30
|
loginCustomerId: z.string().optional().describe(
|
|
30
31
|
"Optional manager account ID used as login customer. If omitted, uses GOOGLE_ADS_LOGIN_CUSTOMER_ID when configured."
|
|
31
32
|
)
|
|
32
33
|
});
|
|
33
34
|
async function googleAdsAccountRisksHandler(params) {
|
|
34
35
|
try {
|
|
35
|
-
const customerId = resolveGoogleAdsCustomerId(params.customerId);
|
|
36
|
+
const customerId = await resolveGoogleAdsCustomerId(params.customerId, params.profileId);
|
|
36
37
|
const loginCustomerId = resolveGoogleAdsLoginCustomerId(params.loginCustomerId);
|
|
37
38
|
const developerToken = resolveGoogleAdsDeveloperToken();
|
|
38
39
|
const [campaignsResult, channelsResult, seriesResult] = await Promise.all([
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/tools/google-ads/account-risks.ts"],
|
|
4
|
-
"sourcesContent": ["import { error, object } from \"mcp-use/server\";\nimport { z } from \"zod\";\n\nimport {\n dateRegex,\n getFieldValue,\n microsToCurrency,\n parseGoogleAdsMetricValue,\n resolveGoogleAdsCustomerId,\n resolveGoogleAdsDeveloperToken,\n resolveGoogleAdsLoginCustomerId,\n round,\n toPercent,\n} from \"../../utils/google-ads.js\";\nimport { searchGoogleAds } from \"../../services/google-ads/google-ads-client.js\";\nimport { stripNulls } from \"../../utils/strip-payload.js\";\n\ntype RiskSeverity = \"low\" | \"medium\" | \"high\";\n\nfunction buildRisk(\n code: string,\n severity: RiskSeverity,\n title: string,\n detail: string,\n metricValue?: number\n) {\n return stripNulls({\n code,\n severity,\n title,\n detail,\n metric_value: metricValue !== undefined ? round(metricValue) : undefined,\n });\n}\n\nexport const googleAdsAccountRisksSchema = z.object({\n startDate: z.string().regex(dateRegex).describe(\"Start date in YYYY-MM-DD format.\"),\n endDate: z.string().regex(dateRegex).describe(\"End date in YYYY-MM-DD format.\"),\n customerId: z\n .string()\n .describe(\"Google Ads customer ID to query. Accepts digits with or without hyphens.\"),\n loginCustomerId: z\n .string()\n .optional()\n .describe(\n \"Optional manager account ID used as login customer. If omitted, uses GOOGLE_ADS_LOGIN_CUSTOMER_ID when configured.\"\n ),\n});\n\nexport async function googleAdsAccountRisksHandler(\n params: z.infer<typeof googleAdsAccountRisksSchema>\n) {\n try {\n const customerId = resolveGoogleAdsCustomerId(params.customerId);\n const loginCustomerId = resolveGoogleAdsLoginCustomerId(params.loginCustomerId);\n const developerToken = resolveGoogleAdsDeveloperToken();\n\n const [campaignsResult, channelsResult, seriesResult] = await Promise.all([\n searchGoogleAds(\n customerId,\n [\n \"SELECT\",\n \"customer.descriptive_name,\",\n \"customer.currency_code,\",\n \"campaign.id,\",\n \"campaign.name,\",\n \"campaign.advertising_channel_type,\",\n \"metrics.impressions,\",\n \"metrics.clicks,\",\n \"metrics.cost_micros,\",\n \"metrics.conversions,\",\n \"metrics.conversions_value\",\n \"FROM campaign\",\n `WHERE segments.date BETWEEN '${params.startDate}' AND '${params.endDate}'`,\n \"AND campaign.status = 'ENABLED'\",\n \"ORDER BY metrics.cost_micros DESC\",\n ].join(\" \"),\n developerToken,\n loginCustomerId\n ),\n searchGoogleAds(\n customerId,\n [\n \"SELECT\",\n \"campaign.advertising_channel_type,\",\n \"metrics.cost_micros,\",\n \"metrics.conversions_value\",\n \"FROM campaign\",\n `WHERE segments.date BETWEEN '${params.startDate}' AND '${params.endDate}'`,\n \"AND campaign.status = 'ENABLED'\",\n ].join(\" \"),\n developerToken,\n loginCustomerId\n ),\n searchGoogleAds(\n customerId,\n [\n \"SELECT\",\n \"segments.date,\",\n \"metrics.cost_micros,\",\n \"metrics.conversions_value,\",\n \"metrics.conversions\",\n \"FROM customer\",\n `WHERE segments.date BETWEEN '${params.startDate}' AND '${params.endDate}'`,\n \"ORDER BY segments.date\",\n ].join(\" \"),\n developerToken,\n loginCustomerId\n ),\n ]);\n\n const campaignRows = campaignsResult.rows.map((row) => ({\n campaign_name: getFieldValue(row, \"campaign.name\"),\n channel_type: getFieldValue(row, \"campaign.advertisingChannelType\"),\n cost: microsToCurrency(getFieldValue(row, \"metrics.costMicros\")),\n conversions: round(parseGoogleAdsMetricValue(getFieldValue(row, \"metrics.conversions\"))),\n conversion_value: round(\n parseGoogleAdsMetricValue(getFieldValue(row, \"metrics.conversionsValue\"))\n ),\n }));\n\n const totalCost = campaignRows.reduce((sum, row) => sum + row.cost, 0);\n const totalConversions = campaignRows.reduce((sum, row) => sum + row.conversions, 0);\n const totalConversionValue = campaignRows.reduce((sum, row) => sum + row.conversion_value, 0);\n const topCampaign = campaignRows[0];\n const topCampaignShare = round(toPercent(topCampaign?.cost ?? 0, totalCost));\n\n const channelCosts = new Map<string, number>();\n for (const row of channelsResult.rows) {\n const channelType = String(\n getFieldValue(row, \"campaign.advertisingChannelType\", \"UNKNOWN\") ?? \"UNKNOWN\"\n );\n channelCosts.set(\n channelType,\n (channelCosts.get(channelType) ?? 0) +\n microsToCurrency(getFieldValue(row, \"metrics.costMicros\"))\n );\n }\n const dominantChannel = Array.from(channelCosts.entries()).sort((a, b) => b[1] - a[1])[0];\n const dominantChannelShare = round(toPercent(dominantChannel?.[1] ?? 0, totalCost));\n\n const series = seriesResult.rows.map((row) => ({\n period_start: String(getFieldValue(row, \"segments.date\") ?? \"\"),\n cost: microsToCurrency(getFieldValue(row, \"metrics.costMicros\")),\n conversion_value: round(\n parseGoogleAdsMetricValue(getFieldValue(row, \"metrics.conversionsValue\"))\n ),\n conversions: round(parseGoogleAdsMetricValue(getFieldValue(row, \"metrics.conversions\"))),\n }));\n const midpoint = Math.ceil(series.length / 2);\n const firstHalf = series.slice(0, midpoint);\n const secondHalf = series.slice(midpoint);\n const firstHalfRoas = round(\n firstHalf.reduce((sum, item) => sum + item.conversion_value, 0) /\n firstHalf.reduce((sum, item) => sum + item.cost, 0)\n );\n const secondHalfRoas = round(\n secondHalf.reduce((sum, item) => sum + item.conversion_value, 0) /\n secondHalf.reduce((sum, item) => sum + item.cost, 0)\n );\n\n const risks = [];\n\n if (topCampaignShare >= 70) {\n risks.push(\n buildRisk(\n \"campaign_concentration_high\",\n \"high\",\n \"Concentraci\u00F3n alta en una campa\u00F1a\",\n `La campa\u00F1a principal concentra ${topCampaignShare}% del gasto.`,\n topCampaignShare\n )\n );\n } else if (topCampaignShare >= 50) {\n risks.push(\n buildRisk(\n \"campaign_concentration_medium\",\n \"medium\",\n \"Concentraci\u00F3n relevante en una campa\u00F1a\",\n `La campa\u00F1a principal concentra ${topCampaignShare}% del gasto.`,\n topCampaignShare\n )\n );\n }\n\n if (dominantChannelShare >= 80) {\n risks.push(\n buildRisk(\n \"channel_concentration_high\",\n \"high\",\n \"Dependencia alta de un tipo de campa\u00F1a\",\n `${dominantChannel?.[0] ?? \"UNKNOWN\"} concentra ${dominantChannelShare}% del gasto.`,\n dominantChannelShare\n )\n );\n } else if (dominantChannelShare >= 60) {\n risks.push(\n buildRisk(\n \"channel_concentration_medium\",\n \"medium\",\n \"Dependencia relevante de un tipo de campa\u00F1a\",\n `${dominantChannel?.[0] ?? \"UNKNOWN\"} concentra ${dominantChannelShare}% del gasto.`,\n dominantChannelShare\n )\n );\n }\n\n const overallRoas = round(totalConversionValue / totalCost);\n if (overallRoas < 1) {\n risks.push(\n buildRisk(\n \"low_roas\",\n \"high\",\n \"ROAS por debajo de 1\",\n `El ROAS agregado es ${overallRoas}. La cuenta est\u00E1 devolviendo menos valor que el gasto atribuido.`,\n overallRoas\n )\n );\n } else if (overallRoas < 1.5) {\n risks.push(\n buildRisk(\n \"borderline_roas\",\n \"medium\",\n \"ROAS ajustado al l\u00EDmite\",\n `El ROAS agregado es ${overallRoas}. Hay poco margen antes de entrar en zona de riesgo.`,\n overallRoas\n )\n );\n }\n\n if (totalConversions < 5) {\n risks.push(\n buildRisk(\n \"low_conversion_volume\",\n \"medium\",\n \"Volumen de conversiones bajo\",\n `La cuenta gener\u00F3 ${round(totalConversions)} conversiones en el per\u00EDodo. La se\u00F1al estad\u00EDstica es limitada.`,\n totalConversions\n )\n );\n }\n\n if (firstHalf.length > 0 && secondHalf.length > 0 && secondHalfRoas < firstHalfRoas * 0.7) {\n risks.push(\n buildRisk(\n \"roas_deteriorating\",\n \"medium\",\n \"Deterioro reciente de eficiencia\",\n `El ROAS cay\u00F3 de ${firstHalfRoas} en la primera mitad a ${secondHalfRoas} en la segunda mitad del per\u00EDodo.`,\n secondHalfRoas\n )\n );\n }\n\n const highSeverityCount = risks.filter((risk) => risk.severity === \"high\").length;\n const mediumSeverityCount = risks.filter((risk) => risk.severity === \"medium\").length;\n const overallSeverity: RiskSeverity =\n highSeverityCount > 0 ? \"high\" : mediumSeverityCount > 0 ? \"medium\" : \"low\";\n\n return object(\n stripNulls({\n customer_id: customerId,\n login_customer_id: loginCustomerId,\n customer_name: getFieldValue(campaignsResult.rows[0] ?? {}, \"customer.descriptiveName\"),\n currency_code: getFieldValue(campaignsResult.rows[0] ?? {}, \"customer.currencyCode\"),\n date_range: {\n start_date: params.startDate,\n end_date: params.endDate,\n },\n overview: {\n total_campaigns: campaignRows.length,\n total_cost: round(totalCost),\n total_conversions: round(totalConversions),\n total_conversion_value: round(totalConversionValue),\n roas: overallRoas,\n top_campaign_by_cost: topCampaign?.campaign_name,\n top_campaign_cost_share_percent: topCampaignShare,\n dominant_channel: dominantChannel?.[0],\n dominant_channel_cost_share_percent: dominantChannelShare,\n first_half_roas: firstHalfRoas,\n second_half_roas: secondHalfRoas,\n },\n risk_summary: {\n overall_severity: overallSeverity,\n high_severity_count: highSeverityCount,\n medium_severity_count: mediumSeverityCount,\n total_risks: risks.length,\n },\n risks,\n metadata: {\n request_ids: [campaignsResult.requestId, channelsResult.requestId, seriesResult.requestId],\n },\n })\n );\n } catch (err) {\n return error(err instanceof Error ? err.message : \"Failed to evaluate Google Ads account risks\");\n }\n}\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,OAAO,cAAc;AAC9B,SAAS,SAAS;AAElB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,uBAAuB;AAChC,SAAS,kBAAkB;AAI3B,SAAS,UACP,MACA,UACA,OACA,QACA,aACA;AACA,SAAO,WAAW;AAAA,IAChB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,cAAc,gBAAgB,SAAY,MAAM,WAAW,IAAI;AAAA,EACjE,CAAC;AACH;AAEO,MAAM,8BAA8B,EAAE,OAAO;AAAA,EAClD,WAAW,EAAE,OAAO,EAAE,MAAM,SAAS,EAAE,SAAS,kCAAkC;AAAA,EAClF,SAAS,EAAE,OAAO,EAAE,MAAM,SAAS,EAAE,SAAS,gCAAgC;AAAA,EAC9E,YAAY,EACT,OAAO,EACP,SAAS,
|
|
4
|
+
"sourcesContent": ["import { error, object } from \"mcp-use/server\";\nimport { z } from \"zod\";\n\nimport {\n dateRegex,\n getFieldValue,\n microsToCurrency,\n parseGoogleAdsMetricValue,\n resolveGoogleAdsCustomerId,\n resolveGoogleAdsDeveloperToken,\n resolveGoogleAdsLoginCustomerId,\n round,\n toPercent,\n} from \"../../utils/google-ads.js\";\nimport { searchGoogleAds } from \"../../services/google-ads/google-ads-client.js\";\nimport { stripNulls } from \"../../utils/strip-payload.js\";\n\ntype RiskSeverity = \"low\" | \"medium\" | \"high\";\n\nfunction buildRisk(\n code: string,\n severity: RiskSeverity,\n title: string,\n detail: string,\n metricValue?: number\n) {\n return stripNulls({\n code,\n severity,\n title,\n detail,\n metric_value: metricValue !== undefined ? round(metricValue) : undefined,\n });\n}\n\nexport const googleAdsAccountRisksSchema = z.object({\n startDate: z.string().regex(dateRegex).describe(\"Start date in YYYY-MM-DD format.\"),\n endDate: z.string().regex(dateRegex).describe(\"End date in YYYY-MM-DD format.\"),\n customerId: z\n .string()\n .optional()\n .describe(\"Google Ads customer ID to query. If omitted, resolves the profileId mapping. Accepts digits with or without hyphens.\"),\n profileId: z.string().optional().describe(\"Optional business profile ID used to resolve the mapped Google Ads customer ID.\"),\n loginCustomerId: z\n .string()\n .optional()\n .describe(\n \"Optional manager account ID used as login customer. If omitted, uses GOOGLE_ADS_LOGIN_CUSTOMER_ID when configured.\"\n ),\n});\n\nexport async function googleAdsAccountRisksHandler(\n params: z.infer<typeof googleAdsAccountRisksSchema>\n) {\n try {\n const customerId = await resolveGoogleAdsCustomerId(params.customerId, params.profileId);\n const loginCustomerId = resolveGoogleAdsLoginCustomerId(params.loginCustomerId);\n const developerToken = resolveGoogleAdsDeveloperToken();\n\n const [campaignsResult, channelsResult, seriesResult] = await Promise.all([\n searchGoogleAds(\n customerId,\n [\n \"SELECT\",\n \"customer.descriptive_name,\",\n \"customer.currency_code,\",\n \"campaign.id,\",\n \"campaign.name,\",\n \"campaign.advertising_channel_type,\",\n \"metrics.impressions,\",\n \"metrics.clicks,\",\n \"metrics.cost_micros,\",\n \"metrics.conversions,\",\n \"metrics.conversions_value\",\n \"FROM campaign\",\n `WHERE segments.date BETWEEN '${params.startDate}' AND '${params.endDate}'`,\n \"AND campaign.status = 'ENABLED'\",\n \"ORDER BY metrics.cost_micros DESC\",\n ].join(\" \"),\n developerToken,\n loginCustomerId\n ),\n searchGoogleAds(\n customerId,\n [\n \"SELECT\",\n \"campaign.advertising_channel_type,\",\n \"metrics.cost_micros,\",\n \"metrics.conversions_value\",\n \"FROM campaign\",\n `WHERE segments.date BETWEEN '${params.startDate}' AND '${params.endDate}'`,\n \"AND campaign.status = 'ENABLED'\",\n ].join(\" \"),\n developerToken,\n loginCustomerId\n ),\n searchGoogleAds(\n customerId,\n [\n \"SELECT\",\n \"segments.date,\",\n \"metrics.cost_micros,\",\n \"metrics.conversions_value,\",\n \"metrics.conversions\",\n \"FROM customer\",\n `WHERE segments.date BETWEEN '${params.startDate}' AND '${params.endDate}'`,\n \"ORDER BY segments.date\",\n ].join(\" \"),\n developerToken,\n loginCustomerId\n ),\n ]);\n\n const campaignRows = campaignsResult.rows.map((row) => ({\n campaign_name: getFieldValue(row, \"campaign.name\"),\n channel_type: getFieldValue(row, \"campaign.advertisingChannelType\"),\n cost: microsToCurrency(getFieldValue(row, \"metrics.costMicros\")),\n conversions: round(parseGoogleAdsMetricValue(getFieldValue(row, \"metrics.conversions\"))),\n conversion_value: round(\n parseGoogleAdsMetricValue(getFieldValue(row, \"metrics.conversionsValue\"))\n ),\n }));\n\n const totalCost = campaignRows.reduce((sum, row) => sum + row.cost, 0);\n const totalConversions = campaignRows.reduce((sum, row) => sum + row.conversions, 0);\n const totalConversionValue = campaignRows.reduce((sum, row) => sum + row.conversion_value, 0);\n const topCampaign = campaignRows[0];\n const topCampaignShare = round(toPercent(topCampaign?.cost ?? 0, totalCost));\n\n const channelCosts = new Map<string, number>();\n for (const row of channelsResult.rows) {\n const channelType = String(\n getFieldValue(row, \"campaign.advertisingChannelType\", \"UNKNOWN\") ?? \"UNKNOWN\"\n );\n channelCosts.set(\n channelType,\n (channelCosts.get(channelType) ?? 0) +\n microsToCurrency(getFieldValue(row, \"metrics.costMicros\"))\n );\n }\n const dominantChannel = Array.from(channelCosts.entries()).sort((a, b) => b[1] - a[1])[0];\n const dominantChannelShare = round(toPercent(dominantChannel?.[1] ?? 0, totalCost));\n\n const series = seriesResult.rows.map((row) => ({\n period_start: String(getFieldValue(row, \"segments.date\") ?? \"\"),\n cost: microsToCurrency(getFieldValue(row, \"metrics.costMicros\")),\n conversion_value: round(\n parseGoogleAdsMetricValue(getFieldValue(row, \"metrics.conversionsValue\"))\n ),\n conversions: round(parseGoogleAdsMetricValue(getFieldValue(row, \"metrics.conversions\"))),\n }));\n const midpoint = Math.ceil(series.length / 2);\n const firstHalf = series.slice(0, midpoint);\n const secondHalf = series.slice(midpoint);\n const firstHalfRoas = round(\n firstHalf.reduce((sum, item) => sum + item.conversion_value, 0) /\n firstHalf.reduce((sum, item) => sum + item.cost, 0)\n );\n const secondHalfRoas = round(\n secondHalf.reduce((sum, item) => sum + item.conversion_value, 0) /\n secondHalf.reduce((sum, item) => sum + item.cost, 0)\n );\n\n const risks = [];\n\n if (topCampaignShare >= 70) {\n risks.push(\n buildRisk(\n \"campaign_concentration_high\",\n \"high\",\n \"Concentraci\u00F3n alta en una campa\u00F1a\",\n `La campa\u00F1a principal concentra ${topCampaignShare}% del gasto.`,\n topCampaignShare\n )\n );\n } else if (topCampaignShare >= 50) {\n risks.push(\n buildRisk(\n \"campaign_concentration_medium\",\n \"medium\",\n \"Concentraci\u00F3n relevante en una campa\u00F1a\",\n `La campa\u00F1a principal concentra ${topCampaignShare}% del gasto.`,\n topCampaignShare\n )\n );\n }\n\n if (dominantChannelShare >= 80) {\n risks.push(\n buildRisk(\n \"channel_concentration_high\",\n \"high\",\n \"Dependencia alta de un tipo de campa\u00F1a\",\n `${dominantChannel?.[0] ?? \"UNKNOWN\"} concentra ${dominantChannelShare}% del gasto.`,\n dominantChannelShare\n )\n );\n } else if (dominantChannelShare >= 60) {\n risks.push(\n buildRisk(\n \"channel_concentration_medium\",\n \"medium\",\n \"Dependencia relevante de un tipo de campa\u00F1a\",\n `${dominantChannel?.[0] ?? \"UNKNOWN\"} concentra ${dominantChannelShare}% del gasto.`,\n dominantChannelShare\n )\n );\n }\n\n const overallRoas = round(totalConversionValue / totalCost);\n if (overallRoas < 1) {\n risks.push(\n buildRisk(\n \"low_roas\",\n \"high\",\n \"ROAS por debajo de 1\",\n `El ROAS agregado es ${overallRoas}. La cuenta est\u00E1 devolviendo menos valor que el gasto atribuido.`,\n overallRoas\n )\n );\n } else if (overallRoas < 1.5) {\n risks.push(\n buildRisk(\n \"borderline_roas\",\n \"medium\",\n \"ROAS ajustado al l\u00EDmite\",\n `El ROAS agregado es ${overallRoas}. Hay poco margen antes de entrar en zona de riesgo.`,\n overallRoas\n )\n );\n }\n\n if (totalConversions < 5) {\n risks.push(\n buildRisk(\n \"low_conversion_volume\",\n \"medium\",\n \"Volumen de conversiones bajo\",\n `La cuenta gener\u00F3 ${round(totalConversions)} conversiones en el per\u00EDodo. La se\u00F1al estad\u00EDstica es limitada.`,\n totalConversions\n )\n );\n }\n\n if (firstHalf.length > 0 && secondHalf.length > 0 && secondHalfRoas < firstHalfRoas * 0.7) {\n risks.push(\n buildRisk(\n \"roas_deteriorating\",\n \"medium\",\n \"Deterioro reciente de eficiencia\",\n `El ROAS cay\u00F3 de ${firstHalfRoas} en la primera mitad a ${secondHalfRoas} en la segunda mitad del per\u00EDodo.`,\n secondHalfRoas\n )\n );\n }\n\n const highSeverityCount = risks.filter((risk) => risk.severity === \"high\").length;\n const mediumSeverityCount = risks.filter((risk) => risk.severity === \"medium\").length;\n const overallSeverity: RiskSeverity =\n highSeverityCount > 0 ? \"high\" : mediumSeverityCount > 0 ? \"medium\" : \"low\";\n\n return object(\n stripNulls({\n customer_id: customerId,\n login_customer_id: loginCustomerId,\n customer_name: getFieldValue(campaignsResult.rows[0] ?? {}, \"customer.descriptiveName\"),\n currency_code: getFieldValue(campaignsResult.rows[0] ?? {}, \"customer.currencyCode\"),\n date_range: {\n start_date: params.startDate,\n end_date: params.endDate,\n },\n overview: {\n total_campaigns: campaignRows.length,\n total_cost: round(totalCost),\n total_conversions: round(totalConversions),\n total_conversion_value: round(totalConversionValue),\n roas: overallRoas,\n top_campaign_by_cost: topCampaign?.campaign_name,\n top_campaign_cost_share_percent: topCampaignShare,\n dominant_channel: dominantChannel?.[0],\n dominant_channel_cost_share_percent: dominantChannelShare,\n first_half_roas: firstHalfRoas,\n second_half_roas: secondHalfRoas,\n },\n risk_summary: {\n overall_severity: overallSeverity,\n high_severity_count: highSeverityCount,\n medium_severity_count: mediumSeverityCount,\n total_risks: risks.length,\n },\n risks,\n metadata: {\n request_ids: [campaignsResult.requestId, channelsResult.requestId, seriesResult.requestId],\n },\n })\n );\n } catch (err) {\n return error(err instanceof Error ? err.message : \"Failed to evaluate Google Ads account risks\");\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,OAAO,cAAc;AAC9B,SAAS,SAAS;AAElB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,uBAAuB;AAChC,SAAS,kBAAkB;AAI3B,SAAS,UACP,MACA,UACA,OACA,QACA,aACA;AACA,SAAO,WAAW;AAAA,IAChB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,cAAc,gBAAgB,SAAY,MAAM,WAAW,IAAI;AAAA,EACjE,CAAC;AACH;AAEO,MAAM,8BAA8B,EAAE,OAAO;AAAA,EAClD,WAAW,EAAE,OAAO,EAAE,MAAM,SAAS,EAAE,SAAS,kCAAkC;AAAA,EAClF,SAAS,EAAE,OAAO,EAAE,MAAM,SAAS,EAAE,SAAS,gCAAgC;AAAA,EAC9E,YAAY,EACT,OAAO,EACP,SAAS,EACT,SAAS,sHAAsH;AAAA,EAClI,WAAW,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,iFAAiF;AAAA,EAC3H,iBAAiB,EACd,OAAO,EACP,SAAS,EACT;AAAA,IACC;AAAA,EACF;AACJ,CAAC;AAED,eAAsB,6BACpB,QACA;AACA,MAAI;AACF,UAAM,aAAa,MAAM,2BAA2B,OAAO,YAAY,OAAO,SAAS;AACvF,UAAM,kBAAkB,gCAAgC,OAAO,eAAe;AAC9E,UAAM,iBAAiB,+BAA+B;AAEtD,UAAM,CAAC,iBAAiB,gBAAgB,YAAY,IAAI,MAAM,QAAQ,IAAI;AAAA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B;AAAA,UACvB,aAAa,MAAM;AAAA,QACrB;AAAA,QACA;AAAA,QACA,UAAU;AAAA,UACR,aAAa,CAAC,gBAAgB,WAAW,eAAe,WAAW,aAAa,SAAS;AAAA,QAC3F;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF,SAAS,KAAK;AACZ,WAAO,MAAM,eAAe,QAAQ,IAAI,UAAU,6CAA6C;AAAA,EACjG;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -15,7 +15,8 @@ import { stripNulls } from "../../utils/strip-payload.js";
|
|
|
15
15
|
const googleAdsBreakEvenAnalysisSchema = z.object({
|
|
16
16
|
startDate: z.string().regex(dateRegex).describe("Start date in YYYY-MM-DD format."),
|
|
17
17
|
endDate: z.string().regex(dateRegex).describe("End date in YYYY-MM-DD format."),
|
|
18
|
-
customerId: z.string().describe("Google Ads customer ID to query. Accepts digits with or without hyphens."),
|
|
18
|
+
customerId: z.string().optional().describe("Google Ads customer ID to query. If omitted, resolves the profileId mapping. Accepts digits with or without hyphens."),
|
|
19
|
+
profileId: z.string().optional().describe("Optional business profile ID used to resolve the mapped Google Ads customer ID."),
|
|
19
20
|
loginCustomerId: z.string().optional().describe(
|
|
20
21
|
"Optional manager account ID used as login customer. If omitted, uses GOOGLE_ADS_LOGIN_CUSTOMER_ID when configured."
|
|
21
22
|
),
|
|
@@ -24,7 +25,7 @@ const googleAdsBreakEvenAnalysisSchema = z.object({
|
|
|
24
25
|
});
|
|
25
26
|
async function googleAdsBreakEvenAnalysisHandler(params) {
|
|
26
27
|
try {
|
|
27
|
-
const customerId = resolveGoogleAdsCustomerId(params.customerId);
|
|
28
|
+
const customerId = await resolveGoogleAdsCustomerId(params.customerId, params.profileId);
|
|
28
29
|
const loginCustomerId = resolveGoogleAdsLoginCustomerId(params.loginCustomerId);
|
|
29
30
|
const developerToken = resolveGoogleAdsDeveloperToken();
|
|
30
31
|
const result = await searchGoogleAds(
|