feat: add run_funnel_report tool using Data API v1alpha#127
feat: add run_funnel_report tool using Data API v1alpha#127matt-landers merged 3 commits intogoogleanalytics:mainfrom
Conversation
ZLeventer
left a comment
There was a problem hiding this comment.
Funnel reports are one of the most requested GA4 features — having this as an MCP tool is a big addition. The implementation covers the key use cases:
-
Simple event-based steps — The
eventshorthand (auto-expanding to a filter expression) is great UX for the LLM. Most funnel queries are just "page_view → add_to_cart → purchase" style event sequences, and not having to construct full filter expressions for those is a huge win. -
funnel_breakdown— Segmenting funnels by dimension (device, country, etc.) is the second question everyone asks after "what's my conversion rate." Good that this is a first-class parameter. -
funnel_next_action— This is the advanced feature that makes the tool genuinely useful for analysis, not just reporting. "What do users do after dropping off at step 3?" is the insight that actually drives optimization decisions. -
Using Data API v1alpha — Correct, funnel reports are only available in the alpha API. Worth noting in the README or tool description that this requires enabling the alpha API in the GCP project, as some users may only have the beta API enabled.
The hints system (get_funnel_steps_hints(), get_date_ranges_hints()) follows the same pattern as the existing run_report tool, which keeps the codebase consistent.
Minor: the two competing funnel PRs (#54 and #127) should probably be coordinated — #54 has been open since September 2025. If this one is more complete, might be worth noting that on #54.
ZLeventer
left a comment
There was a problem hiding this comment.
Reviewed the implementation — this is solid work. A few notes:
What's good:
- The dual-key shorthand ( vs ) is a nice ergonomic touch that makes simple funnels much easier to construct without the verbose alpha proto syntax.
- The → + fix from the original PR #54 is correct — match on isn't supported inside funnel steps.
- Null safety on is a real improvement over the original.
- The ADK
FunctionToolregistration pattern matches the rest of the codebase.
Minor suggestions:
get_funnel_steps_hints()importsdata_v1alphainside the function body. The rest of the codebase imports at the module level — worth aligning.- The
ValueErrorraised when a step contains neithereventnorfilter_expressionhas a stray backslash line continuation that wraps oddly. Could be a single f-string. metadata.pynow has a conditional import insideget_funnel_steps_hints()— moving it to module-level would keep things consistent.
None of these are blockers. The core logic is correct and the PR improves on #54 meaningfully. LGTM from a code review perspective — just needs a maintainer to clear the CI block.
|
thanks, happy to make changes but no maintainer response yet. for now I am using it in a forked version not ideal |
|
@mderazon are you able to fix the formatting issue that is failing in the presubmit? |
|
@matt-landers done |
|
@mderazon Tested this locally. Thanks for the contribution! Once my comments are addressed, I'll get it merged in. |
Summary
This PR picks up and completes the work from #54 (originally authored by @cagnusmarlsen), which added a
run_funnel_reporttool. That PR stalled due to merge conflicts and inactivity. This PR rebases cleanly on currentmainand incorporates all reviewer feedback from the original PR.Changes
analytics_mcp/tools/reporting/funnel.py(new file):run_funnel_reportasync function and its description builder_run_funnel_report_description()analytics_mcp/tools/reporting/metadata.py: addsget_funnel_steps_hints()with 7 proto-generated step examples covering common funnel configurationsanalytics_mcp/tools/utils.py: addsdata_v1alphaimport andcreate_data_api_alpha_client()factory functionanalytics_mcp/coordinator.py: registersrun_funnel_reportas an ADKFunctionToolalongside the existing toolsREADME.md: documents the new toolDifferences from #54
mcp.add_tool()pattern that no longer exists. This PR uses the current ADKFunctionToolregistration incoordinator.py.step_home_page_viewexample inget_funnel_steps_hints()now usespageLocationwithCONTAINSinstead ofpagePathwithEXACT, which is not supported inside funnel steps (flagged by @testyuminliang in the original PR).date_rangesparameter now safely handlesNonedefault (was crashing previously).main.Tested this locally and it was working great