Skip to content

Conversation

@pedrobernardina
Copy link
Contributor

@pedrobernardina pedrobernardina commented Oct 10, 2025

What is this Contribution About?

This contribution introduces a new extraParams prop to the GTM integration, allowing additional query parameters (e.g., version, source, etc.) to be appended dynamically to the GTM script and noscript URLs.
This makes the setup more flexible and prevents the need for hardcoded parameters in future updates.

Summary by CodeRabbit

  • New Features
    • Analytics now accepts optional extra GTM parameters that are appended to both script and noscript GTM URLs; reserved keys (e.g., "id", "ns") and empty keys are ignored to prevent conflicts.
    • The Analytics component forwards these extra parameters to the GTM integration so they are included in all GTM render paths.

@github-actions
Copy link
Contributor

Tagging Options

Should a new tag be published when this PR is merged?

  • 👍 for Patch 0.128.7 update
  • 🎉 for Minor 0.129.0 update
  • 🚀 for Major 1.0.0 update

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 10, 2025

Walkthrough

Adds an ExtraParams type and an optional extraParams?: ExtraParams[] prop to Analytics and TagManager props; forwards extraParams to GoogleTagManager, which appends non-reserved key/value pairs (skipping "id" and "ns") to GTM script and noscript iframe URLs.

Changes

Cohort / File(s) Summary
Analytics GTM extra params
website/components/Analytics.tsx
Added interface ExtraParams { key: string; value: string }; added extraParams?: ExtraParams[] to Props and TagManagerProps; updated Analytics to destructure and forward extraParams to GoogleTagManager; updated GoogleTagManager to iterate extraParams, skip reserved keys ("id", "ns"), and append each non-empty key/value to both the GTM script src and the noscript iframe src.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant Page
  participant Analytics
  participant GoogleTagManager as GTM
  participant Browser

  User->>Page: Load page
  Page->>Analytics: Render (props include extraParams?)
  Analytics->>GTM: Render with extraParams
  Note right of GTM #DDEBF7: Build GTM script & iframe URLs\niterate extraParams, skip "id"/"ns", append key=value pairs
  GTM->>Browser: Insert <script src="...&key=value..."> and <noscript><iframe src="...&key=value..."></iframe></noscript>
  Browser-->>GTM: Load GTM resources
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I twitch my whiskers, params in tow,
I hop through tags where query winds blow,
I skip the reserved, tuck keys in line,
Script and iframe taste the carroted sign,
A tiny hop for context — neat and slow.

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The description only fills out the “What is this Contribution About?” section and omits the required Issue Link, Loom Video, and Demonstration Link sections from the repository’s template, making it incomplete against the specified structure. Please add the missing template sections for Issue Link, Loom Video, and Demonstration Link to fully comply with the repository’s pull request description requirements.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title Check ✅ Passed The title succinctly summarizes the main enhancement by indicating that the analytics feature now supports an extra parameters prop for GTM, and it follows the conventional commit style. It clearly reflects the primary change without extraneous details or ambiguity.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 204f656 and 500bcba.

📒 Files selected for processing (1)
  • website/components/Analytics.tsx (5 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
website/components/Analytics.tsx (1)
compat/std/sections/Analytics.tsx (1)
  • Props (34-49)
🔇 Additional comments (4)
website/components/Analytics.tsx (4)

122-132: LGTM! Well-structured interface with good UX considerations.

The ExtraParams interface is well-defined with clear types and documentation. The @title annotation using template syntax is a nice touch for displaying parameters in the admin interface.


36-45: Verify if empty values should be allowed.

The code checks for reserved keys and non-empty key, but doesn't validate value. The previous review comment suggested checking both key && value. Allowing empty values would result in query parameters like ?version=, which are rarely useful.

Was the omission of the value check intentional, or should it be added to prevent appending parameters with empty values?

If empty values should be filtered out, apply this diff:

  for (const { key, value } of (props.extraParams ?? [])) {
    if (reservedKeys.has(key.toLowerCase())) {
      continue;
    }

-   if (key) {
+   if (key && value) {
      src.searchParams.append(key, value);
      noscript.searchParams.append(key, value);
    }
  }

149-152: LGTM! Props interface properly extended.

The extraParams prop is cleanly integrated into the Props interface with appropriate documentation.


158-194: LGTM! Analytics component properly forwards extraParams.

The extraParams prop is correctly destructured and forwarded to both GoogleTagManager instances in the conditional render branches. The implementation maintains consistency across both code paths.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pedrobernardina pedrobernardina force-pushed the feat/add-extra-params-to-analytics branch from d8b9451 to 6a65c50 Compare October 10, 2025 17:49
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
website/components/Analytics.tsx (1)

35-44: Simplify extraParams processing to improve efficiency.

The current implementation creates an intermediate URLSearchParams object only to immediately iterate through it. This adds unnecessary overhead and complexity.

Apply this diff to simplify the logic:

-  const extraParams = new URLSearchParams(
-    (props.extraParams ?? []).map((param) => [param.key, param.value]),
-  );
-
-  for (const [key, value] of extraParams.entries()) {
-    if (key && value) {
-      src.searchParams.append(key, value);
-      noscript.searchParams.append(key, value);
-    }
-  }
+  (props.extraParams ?? [])
+    .filter((param) => param.key && param.value)
+    .forEach((param) => {
+      src.searchParams.append(param.key, param.value);
+      noscript.searchParams.append(param.key, param.value);
+    });
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ea8f523 and d8b9451.

📒 Files selected for processing (1)
  • website/components/Analytics.tsx (5 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
website/components/Analytics.tsx (1)
compat/std/sections/Analytics.tsx (1)
  • Props (34-49)
🔇 Additional comments (2)
website/components/Analytics.tsx (2)

148-151: LGTM! Clean propagation of extraParams.

The extraParams property is correctly added to the Props interface, destructured in the function signature, and consistently passed to all GoogleTagManager invocations. The optional nature maintains backward compatibility.

Also applies to: 157-164, 177-181, 188-192


41-42: Verify duplicate query parameter handling
URLSearchParams.append produces multiple entries for identical keys (e.g., ?key=1&key=2). Use set instead if duplicates should override. Confirm this is the intended behavior.
File: website/components/Analytics.tsx (lines 41–42)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
website/components/Analytics.tsx (1)

36-36: Consider whether empty values should be allowed.

The check if (key && value) skips parameters with empty strings. While this prevents adding meaningless parameters, it also blocks intentional empty values (e.g., ?debug=).

If empty values are a valid use case, consider adjusting the check:

- if (key && value) {
+ if (key) {
    src.searchParams.append(key, value);
    noscript.searchParams.append(key, value);
  }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ea8f523 and 6a65c50.

📒 Files selected for processing (1)
  • website/components/Analytics.tsx (5 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
website/components/Analytics.tsx (1)
compat/std/sections/Analytics.tsx (1)
  • Props (34-49)
🔇 Additional comments (3)
website/components/Analytics.tsx (3)

117-127: LGTM! Clear interface definition.

The ExtraParams interface is well-defined with appropriate JSDoc annotations. The @title annotation will provide a helpful UI hint when configuring these parameters.


16-16: Props correctly added to both interfaces.

The extraParams property is consistently added to both TagManagerProps and the public Props interface with clear documentation.

Also applies to: 144-147


153-189: extraParams properly forwarded to GoogleTagManager.

The Analytics function correctly destructures extraParams and passes it to both GoogleTagManager instances (lines 173-177 and 184-188), ensuring consistent behavior across both render paths.

@pedrobernardina pedrobernardina force-pushed the feat/add-extra-params-to-analytics branch from 6a65c50 to aa2a4f4 Compare October 10, 2025 17:56
@pedrobernardina pedrobernardina force-pushed the feat/add-extra-params-to-analytics branch from aa2a4f4 to 204f656 Compare October 10, 2025 18:04
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
website/components/Analytics.tsx (2)

34-45: Harden extraParams handling: trim, case-insensitive reserved check, and use set() to avoid duplicates.
Great call skipping reserved keys. Improve robustness:

  • Compare reserved keys case-insensitively.
  • Trim key/value and skip empties.
  • Use URLSearchParams.set to replace duplicates instead of append.
    Also consider hoisting reservedKeys to module scope.

Apply:

-  const reservedKeys = new Set(["id", "ns"]);
+  const reservedKeys = new Set(["id", "ns"]); // case-insensitive check below

-  for (const { key, value } of (props.extraParams ?? [])) {
-    if (reservedKeys.has(key)) {
-      continue;
-    }
-
-    if (key && value) {
-      src.searchParams.append(key, value);
-      noscript.searchParams.append(key, value);
-    }
-  }
+  for (const { key, value } of (props.extraParams ?? [])) {
+    const k = key?.trim();
+    const v = value?.trim();
+    if (!k || !v) continue;
+    if (reservedKeys.has(k.toLowerCase())) continue;
+    // Replace any existing value rather than duplicating
+    src.searchParams.set(k, v);
+    noscript.searchParams.set(k, v);
+  }

121-132: Consider exporting ExtraParams for reuse/introspection.
If other modules or schema tooling need this type, export it; otherwise OK to keep internal.

-interface ExtraParams {
+export interface ExtraParams {
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6a65c50 and aa2a4f4.

📒 Files selected for processing (1)
  • website/components/Analytics.tsx (5 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
website/components/Analytics.tsx (1)
compat/std/sections/Analytics.tsx (1)
  • Props (34-49)
🔇 Additional comments (5)
website/components/Analytics.tsx (5)

16-16: Prop added to TagManagerProps looks good.
Wiring for extraParams starts here; type choice is clear.


149-152: Prop added to public Props looks good.
Docs are clear; no issues.


159-165: Destructuring update LGTM.
No behavior change; keeps props flow simple.


178-182: Pass-through of extraParams to GoogleTagManager LGTM.
Correctly forwards in the trackingIds path.


189-193: Fallback pass-through LGTM.
Correctly forwards when using src without trackingIds.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
website/components/Analytics.tsx (1)

34-45: Consider case-insensitive reserved key check.

The reserved keys check uses case-sensitive matching. If a user accidentally passes "ID" or "Id", it would bypass the check and potentially create issues with GTM.

Apply this diff to make the check case-insensitive:

- const reservedKeys = new Set(["id", "ns"]);
+ const reservedKeys = new Set(["id", "ns"]);

  for (const { key, value } of (props.extraParams ?? [])) {
-   if (reservedKeys.has(key)) {
+   if (reservedKeys.has(key.toLowerCase())) {
      continue;
    }

Additionally, consider expanding the reserved set to include other GTM parameters such as "gtm_auth", "gtm_preview", "gtm_cookies_win", and "l" if you want to prevent users from overriding those as well.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between aa2a4f4 and 204f656.

📒 Files selected for processing (1)
  • website/components/Analytics.tsx (5 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
website/components/Analytics.tsx (1)
compat/std/sections/Analytics.tsx (1)
  • Props (34-49)
🔇 Additional comments (4)
website/components/Analytics.tsx (4)

16-17: LGTM!

The optional extraParams property is properly typed and integrated into the interface.


122-132: LGTM!

The ExtraParams interface is well-documented with helpful JSDoc comments and includes a nice @title annotation for improved UI presentation.


149-152: LGTM!

The extraParams property is properly documented and consistently typed with TagManagerProps.


159-194: LGTM!

The Analytics component properly destructures extraParams from props and consistently forwards it to both GoogleTagManager invocations. The implementation correctly handles both the primary tracking IDs path (lines 178-182) and the fallback src-only path (lines 189-193).

@pedrobernardina pedrobernardina force-pushed the feat/add-extra-params-to-analytics branch from 204f656 to 500bcba Compare October 10, 2025 18:17
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.

2 participants