Skip to content

feat(google-analytics): add Google Analytics GA4 integration#3600

Open
waleedlatif1 wants to merge 1 commit intostagingfrom
waleedlatif1/google-analytics-integration
Open

feat(google-analytics): add Google Analytics GA4 integration#3600
waleedlatif1 wants to merge 1 commit intostagingfrom
waleedlatif1/google-analytics-integration

Conversation

@waleedlatif1
Copy link
Copy Markdown
Collaborator

Summary

  • Add Google Analytics GA4 integration with 3 operations: Run Report, Run Realtime Report, Get Metadata
  • Register OAuth provider with analytics.readonly scope under the Google provider
  • Add block, tools, icon, and docs

Type of Change

  • New feature

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 15, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview, Comment Mar 15, 2026 10:45am

Request Review

@cursor
Copy link
Copy Markdown

cursor bot commented Mar 15, 2026

PR Summary

Medium Risk
Introduces a new OAuth provider and makes authenticated requests to Google Analytics APIs; main risk is correctness of OAuth scopes/redirects and JSON parsing of user-provided filter inputs.

Overview
Adds a new google_analytics integration end-to-end: a block with selectable operations (run report, run realtime report, get metadata), corresponding tool implementations calling the GA4 Data API (runReport, runRealtimeReport, metadata), and registration in the block/tool registries.

Extends OAuth support by registering the google-analytics provider/service (including analytics.readonly scope) and adds a GoogleAnalyticsIcon plus docs page + docs metadata entries; also updates several existing tool docs to include pricing/rateLimit/metadata fields and adjusts some Grain/Jina docs outputs.

Written by Cursor Bugbot for commit 83f3be8. Configure here.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 15, 2026

Greptile Summary

This PR adds a Google Analytics GA4 integration with three operations: Run Report, Run Realtime Report, and Get Metadata. It follows the established integration pattern — new tool files under tools/google_analytics/, a block definition at blocks/blocks/google_analytics.ts, a new google-analytics OAuth service entry with the analytics.readonly scope, registration in both registries, an icon, and docs.

The overall structure is solid: the block correctly uses the basic/advanced OAuth input pattern, canonicalParamId pairing is consistent, type coercions are placed in tools.config.params (not tool), and the TypeScript interfaces are well-typed with no any usage.

Key issues:

  • P1 (×2): JSON.parse is called without try/catch on three user-supplied JSON strings in run_report.ts (dimensionFilter, metricFilter, orderBys) and two in run_realtime_report.ts (dimensionFilter, metricFilter). Invalid JSON input from a user will produce an unhandled SyntaxError instead of a descriptive error message. Every other tool in the codebase that parses user-supplied JSON wraps it in try/catch.

Confidence Score: 4/5

Safe to merge after fixing the unguarded JSON.parse calls in the two report tool files.

Two P1 issues exist: unguarded JSON.parse on user-supplied filter/orderBy strings in run_report.ts and run_realtime_report.ts will produce unhandled SyntaxErrors on malformed input. All other aspects of the integration are well-formed and follow established patterns.

apps/sim/tools/google_analytics/run_report.ts and apps/sim/tools/google_analytics/run_realtime_report.ts — JSON.parse calls need try/catch guards.

Important Files Changed

Filename Overview
apps/sim/tools/google_analytics/run_report.ts Implements the Run Report tool with direct GA4 API calls; unguarded JSON.parse calls on three optional filter params will throw unhandled errors on invalid input.
apps/sim/tools/google_analytics/run_realtime_report.ts Implements the Realtime Report tool; same unguarded JSON.parse issue on dimensionFilter and metricFilter params.
apps/sim/tools/google_analytics/get_metadata.ts Simple GET-based metadata tool; clean implementation with no unguarded parsing.
apps/sim/blocks/blocks/google_analytics.ts Block config with three operations, correct conditional subblocks, proper OAuth input pattern with basic/advanced modes, and correct type coercions in params (not tool).
apps/sim/lib/oauth/oauth.ts Adds google-analytics service entry with the correct analytics.readonly scope; properly registered under the Google provider.
apps/sim/tools/google_analytics/types.ts Well-typed interfaces for all three operations; no use of any.
apps/sim/lib/auth/auth.ts Registers google-analytics OAuth provider with correct scopes; follows the same pattern as other Google sub-providers.

Sequence Diagram

sequenceDiagram
    participant U as User / Agent
    participant B as GA4 Block
    participant T as Tool (run_report / run_realtime_report / get_metadata)
    participant O as Google OAuth
    participant GA as GA4 Data API

    U->>B: Configure operation + params
    B->>O: OAuth consent (analytics.readonly scope)
    O-->>B: accessToken
    B->>T: Execute with params + accessToken
    T->>GA: POST /properties/{id}:runReport
    GA-->>T: { dimensionHeaders, metricHeaders, rows, rowCount, metadata }
    T-->>B: Transformed output
    B-->>U: dimensionHeaders, metricHeaders, rows, rowCount, metadata / dimensions / metrics
Loading

Comments Outside Diff (2)

  1. apps/sim/tools/google_analytics/run_report.ts, line 126-134 (link)

    Unguarded JSON.parse on user-supplied strings

    JSON.parse is called directly on params.dimensionFilter, params.metricFilter, and params.orderBys without any try/catch. If a user provides invalid JSON, this will throw an unhandled SyntaxError instead of a meaningful error message.

    The rest of the codebase wraps user-supplied JSON in try/catch with a descriptive error (see tools/databricks/run_job.ts:65–71, tools/zep/add_messages.ts:43–47):

  2. apps/sim/tools/google_analytics/run_realtime_report.ts, line 100-105 (link)

    Unguarded JSON.parse on user-supplied filter strings

    Same issue as in run_report.ts: JSON.parse(params.dimensionFilter) and JSON.parse(params.metricFilter) are called without try/catch. Invalid JSON input will throw an unhandled SyntaxError.

Reviews (2): Last reviewed commit: "feat(google-analytics): add Google Analy..." | Re-trigger Greptile

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

| `apiKey` | string | Yes | Firecrawl API key |
| `pricing` | custom | No | No description |
| `metadata` | string | No | No description |
| `rateLimit` | string | No | No description |
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unrelated tool docs modified with "No description" entries

Medium Severity

This PR adds pricing, metadata, and rateLimit parameters with "No description" to the docs of many unrelated tools (Firecrawl, Google Books, Google Maps, Google PageSpeed, Google Translate, Linkup, Perplexity, Serper, Jina). These appear to be auto-generated side effects from running a docs generation script, not intentional changes for a Google Analytics feature PR. The "No description" entries degrade documentation quality for those tools.

Additional Locations (2)
Fix in Cursor Fix in Web

@waleedlatif1 waleedlatif1 deleted the branch staging April 3, 2026 23:01
@waleedlatif1 waleedlatif1 reopened this Apr 4, 2026
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.

1 participant