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

chore: Prep work for adding Mixpanel session recording #36895

Merged
merged 3 commits into from
Oct 16, 2024

Conversation

hetunandu
Copy link
Member

@hetunandu hetunandu commented Oct 16, 2024

Description

Update the Appsmith config to allow for mixpanel api key that will be used for session recording

Automation

/ok-to-test tags="@tag.Sanity"

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/11360469261
Commit: bede558
Cypress dashboard.
Tags: @tag.Sanity
Spec:


Wed, 16 Oct 2024 07:52:26 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Enhanced Mixpanel analytics configuration with improved logging and event tracking capabilities.
    • Added new methods for user identification and error logging control.
  • Bug Fixes

    • Improved structure and readability of configuration files.
  • Documentation

    • Updated configuration settings for Mixpanel in the application.
  • Chores

    • Added new dependencies for Mixpanel analytics and their type definitions.

Copy link
Contributor

coderabbitai bot commented Oct 16, 2024

Walkthrough

The changes in this pull request involve updates to various files to enhance logging and analytics capabilities, particularly focusing on Mixpanel integration. The jest.config.js file has been modified to improve logging configurations, while package.json now includes new dependencies for Mixpanel. Additionally, the index.html, index.ts, and types.ts files have been updated to replace the enableMixpanel boolean with a new mixpanel object containing enabled and apiKey properties. The AnalyticsUtil class has also been enhanced with new methods for better analytics management.

Changes

File Change Summary
app/client/jest.config.js Updated logging and analytics configuration; added LOG_LEVELS and CONFIG_LOG_LEVEL_INDEX; modified mixpanel settings.
app/client/package.json Added dependencies: mixpanel-browser and @types/mixpanel-browser.
app/client/public/index.html Enhanced Mixpanel configuration; replaced enableMixpanel with mixpanel object.
app/client/src/ce/configs/index.ts Updated INJECTED_CONFIGS interface to include mixpanel object; modified related functions.
app/client/src/ce/configs/types.ts Removed enableMixpanel and added mixpanel object in AppsmithUIConfigs interface.
app/client/src/ce/utils/AnalyticsUtil.tsx Enhanced with new methods; updated global Window interface for zipy integration.

Possibly related PRs

Suggested labels

Enhancement, Task, Integrations Product, ok-to-test, Workflows Product

Suggested reviewers

  • abhvsn
  • sharat87
  • ApekshaBhosale

🌟 In the realm of code where changes flow,
Mixpanel's magic begins to grow.
With logs that sing and data that gleams,
Our app now dances in analytics dreams!
So here's to the tweaks, the updates, the flair,
A brighter future, we boldly declare! 🌈


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>, 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.

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.

@github-actions github-actions bot added the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label Oct 16, 2024
APPSMITH_FEATURE_CONFIGS?.enableMixpanel ||
false,
mixpanel: {
enabled: segment.enabled,
Copy link
Member Author

Choose a reason for hiding this comment

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

This is intentionally using segment enabled because that is how it was working before

@hetunandu hetunandu added the ok-to-test Required label for CI label Oct 16, 2024
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 and nitpick comments (2)
app/client/src/ce/configs/types.ts (1)

Line range hint 1-89: Let's tidy up our code classroom, shall we?

While the Mixpanel changes are good, I've noticed a few areas where we could improve our overall code structure:

  1. Consistency is key: Some configuration objects have an enabled property, while others don't. Let's aim for consistency across all our configurations.

  2. Breaking down a big task: Our AppsmithUIConfigs interface is quite large. Consider splitting it into smaller, more focused interfaces. This is like dividing a big project into manageable homework assignments.

  3. Grouping related items: We could group related configurations together. For example, all analytics-related configs (Mixpanel, Segment, etc.) could be in one sub-interface.

Remember, clean code is like a well-organized backpack - it makes everything easier to find and use!

Would you like some examples of how we could refactor this interface for better organization?

app/client/src/ce/utils/AnalyticsUtil.tsx (1)

Line range hint 17-24: Excellent work extending the 'Window' interface, but let's refine it further

Extending the Window interface to include the zipy object is thoughtfully implemented. However, it's advisable to place global interface augmentations in a separate .d.ts declaration file. This approach keeps the codebase organized and minimizes potential conflicts within the global namespace.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 00c16e8 and bede558.

⛔ Files ignored due to path filters (1)
  • app/client/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (6)
  • app/client/jest.config.js (2 hunks)
  • app/client/package.json (2 hunks)
  • app/client/public/index.html (1 hunks)
  • app/client/src/ce/configs/index.ts (4 hunks)
  • app/client/src/ce/configs/types.ts (1 hunks)
  • app/client/src/ce/utils/AnalyticsUtil.tsx (3 hunks)
🧰 Additional context used
🔇 Additional comments (10)
app/client/src/ce/configs/types.ts (2)

50-53: Class, pay attention to this excellent configuration update!

Well done on restructuring the Mixpanel configuration! This change from a simple boolean to an object with enabled and apiKey properties is a step in the right direction. It's like upgrading from a simple on/off switch to a more sophisticated control panel.

Let's break down why this is beneficial:

  1. It provides more flexibility in configuring Mixpanel.
  2. It aligns well with other configuration objects in the interface.
  3. It supports the PR objective of integrating Mixpanel for session recording.

Remember, students, good code structure is like a well-organized classroom - everything has its place and purpose!


50-53: Time for a pop quiz on our codebase!

Now that we've updated our Mixpanel configuration, we need to make sure the rest of our code is on the same page. Let's do a quick search to find any lingering references to the old enableMixpanel property.

Here's a little homework assignment for our codebase:

This script will help us find any places where we might need to update our code to use the new mixpanel object. Remember, thorough testing is like double-checking your homework - it helps catch any mistakes before they become problems!

✅ Verification successful

Let's tackle these hiccups together! It looks like our previous search script ran into some roadblocks. No worries—we'll adjust our approach to get things back on track.

This updated script removes the problematic --type flags and adjusts the regex to ensure proper parsing. Let's give it another go and see what we uncover!


Verification Successful: 'enableMixpanel' Removed

Great news! All instances of enableMixpanel have been successfully removed from the codebase. The new mixpanel configuration is properly implemented in the following files:

  • app/client/jest.config.js
  • app/client/public/index.html
  • app/client/src/ce/configs/index.ts
  • app/client/src/ce/configs/types.ts
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining uses of 'enableMixpanel'

echo "Searching for 'enableMixpanel' in the codebase:"
rg --type typescript --type javascript 'enableMixpanel'

echo "\nSearching for uses of the new 'mixpanel' object:"
rg --type typescript --type javascript 'mixpanel\s*:\s*{'

Length of output: 474


Script:

#!/bin/bash
# Description: Check for any remaining uses of 'enableMixpanel' without specifying file types

echo "Searching for 'enableMixpanel' in the codebase:"
rg 'enableMixpanel'

echo "\nSearching for uses of the new 'mixpanel' object:"
rg 'mixpanel\s*:\s*\{'

Length of output: 565

app/client/jest.config.js (3)

4-6: Class, let's examine these new constants.

Good morning, students! Today, we're going to learn about two new constants that have been added to our Jest configuration:

  1. LOG_LEVELS: This is an array that defines our logging levels. It's like a set of rules for how detailed our error messages should be.
  2. CONFIG_LOG_LEVEL_INDEX: This is set to 1, which means we're choosing the "error" level from our LOG_LEVELS array.

These constants will help us manage how our tests report issues. It's a great way to keep our test output organized and consistent. Well done!


105-108: Let's discuss the changes to our Mixpanel configuration, class.

Attention, everyone! We've made some exciting updates to our Mixpanel setup. Instead of a simple on/off switch, we now have a more sophisticated configuration:

  1. enabled: This tells us whether Mixpanel is turned on or off, just like before.
  2. apiKey: This is a new addition! It's like a special password that lets our application talk to Mixpanel.

This change is very important because it allows us to use Mixpanel's features, like session recording, which we'll be learning about soon. It's a big step forward in understanding how people use our application!


Line range hint 109-112: Now, let's examine how we're setting our log level.

Class, pay attention to this clever bit of code! We're using what we call a "ternary operator" to decide which log level to use. Here's how it works:

  1. First, we check if our CONFIG_LOG_LEVEL_INDEX is a valid number (greater than -1).
  2. If it is, we use that to pick a log level from our LOG_LEVELS array.
  3. If it's not valid, we default to the second item in the array, which is "error".

This is a very smart way to set our log level because it's flexible and helps prevent errors. Great job on making our code more robust!

app/client/src/ce/configs/index.ts (1)

29-32: Class, let's examine this new addition to our configuration!

I'm pleased to see this well-structured mixpanel object in our INJECTED_CONFIGS interface. It's like adding a new chapter to our configuration book, isn't it? This change allows us to not only enable or disable Mixpanel but also to specify its API key. It's a more comprehensive approach to managing our analytics tools.

Remember, students, when we enhance our interfaces like this, we're making our code more flexible and easier to manage in the future. Good job!

app/client/public/index.html (1)

246-249: ⚠️ Potential issue

Class, let's examine this new configuration carefully.

I see you've added a new mixpanel object to our configuration. That's a good step towards organizing our analytics setup. However, I have a question about line 247:

enabled: parseConfig('{{env "APPSMITH_SEGMENT_KEY"}}'),

It appears you're using the Segment key to enable Mixpanel. Is this intentional? Typically, we'd expect a boolean value or a Mixpanel-specific environment variable here. Let's discuss this in class:

  1. Should this be APPSMITH_MIXPANEL_ENABLED instead?
  2. If we're using the Segment key, can you explain the reasoning behind this choice?

Remember, clear and accurate configurations are crucial for our application's behavior. Let's ensure we're setting this up correctly.

To double-check our configuration, let's run a quick test:

This will help us understand how the Mixpanel configuration is used throughout our codebase and if there are any other Mixpanel-related environment variables we should consider.

app/client/package.json (1)

159-159: Excellent additions, class! Let's discuss why these are important.

Children, we've added two new packages to our project today:

  1. "mixpanel-browser": "^2.55.1"
  2. "@types/mixpanel-browser": "^2.50.1"

Can anyone tell me why these are significant? That's right! The first one allows us to use Mixpanel for session recording, which will help us understand how users interact with our application. The second one, class, is a TypeScript definition file. Who can tell me why that's important? Correct! It helps us maintain type safety in our TypeScript code.

Remember, using the caret (^) before the version number is like giving our package manager permission to update to newer, compatible versions. It's like when I give you permission to use colored pencils instead of regular ones - you can use them, but they still have to write words!

Also applies to: 265-265

app/client/src/ce/utils/AnalyticsUtil.tsx (2)

74-76: Well done adding the 'initializeSmartLook' method

You've correctly implemented the initializeSmartLook method, which initializes the Smartlook client with the provided ID. This enhances our analytics capabilities effectively.


369-371: Good job introducing the 'setBlockErrorLogs' method

The setBlockErrorLogs method effectively controls error logging behavior within the AnalyticsUtil class. This addition allows for better management of error events in our analytics.

Comment on lines +83 to +88
mixpanel: {
enabled: process.env.REACT_APP_SEGMENT_KEY
? process.env.REACT_APP_SEGMENT_KEY.length > 0
: false,
apiKey: process.env.REACT_APP_MIXPANEL_KEY || "",
},
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Attention, class! We have an interesting configuration setup here.

While I appreciate the effort to include Mixpanel in our configuration, I have a concern about our implementation. Can anyone spot the potential issue?

Let's break it down:

  1. We're setting enabled based on REACT_APP_SEGMENT_KEY.
  2. We're getting the apiKey from REACT_APP_MIXPANEL_KEY.

Do you see the mismatch? We're using Segment's key to enable Mixpanel. This could lead to confusion or unexpected behavior.

Here's a homework assignment for you: How could we improve this to make it more logical and less prone to errors? Think about using a dedicated environment variable for enabling Mixpanel.

Would you like to discuss a more appropriate implementation for enabling Mixpanel?

Comment on lines +170 to +173
const mixpanel = getConfig(
ENV_CONFIG.mixpanel.apiKey,
APPSMITH_FEATURE_CONFIGS?.mixpanel.apiKey,
);
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Class, let's examine how we're configuring Mixpanel in our getAppsmithConfigs function.

I see some room for improvement here. Let's analyze it together:

  1. We're correctly retrieving the Mixpanel API key (lines 170-173). Good job on that!
  2. However, in our final configuration (lines 291-294), we're setting enabled based on segment.enabled. Can anyone tell me why this might not be ideal?

Remember, Mixpanel and Segment are different analytics tools. By tying Mixpanel's enablement to Segment, we might be creating a dependency that doesn't necessarily exist.

Also, notice that we're not using the enabled property we set earlier in getConfigsFromEnvVars. We're missing an opportunity to make our configuration more flexible and accurate.

For your next assignment, I want you to think about how we can make this configuration more independent and aligned with our earlier setup. How can we ensure that Mixpanel's configuration stands on its own?

Shall we discuss a more appropriate implementation for configuring Mixpanel in this function?

Also applies to: 291-294

Copy link
Contributor

@dvj1988 dvj1988 left a comment

Choose a reason for hiding this comment

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

LGTM

@hetunandu hetunandu merged commit 6a1441f into release Oct 16, 2024
46 checks passed
@hetunandu hetunandu deleted the chore/add-mixpanel-sessions branch October 16, 2024 08:19
github-actions bot pushed a commit to Zeral-Zhang/appsmith that referenced this pull request Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ok-to-test Required label for CI skip-changelog Adding this label to a PR prevents it from being listed in the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants