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: userId in braze hyrbrid #1833

Closed
wants to merge 2 commits into from
Closed

fix: userId in braze hyrbrid #1833

wants to merge 2 commits into from

Conversation

aashishmalik
Copy link
Contributor

@aashishmalik aashishmalik commented Aug 22, 2024

PR Description

Please include a summary of the change along with the relevant motivation and context.

Linear task (optional)

Linear task link

Cross Browser Tests

Please confirm you have tested for the following browsers:

  • Chrome
  • Firefox
  • IE11

Sanity Suite

  • All sanity suite test cases pass locally

Security

  • The code changed/added as part of this pull request won't create any security issues with how the software is being used.

Summary by CodeRabbit

  • New Features
    • Enhanced user identification process in hybrid mode by ensuring the changeUser method is called during identification.
  • Tests
    • Updated test cases to reflect the new expected behavior of the Braze API during user identification.

@aashishmalik aashishmalik requested a review from a team August 22, 2024 10:52
Copy link
Contributor

coderabbitai bot commented Aug 22, 2024

Walkthrough

Walkthrough

The changes involve modifications to the identify method in the Braze class within browser.js, specifically adding a call to window.braze.changeUser(userId) when hybrid mode is enabled. This alters the user identification process to ensure that the changeUser method is triggered during identification in hybrid mode. Corresponding test cases in browser.test.js were updated to reflect this new expectation, confirming that changeUser is called once during the identify operation.

Changes

Files Change Summary
packages/analytics-js-integrations/src/integrations/Braze/browser.js, packages/analytics-js-integrations/tests/integrations/Braze/browser.test.js Updated the identify method to directly call window.braze.changeUser(userId) when hybrid mode is enabled. Adjusted the test to expect that changeUser is called exactly once during the identify process.

Suggested reviewers

  • aashishmalik
  • yashasvibajpai

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 generate interesting stats about this repository and render them as a table.
    -- @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.

Tip

Early access features: enabled

We are currently testing the following features in early access:

  • OpenAI o1 for code reviews: OpenAI's new o1 model is being tested for code reviews. This model has advanced reasoning capabilities and can provide more nuanced feedback on your code.

Note:

  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.

@aashishmalik aashishmalik requested a review from utsabc August 22, 2024 10:53
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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 025306e and 65b177f.

Files selected for processing (1)
  • packages/analytics-js-integrations/src/integrations/Braze/browser.js (1 hunks)
Additional comments not posted (1)
packages/analytics-js-integrations/src/integrations/Braze/browser.js (1)

113-117: LGTM! But verify the impact of changes on the codebase.

The addition of the conditional check for isHybridModeEnabled and early return is a logical improvement. The removal of redundant variable declarations enhances code clarity.

However, ensure that this change does not affect other parts of the codebase that rely on the identify method's behavior.

Run the following script to verify the usage of the identify method:

coderabbitai[bot]
coderabbitai bot previously approved these changes Aug 22, 2024
Copy link

github-actions bot commented Aug 22, 2024

size-limit report 📦

Name Size (Base) Size (Current) Size Limit Status
Cookies Utils - Legacy - NPM (ESM) 1.54 KB 1.54 KB (0%) 2 KB
Cookies Utils - Legacy - NPM (CJS) 1.75 KB 1.75 KB (0%) 2 KB
Cookies Utils - Legacy - NPM (UMD) 1.53 KB 1.53 KB (0%) 2 KB
Cookies Utils - Modern - NPM (ESM) 1.17 KB 1.17 KB (0%) 1.5 KB
Cookies Utils - Modern - NPM (CJS) 1.4 KB 1.4 KB (0%) 1.5 KB
Cookies Utils - Modern - NPM (UMD) 1.16 KB 1.16 KB (0%) 1.5 KB
Plugins Module Federation Mapping - Legacy - CDN 332 B 332 B (0%) 512 B
Plugins - Legacy - CDN 15.96 KB 15.96 KB (0%) 16 KB
Plugins Module Federation Mapping - Modern - CDN 331 B 331 B (0%) 512 B
Plugins - Modern - CDN 7.19 KB 7.19 KB (0%) 7.5 KB
Common - No bundling 16.2 KB 16.2 KB (0%) 16.5 KB
Service Worker - Legacy - NPM (ESM) 30.42 KB 30.42 KB (0%) 31 KB
Service Worker - Legacy - NPM (CJS) 30.64 KB 30.64 KB (0%) 31 KB
Service Worker - Legacy - NPM (UMD) 30.42 KB 30.42 KB (0%) 31 KB
Service Worker - Modern - NPM (ESM) 25.49 KB 25.49 KB (0%) 26 KB
Service Worker - Modern - NPM (CJS) 25.76 KB 25.76 KB (0%) 26 KB
Service Worker - Modern - NPM (UMD) 25.5 KB 25.5 KB (0%) 26 KB
Core (v1.1) - NPM (ESM) 30 KB 30 KB (0%) 32 KB
Core (v1.1) - NPM (CJS) 30.14 KB 30.14 KB (0%) 32 KB
Core (v1.1) - NPM (UMD) 30.09 KB 30.09 KB (0%) 32 KB
Core (Content Script - v1.1) - NPM (ESM) 29.58 KB 29.58 KB (0%) 30 KB
Core (Content Script - v1.1) - NPM (CJS) 29.7 KB 29.7 KB (0%) 30 KB
Core (Content Script - v1.1) - NPM (UMD) 29.64 KB 29.64 KB (0%) 30 KB
Core - Legacy - CDN 47.63 KB 47.63 KB (0%) 48 KB
Core - Modern - CDN 24.23 KB 24.23 KB (0%) 24.5 KB
Load Snippet 718 B 718 B (0%) 1 KB
Core - Legacy - NPM (ESM) 47.49 KB 47.49 KB (0%) 48 KB
Core - Legacy - NPM (CJS) 47.71 KB 47.71 KB (0%) 48 KB
Core - Legacy - NPM (UMD) 47.48 KB 47.48 KB (0%) 48 KB
Core - Modern - NPM (ESM) 23.99 KB 23.99 KB (0%) 24.5 KB
Core - Modern - NPM (CJS) 24.21 KB 24.21 KB (0%) 24.5 KB
Core - Modern - NPM (UMD) 24.02 KB 24.02 KB (0%) 24.5 KB
Core (Bundled) - Legacy - NPM (ESM) 47.49 KB 47.49 KB (0%) 48 KB
Core (Bundled) - Legacy - NPM (CJS) 47.7 KB 47.7 KB (0%) 48 KB
Core (Bundled) - Legacy - NPM (UMD) 47.48 KB 47.48 KB (0%) 48 KB
Core (Bundled) - Modern - NPM (ESM) 38.76 KB 38.76 KB (0%) 39 KB
Core (Bundled) - Modern - NPM (CJS) 38.93 KB 38.93 KB (0%) 39 KB
Core (Bundled) - Modern - NPM (UMD) 38.75 KB 38.75 KB (0%) 39 KB
Core (Content Script) - Legacy - NPM (ESM) 46.95 KB 46.95 KB (0%) 48 KB
Core (Content Script) - Legacy - NPM (CJS) 47.19 KB 47.19 KB (0%) 47.5 KB
Core (Content Script) - Legacy - NPM (UMD) 47.01 KB 47.01 KB (0%) 47.5 KB
Core (Content Script) - Modern - NPM (ESM) 38.17 KB 38.17 KB (0%) 38.5 KB
Core (Content Script) - Modern - NPM (CJS) 38.41 KB 38.41 KB (0%) 38.5 KB
Core (Content Script) - Modern - NPM (UMD) 38.25 KB 38.25 KB (0%) 38.5 KB
All Integrations - Legacy - CDN 94.36 KB 94.42 KB (+0.07% ▲) 95.3 KB
All Integrations - Modern - CDN 89.53 KB 89.51 KB (-0.02% ▼) 91 KB

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 65b177f and 2037e66.

Files selected for processing (1)
  • packages/analytics-js-integrations/tests/integrations/Braze/browser.test.js (2 hunks)
Additional comments not posted (1)
packages/analytics-js-integrations/__tests__/integrations/Braze/browser.test.js (1)

Line range hint 1086-1121: Verify the correctness of the changeUser method call expectation.

The test case now expects the changeUser method to be called once during the identify call in hybrid mode. Ensure that this change aligns with the intended functionality and does not introduce regressions.

Run the following script to verify the implementation of the identify method in the Braze class:

Verification successful

Verification Successful: changeUser Method Call in Hybrid Mode

The identify method in the Braze class correctly calls window.braze.changeUser(userId) when isHybridModeEnabled is true, matching the test case expectation of a single call during the identify process in hybrid mode. This confirms that the test case is aligned with the intended functionality.

  • The identify method implementation correctly handles the changeUser call in hybrid mode.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of the `identify` method in the Braze class.

# Test: Search for the `identify` method implementation. Expect: Correct handling of `changeUser` call.
ast-grep --lang javascript --pattern $'class Braze {
  $$$
  identify($_) {
    $$$
  }
  $$$  
}'

Length of output: 31882

coderabbitai[bot]
coderabbitai bot previously approved these changes Aug 22, 2024
Copy link

codecov bot commented Aug 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 57.11%. Comparing base (7584eb2) to head (df1968d).
Report is 21 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #1833   +/-   ##
========================================
  Coverage    57.11%   57.11%           
========================================
  Files          476      476           
  Lines        16228    16229    +1     
  Branches      3250     3245    -5     
========================================
+ Hits          9269     9270    +1     
- Misses        5715     5731   +16     
+ Partials      1244     1228   -16     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2037e66 and 95868ca.

Files selected for processing (1)
  • packages/analytics-js-integrations/tests/integrations/Braze/browser.test.js (2 hunks)
Additional comments not posted (1)
packages/analytics-js-integrations/__tests__/integrations/Braze/browser.test.js (1)

Line range hint 1086-1121: LGTM!

The test case correctly verifies that changeUser is called exactly once during an identify call in hybrid mode.

The code changes are approved.

@aashishmalik aashishmalik deleted the fix.braze-push branch August 27, 2024 05:15
@aashishmalik aashishmalik restored the fix.braze-push branch September 18, 2024 05:03
@aashishmalik aashishmalik reopened this Sep 18, 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

Outside diff range and nitpick comments (1)
packages/analytics-js-integrations/__tests__/integrations/Braze/browser.test.js (1)

Line range hint 1086-1121: Test case uses incorrect message type for identify method.

In the test for the identify method in hybrid mode, the rudderElement message includes type: 'page' and properties for a page event, which are not appropriate for testing the identify method. This may lead to misleading test results. Please update the rudderElement to reflect an identify call.

Apply this diff to correct the test data:

        // Create a mock rudderElement with necessary properties
        const rudderElement = {
          message: {
            userId: 'user123',
-           type: 'page',
-           name: 'Home',
-           properties: {
-             title: 'Home | RudderStack',
-             url: 'http://www.rudderstack.com',
-           },
+           type: 'identify',
+           context: {
+             traits: {
+               email: '[email protected]',
+               firstName: 'John',
+               lastName: 'Doe',
+             },
+           },
          },
        };
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 95868ca and df1968d.

Files selected for processing (2)
  • packages/analytics-js-integrations/tests/integrations/Braze/browser.test.js (2 hunks)
  • packages/analytics-js-integrations/src/integrations/Braze/browser.js (1 hunks)

Comment on lines +113 to +117
const { message } = rudderElement;
const { userId } = message;

if (this.isHybridModeEnabled) {
window.braze.changeUser(userId);
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure userId is defined before calling window.braze.changeUser.

In hybrid mode, the code calls window.braze.changeUser(userId) without checking if userId is defined. If userId is undefined or empty, this could cause an error or unexpected behavior. Consider adding a check to ensure userId is a non-empty string before calling changeUser.

Apply this diff to add the check:

        const { message } = rudderElement;
        const { userId } = message;

        if (this.isHybridModeEnabled) {
+          if (userId) {
            window.braze.changeUser(userId);
+          } else {
+            logger.error('User ID is undefined or empty in hybrid mode');
+          }
          return;
        }
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
const { message } = rudderElement;
const { userId } = message;
if (this.isHybridModeEnabled) {
window.braze.changeUser(userId);
const { message } = rudderElement;
const { userId } = message;
if (this.isHybridModeEnabled) {
if (userId) {
window.braze.changeUser(userId);
} else {
logger.error('User ID is undefined or empty in hybrid mode');
}
return;
}

Copy link

@github-actions github-actions bot deleted the fix.braze-push branch November 19, 2024 00:24
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.

1 participant