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

fix(analytics): segment not passing context to mixpanel #5662

Merged
merged 2 commits into from
Jul 17, 2024
Merged

Conversation

kyranjamie
Copy link
Collaborator

@kyranjamie kyranjamie commented Jul 17, 2024

Try out Leather build 5c6b463Extension build, Test report, Storybook, Chromatic

In some earlier changes, I refactored Analytics such that there's a single mechanism to track events.

Segment's analytics library has two concepts:

Properties: Describe the event details specific to the occurrence.
Context: Provides metadata about the overall environment and situation in which the event occurred.

I followed these concepts, tracking global metadata such as the app version number as general event context. However, it appears this doesn't enter Mixpanel in the way expected, meaning events appear without the properties they had before.

As this negatively impacts our dashboard, I've changed this to be reported as properties, not context.

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced analytics event logging by setting the ip to '0.0.0.0' and ensuring properties are initialized correctly.
  • Refactor

    • Streamlined the initialization of QueryClient by removing unnecessary queryCache configuration.

Copy link

coderabbitai bot commented Jul 17, 2024

Walkthrough

The updates involve two main changes. First, the decorateAnalyticsEventsWithContext function in the analytics.ts file has been enhanced to add IP masking and ensure the presence of a properties object. Second, in the persistence.ts file, the QueryClient initialization has been streamlined by removing the QueryCache configuration and its related import, simplifying the setup.

Changes

File Path Change Summary
src/shared/utils/analytics.ts Modified decorateAnalyticsEventsWithContext to set ip to '0.0.0.0' and ensure a properties object.
src/app/common/persistence.ts Removed QueryCache import from @tanstack/react-query and updated QueryClient initialization.

Sequence Diagram(s)

No sequence diagrams are necessary for these changes since they primarily involve minor enhancements and cleanup of existing functionality rather than introducing new features or altering control flows.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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

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

Commits

Files that changed from the base of the PR and between 98beec5 and 0c3c6f5.

Files selected for processing (1)
  • src/shared/utils/analytics.ts (1 hunks)

Comment on lines +33 to +35
payload.obj.context.ip = '0.0.0.0';
payload.obj.properties = payload.obj.properties || {};
payload.obj.properties[key] = value;
Copy link

Choose a reason for hiding this comment

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

Consider privacy implications and potential data overwriting.

Setting the IP address to '0.0.0.0' might be intended to anonymize users, but it's important to document why this specific value is used to avoid confusion. Additionally, directly modifying payload.obj.properties might overwrite existing properties. Consider merging properties instead of assigning them directly to ensure data integrity.

- payload.obj.properties[key] = value;
+ payload.obj.properties = { ...payload.obj.properties, [key]: value };
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
payload.obj.context.ip = '0.0.0.0';
payload.obj.properties = payload.obj.properties || {};
payload.obj.properties[key] = value;
payload.obj.context.ip = '0.0.0.0';
payload.obj.properties = payload.obj.properties || {};
payload.obj.properties = { ...payload.obj.properties, [key]: value };

@markmhendrickson
Copy link
Collaborator

Are events currently getting reported to Segment aka Mixpanel without any properties at all? Or just some missing?

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0c3c6f5 and 5c6b463.

Files selected for processing (1)
  • src/app/common/persistence.ts (2 hunks)
Additional comments not posted (2)
src/app/common/persistence.ts (2)

20-20: Assess the impact of removing queryCache configuration.

The removal of queryCache configuration from queryClient initialization simplifies the setup. However, verify that all functionalities previously handled by queryCache, especially error handling, are still effectively managed.


2-2: Verify the removal of QueryCache.

The removal of QueryCache from imports suggests it's no longer used. Ensure that there are no lingering references to QueryCache elsewhere in the codebase that could lead to runtime errors.

Verification successful

Verified the removal of QueryCache.

The QueryCache is no longer referenced in the codebase, ensuring that its removal from the imports does not lead to any runtime errors.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that there are no references to `QueryCache` in the codebase.

# Test: Search for `QueryCache` usage. Expect: No occurrences.
rg --type python 'QueryCache'

Length of output: 60


Script:

#!/bin/bash
# Description: Verify that there are no references to `QueryCache` in the codebase.

# Test: Search for `QueryCache` usage. Expect: No occurrences.
rg --type ts 'QueryCache'

Length of output: 69


Script:

#!/bin/bash
# Description: Inspect the usage of `QueryCache` in `src/app/debug.ts`.

# Test: Show lines around the reference to `QueryCache` for context.
rg --type ts 'QueryCache' -A 5 -B 5 src/app/debug.ts

Length of output: 363


Script:

#!/bin/bash
# Description: Inspect the usage of `QueryCache` within the `clearReactQueryCache` function in `src/app/debug.ts`.

# Test: Search for `QueryCache` within the `clearReactQueryCache` function.
rg 'clearReactQueryCache' -A 10 src/app/debug.ts | rg 'QueryCache'

Length of output: 91

@kyranjamie kyranjamie added this pull request to the merge queue Jul 17, 2024
Merged via the queue into dev with commit f3de110 Jul 17, 2024
30 checks passed
@kyranjamie kyranjamie deleted the fix/analytics branch July 17, 2024 14:00
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