Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: setup posthog #39

Merged
merged 5 commits into from
Sep 27, 2024
Merged

feat: setup posthog #39

merged 5 commits into from
Sep 27, 2024

Conversation

rmrt1n
Copy link
Member

@rmrt1n rmrt1n commented Sep 11, 2024

closes: WORLD-1184

Overview

This PR adds PostHog to the editor for analytics.

Brief Changelog

  • Setup PostHog react sdk
  • Capture events related to personas, messages, queries, and entity groups

Testing and Verification

Manually tested and verified

Summary by CodeRabbit

  • New Features

    • Integrated PostHog analytics for enhanced user behavior tracking.
    • Added error tracking capabilities with Sentry integration.
  • Improvements

    • Enhanced application monitoring and analytics through new environment variables and dependencies.
    • Improved tracking of page views and user interactions with the addition of a beforeLoad hook.

Copy link

vercel bot commented Sep 11, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
cardinal-editor ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 25, 2024 4:30pm

Copy link

sentry-io bot commented Sep 11, 2024

🔍 Existing Issues For Review

Your pull request is modifying functions with the following pre-existing issues:

📄 File: src/components/sidebar/messages.tsx

Function Unhandled Issue
Message TypeError: wf is undefined /
Event Count: 5 Affected Users: 1
Message ReferenceError: usePostHog is not defined /
Event Count: 1 Affected Users: 1
📄 File: src/components/sidebar/persona.tsx (Click to Expand)
Function Unhandled Issue
CreatePersona ReferenceError: usePostHog is not defined /
Event Count: 1 Affected Users: 1
---

Did you find this useful? React with a 👍 or 👎

Copy link

coderabbitai bot commented Sep 11, 2024

Walkthrough

The pull request introduces enhancements to a frontend application by adding two environment variables for Sentry and PostHog, integrating the PostHog analytics library, and implementing page view tracking. These changes improve error monitoring and user interaction analytics, facilitating better insights into application performance and user behavior.

Changes

File Change Summary
.env.example Added VITE_SENTRY_DSN and VITE_POSTHOG_KEY environment variables.
package.json Added dependency for posthog-js with version ^1.161.3.
src/main.tsx Integrated PostHog analytics by adding PostHogProvider and configuring it with environment variables.
src/routes/__root.tsx Added a beforeLoad hook to capture page view events using PostHog.
.github/workflows/build.yaml Added environment variables VITE_SENTRY_DSN and VITE_POSTHOG_KEY to the build job configuration.

Possibly related PRs

  • feat: setup sentry #38: The integration of Sentry in PR feat: setup sentry #38 is directly related to the addition of the VITE_SENTRY_DSN environment variable in the main PR, as both involve enhancing error tracking capabilities within the application.

Suggested reviewers

  • zulkhair
  • smsunarto

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 73ae8f4 and 2cdcbd8.

📒 Files selected for processing (1)
  • .github/workflows/build.yaml (1 hunks)
🔇 Additional comments not posted (1)
.github/workflows/build.yaml (1)

39-41: LGTM: Environment variables added correctly

The addition of VITE_SENTRY_DSN and VITE_POSTHOG_KEY environment variables is implemented correctly and aligns with the PR objective of integrating PostHog for analytics. The use of GitHub secrets for these sensitive values is a secure practice.


🪧 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.
    • Generate unit testing code for this file.
    • 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. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • 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
Member Author

rmrt1n commented Sep 11, 2024

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @rmrt1n and the rest of your teammates on Graphite Graphite

@rmrt1n rmrt1n mentioned this pull request Sep 11, 2024
@rmrt1n rmrt1n marked this pull request as ready for review September 12, 2024 19:10
Copy link
Member

@smsunarto smsunarto left a comment

Choose a reason for hiding this comment

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

The posthog feature that we want to use is the Web Analytics (https://posthog.com/docs/web-analytics) and possibly Session Replay.

We don't need to be tracking the messages and queries actions since these are specific to user's game project and is not very useful for us.

Base automatically changed from ryan/world-1183-sentry to main September 13, 2024 14:50
Copy link

@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: 4

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between ceafc5b and 5b7c0de.

Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
Files selected for processing (4)
  • .env.example (1 hunks)
  • package.json (1 hunks)
  • src/main.tsx (2 hunks)
  • src/routes/__root.tsx (2 hunks)
Additional context used
Biome
src/main.tsx

[error] 64-64: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)

Additional comments not posted (3)
package.json (1)

32-32: Dependency added correctly.

The addition of posthog-js to the dependencies is appropriate.

src/main.tsx (1)

4-4: Import statement looks good.

The import of PostHogProvider from 'posthog-js/react' is correct.

src/routes/__root.tsx (1)

26-28: Verify that pageview events are captured correctly.

The beforeLoad hook captures a $pageview event. Ensure that this approach aligns with PostHog's best practices for Single Page Applications (SPAs), and that pageviews are being tracked as expected.

.env.example Show resolved Hide resolved
src/main.tsx Outdated Show resolved Hide resolved
src/main.tsx Show resolved Hide resolved
src/routes/__root.tsx Show resolved Hide resolved
Copy link

@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

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 0f87a34 and 73ae8f4.

Files selected for processing (1)
  • .github/workflows/build.yaml (1 hunks)
Additional comments not posted (1)
.github/workflows/build.yaml (1)

40-41: Verify that secrets are not exposed during the build process

While setting secrets as environment variables is common, ensure that none of the subsequent build steps inadvertently print these environment variables to the console or logs, which could lead to secret leakage.

Run the following script to check for any steps that might expose environment variables:

Verification successful

To ensure a comprehensive verification, we need to perform additional checks. Let's run some more specific searches to look for any potential exposures of the sensitive environment variables.


Based on our thorough analysis, we can provide a final response to the original concern.

Secrets appear to be properly managed, but verify build process

The GitHub Actions workflow is correctly using GitHub's secret management system to handle the sensitive VITE_SENTRY_DSN and VITE_POSTHOG_KEY variables. These are securely passed as environment variables to the build step. There's no evidence of explicit logging or exposure of these variables in the workflow file.

However, as an extra precaution:

  • Verify that the pnpm build script doesn't inadvertently log these environment variables.
  • Ensure that any error reporting or debug output in the build process doesn't include full environment dumps.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for commands that might print environment variables.

# Test: Look for 'env', 'printenv', or any echo commands that reference environment variables.
# Expect: No such commands should be found.

rg --type yaml --ignore-case 'run:.*\b(env|printenv)\b|echo.*\$' .github/workflows/

Length of output: 287


Script:

#!/bin/bash
# Search for direct references to VITE_SENTRY_DSN and VITE_POSTHOG_KEY in workflow files
echo "Searching for direct references to sensitive variables:"
rg --type yaml 'VITE_SENTRY_DSN|VITE_POSTHOG_KEY' .github/workflows/

# Examine build steps in build.yaml for potential risks
echo -e "\nExamining build steps in build.yaml:"
rg --type yaml '^      - name:' .github/workflows/build.yaml -A 10

Length of output: 1637

.github/workflows/build.yaml Outdated Show resolved Hide resolved
Copy link
Member

@rmrt1n Just letting you know we are good to merge this

@rmrt1n rmrt1n merged commit 8b4957c into main Sep 27, 2024
8 checks passed
@rmrt1n rmrt1n deleted the ryan/world-1184-posthog branch September 27, 2024 16:41
@coderabbitai coderabbitai bot mentioned this pull request Oct 8, 2024
1 task
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