Skip to content

Add Scarf analytics for documentation page view tracking#50

Merged
azaddhirajkumar merged 1 commit intomainfrom
add-scarf-analytics
Mar 9, 2026
Merged

Add Scarf analytics for documentation page view tracking#50
azaddhirajkumar merged 1 commit intomainfrom
add-scarf-analytics

Conversation

@azaddhirajkumar
Copy link
Copy Markdown
Contributor

@azaddhirajkumar azaddhirajkumar commented Mar 9, 2026

Integrates Scarf pixel tracking. Uses a Docusaurus client module with the onRouteDidUpdate lifecycle hook to fire the tracking pixel on every page view, including SPA client-side navigations.

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces Scarf analytics to the Docusaurus documentation site. The primary goal is to enable robust page view tracking, specifically designed to handle the single-page application (SPA) nature of Docusaurus. By adding a new client module, the system now ensures that every page navigation, whether an initial load or an in-app route change, is accurately recorded, providing comprehensive usage data.

Highlights

  • Scarf Analytics Integration: Integrated Scarf pixel tracking into the Docusaurus site to monitor page views.
  • SPA-Aware Tracking: Implemented a client module that ensures accurate tracking for single-page application (SPA) navigations, firing a pixel on initial load and subsequent route updates.
  • Docusaurus Configuration Update: Configured Docusaurus to load the new Scarf analytics client module.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • docusaurus.config.js
    • Added 'clientModules' entry to include the new Scarf analytics script.
  • src/clientModules/scarfAnalytics.js
    • Created a new JavaScript file containing the Scarf pixel implementation.
    • Defined 'PIXEL_ID' for Scarf tracking.
    • Implemented 'sendScarfPing' function to send tracking requests.
    • Added 'onRouteDidUpdate' Docusaurus lifecycle hook to trigger tracking on route changes.
    • Included logic to deduplicate pings for the same URL.
Activity
  • No human activity recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds Scarf analytics for tracking page views. The implementation is mostly correct, but I've suggested a couple of improvements for better maintainability and to ensure analytics are only active in the production environment. Specifically, I recommended using an environment variable for the PIXEL_ID instead of hardcoding it, and adding a check to only send tracking pings in production.

// in-app navigation so that each page view is recorded, even in a SPA where
// the full page is never reloaded.

const PIXEL_ID = '5ff443aa-dd19-43ab-9c9e-ad26252d0fb0';
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Hardcoding the PIXEL_ID can make it difficult to manage for different environments (e.g., development, staging, production) or if it needs to be updated. It's better to use an environment variable. Docusaurus supports this by prefixing environment variables with DOCUSAURUS_. You will need to set DOCUSAURUS_SCARF_PIXEL_ID in your build environment.

Suggested change
const PIXEL_ID = '5ff443aa-dd19-43ab-9c9e-ad26252d0fb0';
const PIXEL_ID = process.env.DOCUSAURUS_SCARF_PIXEL_ID;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The pixel ID is not a secret — it's sent to the browser as a visible query parameter on every page view. There's also only one environment (production). Hardcoding keeps it simple and avoids a silent failure if the env var is missing.

Comment on lines +22 to +24
export function onRouteDidUpdate() {
sendScarfPing();
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

It's good practice to only enable analytics in the production environment to avoid sending tracking events during local development. You should also check if the PIXEL_ID is configured before attempting to send a ping. This can be done by checking process.env.NODE_ENV and the PIXEL_ID variable (which should be loaded from an environment variable as per my other comment).

Suggested change
export function onRouteDidUpdate() {
sendScarfPing();
}
export function onRouteDidUpdate() {
if (process.env.NODE_ENV === 'production' && PIXEL_ID) {
sendScarfPing();
}
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

onRouteDidUpdate only runs client-side, so this would only affect local dev. The few localhost pings during development are negligible noise compared to real traffic. Keeping it simple for now — happy to add a NODE_ENV check if the team prefers it.

@azaddhirajkumar azaddhirajkumar changed the title Added changes for scarf pixel Add Scarf analytics for documentation page view tracking Mar 9, 2026
@azaddhirajkumar azaddhirajkumar merged commit 758952f into main Mar 9, 2026
4 checks passed
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