Skip to content

Conversation

@Swathi-eGov
Copy link
Contributor

@Swathi-eGov Swathi-eGov commented Aug 14, 2025

Summary by CodeRabbit

  • Chores
    • Integrated Matomo analytics site‑wide to track page views and link clicks.
    • Added SPA-friendly page-view tracking so navigation within the app is recorded.
    • Added UI interaction tracking to capture clicks on common interactive elements.
    • Loads the tracking script asynchronously to minimize performance impact.
    • No visible changes to user interface or workflows.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 14, 2025

Walkthrough

Adds a Matomo analytics snippet to the frontend public index.html that initializes _paq, loads Matomo from CDN, configures tracker URL and siteId, adds SPA-friendly URL change tracking (history wrap + popstate), and attaches UI click event tracking sending trackEvent details.

Changes

Cohort / File(s) Summary of Changes
Matomo analytics snippet
frontend/micro-ui/web/public/index.html
Inserted Matomo setup: initializes _paq queue, enqueues trackPageView and enableLinkTracking, sets tracker URL https://digit-analytics.matomo.cloud/matomo.php with siteId: "1", loads https://cdn.matomo.cloud/.../matomo.js asynchronously, adds SPA-friendly URL tracking by wrapping history.pushState/replaceState and listening to popstate (also includes commented MutationObserver approach), and adds a click listener to send trackEvent for UI interactions (captures element type, text, id, classes, href). Includes end marker comment.

Sequence Diagram(s)

sequenceDiagram
  participant B as Browser (app)
  participant S as index.html Snippet
  participant C as Matomo CDN (matomo.js)
  participant T as Matomo Tracker (digit-analytics.matomo.cloud)

  B->>S: Load page → snippet runs
  S->>C: Async load matomo.js
  C-->>B: matomo.js executed
  B->>T: _paq: trackPageView, enableLinkTracking
  Note right of S: Wrap history.pushState/replaceState\nand listen to popstate
  B->>T: on URL change → setCustomUrl + trackPageView
  Note right of S: Click listener captures UI details
  B->>T: on UI click → trackEvent(category="UI Interaction", action, label)
Loading

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

I twitch my whiskers, logs in sight,
A hop, a skip—events take flight!
I mark the routes where pages roam,
And count each click that finds a home.
Tiny rabbit, tracking bright. 🥕✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch FEATURE/CCSD-685

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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: 3

🔭 Outside diff range comments (1)
frontend/micro-ui/web/public/index.html (1)

3-11: Duplicate head tags and duplicated meta/link elements — invalid HTML structure

The document currently has two opening tags and duplicate meta/link tags. This is a parse error and may lead browsers to unpredictably discard or reorder elements. Please keep a single head section.

Apply this diff to remove the first, duplicate head (Lines 3–9):

-  <head>
-    <meta charset="utf-8"/>
-    <link rel="icon" href="https://cdn.jsdelivr.net/npm/@egovernments/digit-ui-css/img/browser-icon.png"/>
-    <link href="https://fonts.googleapis.com/css2?family=Roboto+Condensed:wght@400;500;700&family=Roboto:wght@400;500;700&display=swap" rel='stylesheet' type='text/css'>
-    <link rel="stylesheet" href="https://unpkg.com/@egovernments/[email protected]/dist/index.css"/>
-    <link rel="stylesheet" href="https://unpkg.com/@egovernments/[email protected]/dist/index.css" />
-
-  <head>
+  <head>
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these settings in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 2daad87 and 6724879.

📒 Files selected for processing (1)
  • frontend/micro-ui/web/public/index.html (1 hunks)
🔇 Additional comments (1)
frontend/micro-ui/web/public/index.html (1)

22-36: Matomo snippet is correctly integrated and will load asynchronously

The initialization order and tracker URL/siteId configuration look correct for Matomo Cloud. Async load via CDN is appropriate.

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: 2

🔭 Outside diff range comments (2)
frontend/micro-ui/web/public/index.html (2)

3-9: Invalid duplicate and duplicate meta/link tags — consolidate the head; also retain the components CSS link

Two opening tags and repeated meta/link elements will produce malformed HTML and unpredictable parsing. Remove the duplicate block and keep a single . Ensure the components CSS link from the first block is retained in the remaining head.

Apply this diff to consolidate:

-  <head>
-    <meta charset="utf-8"/>
-    <link rel="icon" href="https://cdn.jsdelivr.net/npm/@egovernments/digit-ui-css/img/browser-icon.png"/>
-    <link href="https://fonts.googleapis.com/css2?family=Roboto+Condensed:wght@400;500;700&family=Roboto:wght@400;500;700&display=swap" rel='stylesheet' type='text/css'>
-    <link rel="stylesheet" href="https://unpkg.com/@egovernments/[email protected]/dist/index.css"/>
-    <link rel="stylesheet" href="https://unpkg.com/@egovernments/[email protected]/dist/index.css" />
-
-  <head>
+  <head>
   <meta charset="utf-8" />
   <link rel="icon" href="https://cdn.jsdelivr.net/npm/@egovernments/digit-ui-css/img/browser-icon.png" />
   <link
     href="https://fonts.googleapis.com/css2?family=Roboto+Condensed:wght@400;500;700&family=Roboto:wght@400;500;700&display=swap"
     rel='stylesheet' type='text/css'>
   <link rel="stylesheet" href="https://unpkg.com/@egovernments/[email protected]/dist/index.css" />
+  <link rel="stylesheet" href="https://unpkg.com/@egovernments/[email protected]/dist/index.css" />
   <!-- <link rel="stylesheet" href="https://unpkg.com/@egovernments/digit-ui-css/dist/index.css"/> -->
   <meta name="viewport" content="width=device-width, initial-scale=1" />
   <meta name="theme-color" content="#00bcd1" />
   <title>Digit</title>
   <!-- <script src="https://s3.ap-south-1.amazonaws.com/egov-dev-assets/globalConfigs.js"></script> -->

Also applies to: 10-21


114-129: Move the <style> block inside the (or into )

The style tag currently sits between and , which is invalid HTML. Move it inside the head (preferred) before the closing , or place it inside the body.

Suggested relocation (place before Line 113):

-</head>
-<style>
+  <style>
      .options-card {
       overflow: auto ;
       max-height: 18em !important;
     }
 
     .employee-select-wrap .options-card {
     overflow: auto !important;
     max-height: 18em !important;
   }
     .employee-select-wrap .options-card-DateRangePicker {
     overflow: visible !important;
     max-height: 24em !important;
   }
 
-</style>
- 
-</head>
+</style>
+</head>
♻️ Duplicate comments (2)
frontend/micro-ui/web/public/index.html (2)

49-81: SPA tracking: add guard to avoid double-wrapping history; set URL to path+search and update document title before tracking

Current monkey-patching works but can wrap multiple times if the block executes twice, and it tracks with full origin which can fragment analytics. Prefer path+search, update document title, and guard repeated wrapping.

Apply this diff:

-      let lastUrl = location.href;
+      function currentPath() {
+        return location.pathname + location.search;
+      }
+      let lastUrl = currentPath();
 
-      function trackUrlChange() {
-        const url = location.href;
+      function trackUrlChange() {
+        const url = currentPath();
         if (url !== lastUrl) {
           lastUrl = url;
           _paq.push(['setCustomUrl', url]);
+          _paq.push(['setDocumentTitle', document.title || '']);
           _paq.push(['trackPageView']);
         }
       }
 
-      // Wrap pushState
-      history.pushState = (function (original) {
-        return function pushState() {
-          const result = original.apply(this, arguments);
-          trackUrlChange();
-          return result;
-        };
-      })(history.pushState);
-
-      // Wrap replaceState
-      history.replaceState = (function (original) {
-        return function replaceState() {
-          const result = original.apply(this, arguments);
-          trackUrlChange();
-          return result;
-        };
-      })(history.replaceState);
+      if (!window.__matomoHistoryWrapped) {
+        // Wrap pushState
+        history.pushState = (function (original) {
+          return function pushState() {
+            const result = original.apply(this, arguments);
+            trackUrlChange();
+            return result;
+          };
+        })(history.pushState);
+
+        // Wrap replaceState
+        history.replaceState = (function (original) {
+          return function replaceState() {
+            const result = original.apply(this, arguments);
+            trackUrlChange();
+            return result;
+          };
+        })(history.replaceState);
+
+        window.__matomoHistoryWrapped = true;
+      }
 
       // Listen for back/forward
       window.addEventListener('popstate', trackUrlChange);

25-36: Gate Matomo behind consent, honor DNT, and fix CSP (frontend/micro-ui/web/public/index.html)

Verified: the Matomo snippet is present inline in frontend/micro-ui/web/public/index.html (around lines 23–36). Matomo supports requireConsent / requireCookieConsent / disableCookies / setDoNotTrack (confirmed).

Very short action: prevent unconditional tracking by adding consent/DNT handling before trackPageView and address CSP by externalizing the bootstrap or using a server nonce.

Files to change

  • frontend/micro-ui/web/public/index.html — replace Matomo bootstrap (currently inline) with the consent/DNT-aware snippet below or move it to an external loader and load that file from an allowed CSP source.

Suggested diff (minimal, uncomment the appropriate consent line for your legal requirement):

-    var _paq = window._paq = window._paq || [];
-    /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
-    _paq.push(['trackPageView']);
-    _paq.push(['enableLinkTracking']);
+    var _paq = window._paq = window._paq || [];
+    // Respect browser Do Not Track
+    _paq.push(['setDoNotTrack', true]);
+    // If you must block all tracking until explicit opt-in (GDPR strict opt-in), uncomment:
+    // _paq.push(['requireConsent']);
+    // If you want cookieless tracking until consent and only allow cookies after consent, uncomment:
+    // _paq.push(['requireCookieConsent']);
+    // To never use cookies at all (always cookieless), uncomment:
+    // _paq.push(['disableCookies']);
+    /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
+    _paq.push(['trackPageView']);
+    _paq.push(['enableLinkTracking']);

CSP note (pick one)

  • Move the inline snippet into an external JS file (e.g. public/analytics/matomo-loader.js) and load it with a normal <script src="..."> so it can be allowed by script-src; OR
  • Keep inline but add a server-generated nonce attribute to this script tag and add the same nonce to your Content-Security-Policy header.

If you want, I can:

  • Provide the externalized bootstrap + consent-gated loader (including example CMP callbacks to call _paq.push(['setConsentGiven']) / _paq.push(['rememberCookieConsentGiven']) on accept), or
  • Produce a small server-side example showing how to inject a CSP nonce and add it to the script tag.
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these settings in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 6724879 and f415035.

📒 Files selected for processing (1)
  • frontend/micro-ui/web/public/index.html (1 hunks)
🔇 Additional comments (1)
frontend/micro-ui/web/public/index.html (1)

49-81: SPA route tracking present — good coverage of pushState/replaceState/popstate

The added SPA pageview tracking corrects the earlier gap for client-side navigations.

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