Add Scarf analytics for documentation page view tracking#50
Add Scarf analytics for documentation page view tracking#50azaddhirajkumar merged 1 commit intomainfrom
Conversation
Summary of ChangesHello, 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
🧠 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
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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.
| const PIXEL_ID = '5ff443aa-dd19-43ab-9c9e-ad26252d0fb0'; | |
| const PIXEL_ID = process.env.DOCUSAURUS_SCARF_PIXEL_ID; |
There was a problem hiding this comment.
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.
| export function onRouteDidUpdate() { | ||
| sendScarfPing(); | ||
| } |
There was a problem hiding this comment.
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).
| export function onRouteDidUpdate() { | |
| sendScarfPing(); | |
| } | |
| export function onRouteDidUpdate() { | |
| if (process.env.NODE_ENV === 'production' && PIXEL_ID) { | |
| sendScarfPing(); | |
| } | |
| } |
There was a problem hiding this comment.
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.
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.