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 identify user not called correctly #37303

Merged
merged 2 commits into from
Nov 11, 2024

Conversation

hetunandu
Copy link
Member

@hetunandu hetunandu commented Nov 8, 2024

Description

Update the call sequence during init to solve for analytics issue. It was found that the identifyUser in analytics was not called properly when in edit mode. This change will fix the call sequence. It also ensures that the init of analytics is not a blocker by forking out the call into a different generator function

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/11742239861
Commit: 984e325
Cypress dashboard.
Tags: @tag.Sanity
Spec:


Fri, 08 Nov 2024 13:16:33 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Enhanced analytics tracking capabilities by integrating user identification into the analytics setup process.
    • Simplified the initialization of analytics trackers for improved performance.
  • Bug Fixes

    • Improved error handling for analytics initialization and user tracking.
  • Documentation

    • Updated comments for clarity regarding the new analytics tracking logic.

Copy link
Contributor

coderabbitai bot commented Nov 8, 2024

Walkthrough

The changes in this pull request involve updates to the userSagas.tsx and AppsmithUtils.tsx files. The initTrackers function replaces the previous intializeSmartLook function, focusing on initializing Sentry analytics and trackers. Additionally, the initializeAnalyticsAndTrackers function is modified to accept a currentUser parameter, enhancing user tracking capabilities. These modifications streamline analytics initialization and improve error handling while maintaining the overall control flow.

Changes

File Path Change Summary
app/client/src/ce/sagas/userSagas.tsx - Renamed intializeSmartLook to initTrackers and updated its implementation for Sentry tracking.
- Updated runUserSideEffectsSaga to call initTrackers.
- Removed ANONYMOUS_USERNAME import.
app/client/src/utils/AppsmithUtils.tsx - Updated initializeAnalyticsAndTrackers to accept currentUser parameter and added user tracking logic.

Possibly related PRs

  • chore: span push and sentry logs #36682: This PR modifies the userSagas.tsx file, enhancing error handling with Sentry, which is relevant to the changes made in the main PR that also involves Sentry integration in the userSagas.tsx file.
  • chore: ce changes decoupled mixpannel chunk #36979: This PR introduces a new function intializeSmartLook in userSagas.tsx for user identification in analytics, which directly relates to the changes in the main PR where the initTrackers function is introduced for similar purposes.

Suggested labels

Datasources, High, Query & JS Pod

Suggested reviewers

  • ankitakinger

🎉 In the world of code, changes take flight,
initTrackers shines, making analytics bright.
With user insights now in the mix,
Error handling smooth, no more tricks!
A saga reborn, with Sentry's embrace,
In the realm of tracking, we’ve found our place! 🚀

Warning

Tool Failures:

Tool Failure Count:


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.

@hetunandu hetunandu requested a review from vsvamsi1 November 8, 2024 12:31
@github-actions github-actions bot added the Bug Something isn't working label Nov 8, 2024
@hetunandu hetunandu added the ok-to-test Required label for CI label Nov 8, 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: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 806c710 and 984e325.

📒 Files selected for processing (2)
  • app/client/src/ce/sagas/userSagas.tsx (2 hunks)
  • app/client/src/utils/AppsmithUtils.tsx (2 hunks)
🔇 Additional comments (5)
app/client/src/utils/AppsmithUtils.tsx (3)

16-17: LGTM: Required imports added correctly

The new imports for User type and ANONYMOUS_USERNAME constant are properly placed and necessary for the enhanced user identification functionality.


112-114: LGTM: User identification logic is well implemented

The implementation correctly:

  • Filters out anonymous users using both isAnonymous flag and username check
  • Uses proper async/await pattern
  • Is placed appropriately after analytics initialization

19-19: Verify all callers are updated with the new parameter

The function signature change is a breaking change that requires updates to all calling code.

Let's verify all callers are updated:

✅ Verification successful

Function signature change is properly handled

The only caller of initializeAnalyticsAndTrackers in app/client/src/ce/sagas/userSagas.tsx correctly passes the currentUser parameter, which is available in the enclosing initTrackers function. No issues found.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for all calls to initializeAnalyticsAndTrackers
rg "initializeAnalyticsAndTrackers\(" --type ts --type tsx

Length of output: 88


Script:

#!/bin/bash
# Search for all calls to initializeAnalyticsAndTrackers using ripgrep without file type filters
rg "initializeAnalyticsAndTrackers\("

# Also search for the function definition to understand its location and usage
rg "export const initializeAnalyticsAndTrackers"

Length of output: 316


Script:

#!/bin/bash
# Let's check the context of the caller to verify if it's passing the currentUser parameter correctly
rg "initializeAnalyticsAndTrackers\(" -B 5 -A 5

Length of output: 755

app/client/src/ce/sagas/userSagas.tsx (2)

210-210: LGTM! Correct usage of fork for non-blocking analytics initialization.

The change properly ensures analytics initialization doesn't block the main flow.


Line range hint 192-210: Verify complete removal of SmartLook initialization.

Let's ensure there are no remaining references to the old analytics initialization.

Comment on lines +192 to 201
function* initTrackers(currentUser: User) {
const initializeSentry = initializeAnalyticsAndTrackers(currentUser);

const sentryInitialized: boolean = yield initializeSentry;

if (sentryInitialized) {
yield put(segmentInitSuccess());
} else {
yield put(segmentInitUncertain());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add error handling and improve type safety.

The function should handle potential initialization errors and have proper type checking:

-function* initTrackers(currentUser: User) {
+function* initTrackers(currentUser: User) {
+  try {
     const initializeSentry = initializeAnalyticsAndTrackers(currentUser);
-    const sentryInitialized: boolean = yield initializeSentry;
+    const sentryInitialized: boolean = yield Promise.resolve(initializeSentry);
 
     if (sentryInitialized) {
       yield put(segmentInitSuccess());
     } else {
       yield put(segmentInitUncertain());
     }
+  } catch (error) {
+    yield put(segmentInitUncertain());
+    Sentry.captureException("Analytics initialization failed", {
+      level: Severity.Error,
+      extra: { error },
+    });
+  }
 }

Also, consider renaming the function to better reflect its responsibility (e.g., initSentryAnalytics).

Committable suggestion skipped: line range outside the PR's diff.

@hetunandu hetunandu enabled auto-merge (squash) November 8, 2024 12:47
@hetunandu hetunandu disabled auto-merge November 8, 2024 13:05
@hetunandu hetunandu requested a review from dvj1988 November 8, 2024 13:05
@hetunandu hetunandu merged commit ec1d737 into release Nov 11, 2024
50 checks passed
@hetunandu hetunandu deleted the fix/mixpanel-identify-not-called branch November 11, 2024 05:17
hetunandu added a commit that referenced this pull request Nov 12, 2024
## Description

Fix the bug where return was called before the await for cloud
conditions. This made the identifyUser case being skipped almost always


Missed in #37303


## Automation

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

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!IMPORTANT]
> 🟣 🟣 🟣 Your tests are running.
> Tests running at:
<https://github.com/appsmithorg/appsmith/actions/runs/11791461362>
> Commit: 94bc989
> Workflow: `PR Automation test suite`
> Tags: `@tag.Sanity`
> Spec: ``
> <hr>Tue, 12 Nov 2024 05:44:55 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- Enhanced analytics initialization process to ensure completion before
user identification.
  
- **Bug Fixes**
	- Improved error handling for analytics setup with Sentry logging.

- **Documentation**
	- Updated function signatures for clarity and consistency.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
@coderabbitai coderabbitai bot mentioned this pull request Nov 14, 2024
2 tasks
github-actions bot pushed a commit to Zeral-Zhang/appsmith that referenced this pull request Nov 20, 2024
## Description

Update the call sequence during init to solve for analytics issue. It
was found that the `identifyUser` in analytics was not called properly
when in edit mode. This change will fix the call sequence. It also
ensures that the init of analytics is not a blocker by forking out the
call into a different generator function

## Automation

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

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/11742239861>
> Commit: 984e325
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=11742239861&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Sanity`
> Spec:
> <hr>Fri, 08 Nov 2024 13:16:33 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [x] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- Enhanced analytics tracking capabilities by integrating user
identification into the analytics setup process.
- Simplified the initialization of analytics trackers for improved
performance.

- **Bug Fixes**
- Improved error handling for analytics initialization and user
tracking.

- **Documentation**
- Updated comments for clarity regarding the new analytics tracking
logic.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
github-actions bot pushed a commit to Zeral-Zhang/appsmith that referenced this pull request Nov 20, 2024
## Description

Fix the bug where return was called before the await for cloud
conditions. This made the identifyUser case being skipped almost always


Missed in appsmithorg#37303


## Automation

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

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!IMPORTANT]
> 🟣 🟣 🟣 Your tests are running.
> Tests running at:
<https://github.com/appsmithorg/appsmith/actions/runs/11791461362>
> Commit: 94bc989
> Workflow: `PR Automation test suite`
> Tags: `@tag.Sanity`
> Spec: ``
> <hr>Tue, 12 Nov 2024 05:44:55 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- Enhanced analytics initialization process to ensure completion before
user identification.
  
- **Bug Fixes**
	- Improved error handling for analytics setup with Sentry logging.

- **Documentation**
	- Updated function signatures for clarity and consistency.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
@coderabbitai coderabbitai bot mentioned this pull request Dec 13, 2024
2 tasks
@coderabbitai coderabbitai bot mentioned this pull request Jan 9, 2025
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working ok-to-test Required label for CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants