Skip to content

feat: add support for funnel reports#54

Open
cagnusmarlsen wants to merge 7 commits intogoogleanalytics:mainfrom
cagnusmarlsen:funnel_tool
Open

feat: add support for funnel reports#54
cagnusmarlsen wants to merge 7 commits intogoogleanalytics:mainfrom
cagnusmarlsen:funnel_tool

Conversation

@cagnusmarlsen
Copy link
Copy Markdown

This PR aims to add support for generating funnel reports using the Google Analytics MCP server. It adds a run_funnel_report tool that uses the runFunnelReport method to generate funnel reports based on user queries.

@google-cla
Copy link
Copy Markdown

google-cla bot commented Sep 2, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Copy link
Copy Markdown
Member

@jradcliff jradcliff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for this PR! I added a few comments and suggestions.

  • Josh, Google Analytics team

Comment on lines +283 to +284
"""Run a Google Analytics Data API funnel report.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""Run a Google Analytics Data API funnel report.
"""Run a Google Analytics Data API funnel report.
See the funnel report guide at
https://developers.google.com/analytics/devguides/reporting/data/v1/funnels
for details and examples.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yh data analysis programing method

"""


def _run_funnel_report_description() -> str:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you move this file into a funnel.py file, similar to how we separate out runReport into core.py, run_realtime_report into realtime.py, and get_custom_dimensions_and_metrics, etc. into metadata.py?

Comment on lines +296 to +314
Example:
[
{
"name": "Page View",
"filter_expression": {
"funnel_field_filter": {
"field_name": "eventName",
"string_filter": {
"match_type": "EXACT",
"value": "page_view"
}
}
}
},
{
"name": "Sign Up",
"event": "sign_up"
}
]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move the JSON examples into separate methods that you call here, similar to what we're doing with date range hints, etc. for runReport:

This offers a few advantages:

  1. It keeps this docstring reasonably short.
  2. In the methods that return JSON, you can use the client library to generate the JSON so you know that it's well-formed. This will also make maintenance easier if the API objects evolve and change.

@cagnusmarlsen
Copy link
Copy Markdown
Author

Hi Josh,
Thanks for reviewing! I apologize for the long delay, but I've made the requested changes. Thanks again.

@matt-landers
Copy link
Copy Markdown
Member

matt-landers commented Feb 10, 2026

@cagnusmarlsen If you can resolve the conflicts, I'll get this merged.

),
data_v1alpha.FunnelFilterExpression(
funnel_field_filter=data_v1alpha.FunnelFieldFilter(
field_name="pagePath",
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! I use the funnel report function you created! But meet this problem:

{"error": "Failed to execute tool 'run_funnel_report': 400 Field 'pagePath' is not currently supported inside segments & funnel steps. For a list of valid dimensions and metrics, see https://developers.google.com/analytics/devguides/reporting/data/v1/exploration-api-schema "}"

I think you can use

`field_name="pageLocation",
                    string_filter=data_v1alpha.StringFilter(
                        match_type=data_v1alpha.StringFilter.MatchType.CONTAINS,
                        value=step_dict["page_path"],`

It will also change the logic from EXACT to CONTAINS....but can get the data

@mderazon
Copy link
Copy Markdown

Would be great to merge this PR, seems like almost done ?
@cagnusmarlsen if you can't make it I can try

@cagnusmarlsen
Copy link
Copy Markdown
Author

cagnusmarlsen commented Mar 27, 2026 via email

@mderazon
Copy link
Copy Markdown

Thanks @cagnusmarlsen I created a new PR #127 based on your work to resolve the conflicts let's wait for @matt-landers / team to check it out

@lawrencecode764-cloud
Copy link
Copy Markdown

Thanks you every for sorporting the google service
Am happy and I really appreciate you all.
Am yuskay Lawrence management
Babason by name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants