Skip to content

[Main] Fix event tracking#11499

Open
lasanthaS wants to merge 1 commit into
wso2:masterfrom
lasanthaS:master
Open

[Main] Fix event tracking#11499
lasanthaS wants to merge 1 commit into
wso2:masterfrom
lasanthaS:master

Conversation

@lasanthaS

Copy link
Copy Markdown
Contributor

Purpose

$subject

Security checks

@coderabbitai

coderabbitai Bot commented Jun 14, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Summary

Updated event tracking functionality in the documentation template's base JavaScript file. The Google Tag Manager script is now injected unconditionally without domain-based conditional checks. Removed prior conditional JavaScript blocks related to domain restrictions.

Replaced the Moesif initialization configuration with a lightweight trackEvent() helper function that safely calls Moesif's tracking API only when the Moesif library is available. Added automatic page view tracking via a DOMContentLoaded event listener that logs a "Page-Viewed" event with the current page title and includes metadata such as domain, pathname, and asset type information.

Changes:

  • Removed domain allowlist conditional logic for Google Tag Manager injection
  • Removed prior Reo-related JavaScript conditional block
  • Replaced Moesif setup script with lightweight trackEvent(eventName, properties) helper function
  • Added automatic "Page-Viewed" event tracking on page load

Walkthrough

The base HTML template's JavaScript is updated in two areas. First, the Google Tag Manager script loader is now injected unconditionally, removing the prior wso2.com hostname allowlist check and its else-branch warning. The Reo-related conditional block that followed the old GTM snippet is also removed. Second, the Moesif browser script import and moesif.init(...) configuration block are replaced with a global trackEvent(eventName, properties) function that calls moesif.track(...) only when moesif is defined, and a DOMContentLoaded listener that emits a "Page-Viewed" event with the current page title.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is incomplete with a placeholder ($subject) in the Purpose section and lacks details about the actual changes, goals, approach, and impact. Complete the Purpose section with a clear explanation of the tracking issue being fixed, and fill in other relevant sections such as Goals, Approach, and Release notes to match the template requirements.
Title check ❓ Inconclusive The title '[Main] Fix event tracking' is vague and lacks specificity about which aspect of event tracking is being fixed. Provide a more descriptive title that specifies what event tracking issue is being resolved, such as 'Refactor JavaScript event tracking implementation'.
✅ Passed checks (3 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@en/theme/material/partials/javascripts/base.html`:
- Around line 44-54: The trackEvent function's conditional check `if (moesif)`
will throw a ReferenceError if the moesif variable is not defined in the global
scope, preventing the guard from working as intended. Replace the condition with
either `typeof moesif !== 'undefined'` or use `window.moesif` instead of the
bare `moesif` reference. The window.moesif approach is preferred as it safely
returns undefined for missing properties without throwing an error. Update both
the condition and the subsequent moesif.track call to use the same safe
reference pattern.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f579aae5-a496-4bd2-9ec9-62360a362c6e

📥 Commits

Reviewing files that changed from the base of the PR and between 5642000 and a9086bd.

📒 Files selected for processing (1)
  • en/theme/material/partials/javascripts/base.html

Comment on lines +44 to +54
function trackEvent(eventName, properties) {
if (moesif) {
moesif.track(eventName, {
product: "api",
asset_type: "docs",
domain: window.location.hostname,
page_url: window.location.pathname,
...properties,
});
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Use typeof check or window.moesif to avoid ReferenceError.

The current if (moesif) guard will throw a ReferenceError if moesif is not defined in the global scope, defeating the purpose of the conditional check.

Suggested fix
 function trackEvent(eventName, properties) {
-  if (moesif) {
+  if (typeof moesif !== 'undefined') {
     moesif.track(eventName, {
       product: "api",
       asset_type: "docs",
       domain: window.location.hostname,
       page_url: window.location.pathname,
       ...properties,
     });
   }
 }

Alternatively, use window.moesif which safely returns undefined for missing properties.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@en/theme/material/partials/javascripts/base.html` around lines 44 - 54, The
trackEvent function's conditional check `if (moesif)` will throw a
ReferenceError if the moesif variable is not defined in the global scope,
preventing the guard from working as intended. Replace the condition with either
`typeof moesif !== 'undefined'` or use `window.moesif` instead of the bare
`moesif` reference. The window.moesif approach is preferred as it safely returns
undefined for missing properties without throwing an error. Update both the
condition and the subsequent moesif.track call to use the same safe reference
pattern.

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.

3 participants