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: gainsight PX destination #1852

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

gs-nwolfe
Copy link

@gs-nwolfe gs-nwolfe commented Sep 16, 2024

PR Description

The intention is to allow customers to load the Gainsight PX javascript SDK in the browser and send events directly to Gainsight PX from the client side. This new integration will likely be used more than the existing home-grown Gainsight PX integration that uses the REST API to send events from server-to-server.

To avoid conflicts with the existing Gainsight PX integration, I used the name of "GAINSIGHT_PX_BROWSER".
There are corresponding PR's to the rudder-integrations-config and docs repos.
Docs: rudderlabs/rudderstack-docs#1193
UI: rudderlabs/rudder-integrations-config#1684

NOTE: I have not tested this in concert with the rudder-integrations-config change, so I am not sure about the "extraConfig" config field. In the integrations-config code, I marked it as type:"textareaInput" and subType: "JSON", and in the sdk-js code, I consumed that as a string. If it will come in as a javascript object instead, then I should change the code. Let me know how that subtype works. (or if that is not even a valid choice, let me know, I can get rid of the subType)

Linear task (optional)

n/a

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

    • Introduced the Gainsight PX integration, enabling enhanced analytics capabilities.
    • Added support for user identification, grouping, and event tracking within the Gainsight PX platform.
    • Expanded mapping for client identifiers and configuration keys to include Gainsight PX.
    • Centralized export structure for easier access to Gainsight PX functionalities.
  • Bug Fixes

    • Improved consistency in naming conventions across the integration mappings.
  • Documentation

    • Updated documentation to reflect the new Gainsight PX integration and its functionalities.

@contributor-support
Copy link

Thank you for contributing this PR.
Please sign the Contributor License Agreement (CLA) before merging.

Copy link
Contributor

coderabbitai bot commented Sep 16, 2024

Walkthrough

Walkthrough

The pull request introduces the Gainsight PX integration by adding various constants, mappings, and a new class to facilitate user and event tracking. It includes the definition of essential constants in the constants.ts file, updates to client-server mappings, and enhancements to the integration's functionality through the creation of a dedicated GainsightPX class. Additionally, it establishes a mechanism for loading the Gainsight PX native SDK dynamically. These changes collectively expand the analytics framework's integration capabilities.

Changes

File Path Change Summary
packages/analytics-js-common/src/constants/integrations/GainsightPX/constants.ts Added constants for directory name, name, display name, and mappings related to the Gainsight PX integration.
packages/analytics-js-common/src/constants/integrations/client_server_name.js Added mapping for the client identifier GAINSIGHT_PX_BROWSER to the server name GainsightPX.
packages/analytics-js-common/src/constants/integrations/config_to_integration_names.js Added mapping for the configuration key GAINSIGHT_PX_BROWSER to the integration name GainsightPX.
packages/analytics-js-common/src/constants/integrations/destDisplayNamesToFileNamesMap.ts Added mappings for GainsightPXDisplayName and GainsightPXDirectoryName.
packages/analytics-js-common/src/constants/integrations/destinationNames.ts Added exports for GainsightPXDisplayName and GainsightPXDirectoryName.
packages/analytics-js-common/src/constants/integrations/integration_cname.js Added integration mapping for GainsightPX in the commonNames object.
packages/analytics-js-integrations/src/integrations/GainsightPX/browser.js Introduced GainsightPX class with methods for initialization, user identification, grouping, and event tracking.
packages/analytics-js-integrations/src/integrations/GainsightPX/index.js Added module export for the GainsightPX class from the browser file.
packages/analytics-js-integrations/src/integrations/GainsightPX/nativeSdkLoader.js Implemented loadNativeSdk function to dynamically load the Gainsight PX SDK.
packages/analytics-js-integrations/src/integrations/index.js Added GainsightPX integration to the main integrations object.

Possibly related PRs


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.

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

Outside diff range and nitpick comments (1)
packages/analytics-js-integrations/src/integrations/GainsightPX/browser.js (1)

51-51: Consider using an optional chain.

The current code uses a logical AND operator && to check for the presence of the window.aptrinsic object and its init property. Consider using an optional chain ?. instead for a more concise and safer check.

-return !!(window.aptrinsic && window.aptrinsic.init);
+return !!window.aptrinsic?.init;
Tools
Biome

[error] 51-51: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7584eb2 and 9b89b33.

Files selected for processing (10)
  • packages/analytics-js-common/src/constants/integrations/GainsightPX/constants.ts (1 hunks)
  • packages/analytics-js-common/src/constants/integrations/client_server_name.js (1 hunks)
  • packages/analytics-js-common/src/constants/integrations/config_to_integration_names.js (1 hunks)
  • packages/analytics-js-common/src/constants/integrations/destDisplayNamesToFileNamesMap.ts (2 hunks)
  • packages/analytics-js-common/src/constants/integrations/destinationNames.ts (1 hunks)
  • packages/analytics-js-common/src/constants/integrations/integration_cname.js (2 hunks)
  • packages/analytics-js-integrations/src/integrations/GainsightPX/browser.js (1 hunks)
  • packages/analytics-js-integrations/src/integrations/GainsightPX/index.js (1 hunks)
  • packages/analytics-js-integrations/src/integrations/GainsightPX/nativeSdkLoader.js (1 hunks)
  • packages/analytics-js-integrations/src/integrations/index.js (2 hunks)
Files skipped from review due to trivial changes (1)
  • packages/analytics-js-integrations/src/integrations/GainsightPX/index.js
Additional context used
Biome
packages/analytics-js-integrations/src/integrations/GainsightPX/nativeSdkLoader.js

[error] 29-29: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

packages/analytics-js-integrations/src/integrations/GainsightPX/browser.js

[error] 51-51: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

Additional comments not posted (23)
packages/analytics-js-common/src/constants/integrations/GainsightPX/constants.ts (5)

1-1: LGTM!

The constant is correctly defined and the value is appropriate for the directory name.


2-2: LGTM!

The constant is correctly defined and the value is appropriate for the unique name identifier.


3-3: LGTM!

The constant is correctly defined and the value is appropriate for the user-friendly display name.


5-5: LGTM!

The constant is correctly defined as an object that maps the display name to the directory name. This mapping is useful for easier reference within the codebase.


6-10: LGTM!

The constant is correctly defined as an object that maps various representations of the integration's name to the standardized name identifier. This mapping ensures consistency and helps avoid discrepancies when referring to the Gainsight PX integration across the application.

packages/analytics-js-integrations/src/integrations/GainsightPX/nativeSdkLoader.js (1)

7-38: LGTM!

The loadNativeSdk function is well-structured and follows best practices for dynamically loading the Gainsight PX native SDK. It correctly determines the appropriate hostname based on the data center, constructs the SDK URL, parses the optional JSON configuration, creates and configures the script element, and inserts it into the document to initiate the SDK loading process. The closure usage for defining the SDK's global namespace and queue is a valid approach.

The code is clean, readable, and does not introduce any apparent issues or vulnerabilities. The suspicious assignment in an expression at line 29, as indicated by the static analysis hint, is a common pattern used in JavaScript for pushing arguments into an array and is not a cause for concern in this context.

Great job with the implementation!

Tools
Biome

[error] 29-29: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

packages/analytics-js-common/src/constants/integrations/config_to_integration_names.js (1)

83-83: LGTM!

The addition of the new entry GAINSIGHT_PX_BROWSER: 'GainsightPX' to the configToIntNames constant is consistent with the existing pattern and expands the mapping to include the new Gainsight PX integration. The change is self-contained and does not introduce any apparent issues.

packages/analytics-js-common/src/constants/integrations/client_server_name.js (1)

82-82: LGTM!

The addition of the new entry GAINSIGHT_PX_BROWSER: 'GainsightPX' to the clientToServerNames object is consistent with the existing pattern and expands the mapping of client identifiers to their corresponding server names. This change allows the analytics system to recognize and process data from the Gainsight PX browser client.

packages/analytics-js-integrations/src/integrations/GainsightPX/browser.js (8)

12-27: LGTM!

The GainsightPX class definition and constructor look good. The class properties are correctly initialized based on the provided configuration, and the logging setup is properly handled based on the analytics log level.


29-32: LGTM!

The init method correctly loads the native SDK using the provided configuration and calls the initializeMe method in the correct sequence.


34-48: LGTM!

The initializeMe method correctly identifies the user if a user ID is present. It constructs the visitor and account objects using the appropriate IDs and traits, and calls the window.aptrinsic function with the correct arguments to send the identification information to the Gainsight PX service.


50-52: LGTM!

The isLoaded method correctly checks if the SDK is loaded and ready for use by verifying the presence of the window.aptrinsic object and its init property. The double negation !! is used appropriately to convert the result to a boolean value.

Tools
Biome

[error] 51-51: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


54-56: LGTM!

The isReady method correctly determines if the SDK is ready by calling the isLoaded method. This is a valid approach as the readiness of the SDK depends on whether it is loaded.


64-84: LGTM!

The identify method correctly constructs visitor and account objects from the provided data. It extracts the necessary information from the rudderElement object, such as user ID, group ID, and traits. The method appropriately checks for the presence of a user ID before calling the window.aptrinsic function to identify the user with the constructed visitor and account objects.


90-109: LGTM!

The group method correctly constructs account and visitor objects from the provided data. It extracts the necessary information from the rudderElement object, such as user ID, group ID, anonymous ID, and traits. The method appropriately constructs the account object using the group ID or anonymous ID and traits, and the visitor object using the user ID and traits, if a user ID is present. The window.aptrinsic function is called with the constructed objects to identify the user.


112-120: LGTM!

The track method correctly sends custom events to the Gainsight PX service. It extracts the event name and properties from the rudderElement object and checks for the presence of an event name before proceeding. If the event name is missing, it appropriately logs an error and returns. The window.aptrinsic function is called with the correct arguments to track the custom event.

packages/analytics-js-integrations/src/integrations/index.js (2)

80-80: LGTM!

The import statement is syntactically correct and necessary to use the GainsightPX integration in this file.


164-164: Looks good!

The addition of the GainsightPX integration to the integrations object is syntactically correct and follows the established naming convention. The key name GAINSIGHT_PX_BROWSER is consistent with the PR summary's objective to prevent conflicts with the existing Gainsight PX integration.

packages/analytics-js-common/src/constants/integrations/integration_cname.js (2)

81-81: LGTM!

The import statement is syntactically correct and consistent with the existing import statements in the file. It is necessary to include the GainsightPX integration mapping in the commonNames object.


166-166: LGTM!

The spread syntax is syntactically correct and consistent with the existing spreads in the commonNames object. It is necessary to include the GainsightPX integration mapping in the commonNames object.

packages/analytics-js-common/src/constants/integrations/destDisplayNamesToFileNamesMap.ts (2)

161-162: LGTM!

The addition of the GainsightPXDisplayName and GainsightPXDirectoryName constants is consistent with the existing pattern and enables the inclusion of the Gainsight PX integration in the mapping.


246-246: LGTM!

The addition of the GainsightPXDisplayName to GainsightPXDirectoryName mapping is consistent with the existing pattern and allows the Gainsight PX integration to be correctly referenced and linked.

packages/analytics-js-common/src/constants/integrations/destinationNames.ts (1)

293-296: LGTM!

The changes add new exports for the Gainsight PX integration, following the existing pattern in the file. The additions are consistent and expand the integration capabilities within the analytics framework.

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