PromucFlow_constructor/app/client/src/utils/AnalyticsUtil.tsx
subratadeypappu a480d4ff2e
feat: Store originalActionId as part of Action DTO for copied action (#25011)
## Description
To measure the impact of query modules in Appsmith. We need to track the
time a user takes to edit a copied query. Today, we do not have a
mechanism to understand if a query in question is a copied query. To fix
this, the data model of the Query action needs to change to include the
`originalQueryId` if a query is, in fact, a copied query.

- [ ] When a query is first copied, there will be no `originalActionId`
in the action object. In this scenario, the client will populate the
`originalActionId` field and call the POST API to create the copied
query.

- [ ] If the query is already a copied query, the client will duplicate
the value of the `originalActionId` when calling the POST API to create
the copied query.

|POST|`/api/v1/actions`|
----------|------|

### [Related discussion on

Notion](https://www.notion.so/appsmith/Backend-dependency-for-modules-instrumentation-889462d461844745be0a2599c8555ca5)

#### PR fixes following issue(s)
Fixes #24734 

#### Media
> A video or a GIF is preferred. when using Loom, don’t embed because it
looks like it’s a GIF. instead, just link to the video
>
>
#### Type of change
> Please delete options that are not relevant.
- Bug fix (non-breaking change which fixes an issue)
- New feature (non-breaking change which adds functionality)
- Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- Chore (housekeeping or task changes that don't impact user perception)
- This change requires a documentation update
>
>
>
## Testing
>
#### How Has This Been Tested?
> Please describe the tests that you ran to verify your changes. Also
list any relevant details for your test configuration.
> Delete anything that is not relevant
- [x] Manual
- [x] JUnit
- [ ] Jest
- [ ] Cypress
>
>
#### Test Plan
> Add Testsmith test cases links that relate to this PR
>
>
#### Issues raised during DP testing
> Link issues raised during DP testing for better visiblity and tracking
(copy link from comments dropped on this PR)
>
>
>
## Checklist:
#### Dev activity
- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing unit tests pass locally with my changes
- [ ] PR is being merged under a feature flag


#### QA activity:
- [ ] [Speedbreak
features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-)
have been covered
- [ ] Test plan covers all impacted features and [areas of
interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-)
- [ ] Test plan has been peer reviewed by project stakeholders and other
QA members
- [ ] Manually tested functionality on DP
- [ ] We had an implementation alignment call with stakeholders post QA
Round 2
- [ ] Cypress test cases have been added and approved by SDET/manual QA
- [ ] Added `Test Plan Approved` label after Cypress tests were reviewed
- [ ] Added `Test Plan Approved` label after JUnit tests were reviewed

> Pull Request Template
>
> Use this template to quickly create a well written pull request.
Delete all quotes before creating the pull request.
>
## Description
> Add a TL;DR when description is extra long (helps content team)
>
> Please include a summary of the changes and which issue has been
fixed. Please also include relevant motivation
> and context. List any dependencies that are required for this change
>
> Links to Notion, Figma or any other documents that might be relevant
to the PR
>
>
#### PR fixes following issue(s)
Fixes # (issue number)
> if no issue exists, please create an issue and ask the maintainers
about this first
>
>
#### Media
> A video or a GIF is preferred. when using Loom, don’t embed because it
looks like it’s a GIF. instead, just link to the video
>
>
#### Type of change
> Please delete options that are not relevant.
- Bug fix (non-breaking change which fixes an issue)
- New feature (non-breaking change which adds functionality)
- Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- Chore (housekeeping or task changes that don't impact user perception)
- This change requires a documentation update
>
>
>
## Testing
>
#### How Has This Been Tested?
> Please describe the tests that you ran to verify your changes. Also
list any relevant details for your test configuration.
> Delete anything that is not relevant
- [ ] Manual
- [ ] Jest
- [ ] Cypress
>
>
#### Test Plan
> Add Testsmith test cases links that relate to this PR
>
>
#### Issues raised during DP testing
> Link issues raised during DP testing for better visiblity and tracking
(copy link from comments dropped on this PR)
>
>
>
## Checklist:
#### Dev activity
- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] PR is being merged under a feature flag


#### QA activity:
- [ ] [Speedbreak
features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-)
have been covered
- [ ] Test plan covers all impacted features and [areas of
interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-)
- [ ] Test plan has been peer reviewed by project stakeholders and other
QA members
- [ ] Manually tested functionality on DP
- [ ] We had an implementation alignment call with stakeholders post QA
Round 2
- [ ] Cypress test cases have been added and approved by SDET/manual QA
- [ ] Added `Test Plan Approved` label after Cypress tests were reviewed
- [ ] Added `Test Plan Approved` label after JUnit tests were reviewed

---------

Co-authored-by: Abhinav Jha <abhinav@appsmith.com>
2023-07-04 13:42:09 +06:00

634 lines
18 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Events
import * as log from "loglevel";
import smartlookClient from "smartlook-client";
import { getAppsmithConfigs } from "@appsmith/configs";
import * as Sentry from "@sentry/react";
import type { User } from "constants/userConstants";
import { ANONYMOUS_USERNAME } from "constants/userConstants";
import { sha256 } from "js-sha256";
declare global {
interface Window {
// Zipy is added via script tags in index.html
zipy: {
identify: (uid: string, userInfo: Record<string, string>) => void;
anonymize: () => void;
};
}
}
export type EventLocation =
| "LIGHTNING_MENU"
| "API_PANE"
| "QUERY_PANE"
| "QUERY_TEMPLATE"
| "QUICK_COMMANDS"
| "OMNIBAR"
| "SUBMENU"
| "ACTION_SELECTOR"
| "ENTITY_EXPLORER"
| "KEYBOARD_SHORTCUT"
| "JS_OBJECT_GUTTER_RUN_BUTTON" // Gutter: https://codemirror.net/examples/gutter/
| "JS_OBJECT_MAIN_RUN_BUTTON"
| "JS_OBJECT_RESPONSE_RUN_BUTTON"
| "ONE_CLICK_BINDING";
export type EventName =
| "APP_CRASH"
| "SWITCH_DATASOURCE"
| "LOGIN_CLICK"
| "SIGNUP_CLICK"
| "PAGE_VIEW"
| "ADD_COMPONENT"
| "DELETE_COMPONENT"
| "RESIZE_COMPONENT"
| "WIDGET_DRAG"
| "WIDGET_DROP"
| "WIDGET_DELETE"
| "WIDGET_RESIZE_START"
| "WIDGET_RESIZE_END"
| "WIDGET_PROPERTY_UPDATE"
| "WIDGET_TOGGLE_JS_PROP"
| "WIDGET_CARD_DRAG"
| "WIDGET_CARD_DROP"
| "CREATE_PAGE"
| "PAGE_RENAME"
| "PAGE_SWITCH"
| "DELETE_PAGE"
| "SIDEBAR_NAVIGATION"
| "PUBLISH_APP"
| "PREVIEW_APP"
| "APP_VIEWED_WITH_NAVBAR"
| "EDITOR_OPEN"
| "CREATE_ACTION"
| "SAVE_SAAS"
| "DELETE_SAAS"
| "RUN_SAAS_API"
| "SAVE_API"
| "SAVE_API_CLICK"
| "RUN_API"
| "RUN_API_CLICK"
| "RUN_API_SHORTCUT"
| "DELETE_API"
| "DELETE_API_CLICK"
| "IMPORT_API"
| "EXPAND_API"
| "IMPORT_API_CLICK"
| "MOVE_API_CLICK"
| "ADD_API_PAGE"
| "DUPLICATE_ACTION"
| "DUPLICATE_ACTION_CLICK"
| "RUN_QUERY"
| "RUN_QUERY_CLICK"
| "RUN_QUERY_SHORTCUT"
| "DELETE_QUERY"
| "SAVE_QUERY"
| "MOVE_API"
| "3P_PROVIDER_CLICK"
| "API_SELECT"
| "CREATE_API_CLICK"
| "AUTO_COMPLETE_SHOW"
| "AUTO_COMPLETE_SELECT"
| "CREATE_APP_CLICK"
| "CREATE_APP"
| "CREATE_DATA_SOURCE_CLICK"
| "SAVE_DATA_SOURCE"
| "SAVE_DATA_SOURCE_CLICK"
| "CONSOLE_LOG_CREATED"
| "TEST_DATA_SOURCE_SUCCESS"
| "TEST_DATA_SOURCE_CLICK"
| "UPDATE_DATASOURCE"
| "CREATE_QUERY_CLICK"
| "NAVIGATE"
| "PAGE_LOAD"
| "NAVIGATE_EDITOR"
| "PROPERTY_PANE_OPEN"
| "PROPERTY_PANE_CLOSE"
| "PROPERTY_PANE_OPEN_CLICK"
| "WIDGET_DELETE_UNDO"
| "WIDGET_COPY_VIA_SHORTCUT"
| "WIDGET_COPY"
| "WIDGET_CUT_VIA_SHORTCUT"
| "WIDGET_PASTE"
| "WIDGET_DELETE_VIA_SHORTCUT"
| "OPEN_HELP"
| "INVITE_USER"
| "ROUTE_CHANGE"
| "PROPERTY_PANE_CLOSE_CLICK"
| "APPLICATIONS_PAGE_LOAD"
| "EXECUTE_ACTION"
| "FILE_UPLOAD_COMPLETE"
| "WELCOME_TOUR_CLICK"
| "GUIDED_TOUR_RATING"
| "GUIDED_TOUR_REACHED_STEP"
| "END_GUIDED_TOUR_CLICK"
| "OPEN_OMNIBAR"
| "CLOSE_OMNIBAR"
| "NAVIGATE_TO_ENTITY_FROM_OMNIBAR"
| "PAGE_SAVE"
| "CORRECT_BAD_BINDING"
| "OPEN_DEBUGGER"
| "DEBUGGER_TAB_SWITCH"
| "DEBUGGER_FILTER_CHANGED"
| "DEBUGGER_ENTITY_NAVIGATION"
| "GSHEET_AUTH_INIT"
| "GSHEET_AUTH_COMPLETE"
| "CYCLICAL_DEPENDENCY_ERROR"
| "DISCORD_LINK_CLICK"
| "INTERCOM_CLICK"
| "ENTITY_BINDING_SUCCESS"
| "APP_MENU_OPTION_CLICK"
| "SLASH_COMMAND"
| "DEBUGGER_NEW_ERROR"
| "DEBUGGER_RESOLVED_ERROR"
| "DEBUGGER_NEW_ERROR_MESSAGE"
| "DEBUGGER_RESOLVED_ERROR_MESSAGE"
| "DEBUGGER_LOG_ITEM_EXPAND"
| "DEBUGGER_HELP_CLICK"
| "DEBUGGER_CONTEXT_MENU_CLICK"
| "ADD_MOCK_DATASOURCE_CLICK"
| "GEN_CRUD_PAGE_CREATE_NEW_DATASOURCE"
| "GEN_CRUD_PAGE_FORM_SUBMIT"
| "GEN_CRUD_PAGE_EDIT_DATASOURCE_CONFIG"
| "GEN_CRUD_PAGE_SELECT_DATASOURCE"
| "GEN_CRUD_PAGE_SELECT_TABLE"
| "GEN_CRUD_PAGE_SELECT_SEARCH_COLUMN"
| "BUILD_FROM_SCRATCH_ACTION_CARD_CLICK"
| "GEN_CRUD_PAGE_ACTION_CARD_CLICK"
| "GEN_CRUD_PAGE_DATA_SOURCE_CLICK"
| "DATASOURCE_CARD_GEN_CRUD_PAGE_ACTION"
| "DATASOURCE_CARD_DELETE_ACTION"
| "DATASOURCE_CARD_EDIT_ACTION"
| "UNSUPPORTED_PLUGIN_DIALOG_BACK_ACTION"
| "UNSUPPORTED_PLUGIN_DIALOG_CONTINUE_ACTION"
| "SELECT_IN_CANVAS_CLICK"
| "WIDGET_SELECTED_VIA_SNIPING_MODE"
| "SUGGESTED_WIDGET_CLICK"
| "ASSOCIATED_ENTITY_CLICK"
| "CREATE_DATA_SOURCE_AUTH_API_CLICK"
| "CONNECT_DATA_CLICK"
| "RESPONSE_TAB_RUN_ACTION_CLICK"
| "ASSOCIATED_ENTITY_DROPDOWN_CLICK"
| "PAGES_LIST_LOAD"
| "WIDGET_GROUP"
| "CLOSE_GEN_PAGE_INFO_MODAL"
| "COMMENTS_TOGGLE_MODE"
| "COMMENTS_ONBOARDING_SKIP_BUTTON_CLICK"
| "COMMENTS_ONBOARDING_STEP_CHANGE"
| "COMMENTS_ONBOARDING_SUBMIT_BUTTON_CLICK"
| "COMMENTS_ONBOARDING_MODAL_DISMISSED"
| "COMMENTS_ONBOARDING_MODAL_TRIGGERED"
| "REPLAY_UNDO"
| "REPLAY_REDO"
| "URL_COPIED"
| "SNIPPET_CUSTOMIZE"
| "SNIPPET_EXECUTE"
| "SNIPPET_FILTER"
| "SNIPPET_COPIED"
| "SNIPPET_LOOKUP"
| "SIGNPOSTING_SKIP"
| "SIGNPOSTING_MODAL_CREATE_DATASOURCE_CLICK"
| "SIGNPOSTING_MODAL_CREATE_QUERY_CLICK"
| "SIGNPOSTING_MODAL_ADD_WIDGET_CLICK"
| "SIGNPOSTING_MODAL_CONNECT_WIDGET_CLICK"
| "SIGNPOSTING_MODAL_PUBLISH_CLICK"
| "SIGNPOSTING_WELCOME_TOUR_CLICK"
| "SIGNPOSTING_MODAL_CLOSE_CLICK"
| "SIGNPOSTING_INFO_CLICK"
| "SIGNPOSTING_MODAL_FIRST_TIME_OPEN"
| "GS_BRANCH_MORE_MENU_OPEN"
| "GIT_DISCARD_WARNING"
| "GIT_DISCARD_CANCEL"
| "GIT_DISCARD"
| "GS_OPEN_BRANCH_LIST_POPUP"
| "GS_CREATE_NEW_BRANCH"
| "GS_SYNC_BRANCHES"
| "GS_CONNECT_GIT_CLICK"
| "GS_SETTING_CLICK"
| "GS_DISCONNECT_GIT_CLICK"
| "GS_COMMIT_AND_PUSH_BUTTON_CLICK"
| "GS_LAST_DEPLOYED_PREVIEW_LINK_CLICK"
| "GS_PULL_GIT_CLICK"
| "GS_DEPLOY_GIT_CLICK"
| "GS_DEPLOY_GIT_MODAL_TRIGGERED"
| "GS_MERGE_GIT_MODAL_TRIGGERED"
| "GS_REPO_LIMIT_ERROR_MODAL_TRIGGERED"
| "GS_GIT_DOCUMENTATION_LINK_CLICK"
| "GS_MERGE_CHANGES_BUTTON_CLICK"
| "GS_REPO_URL_EDIT"
| "GS_MATCHING_REPO_NAME_ON_GIT_DISCONNECT_MODAL"
| "GS_GENERATE_KEY_BUTTON_CLICK"
| "GS_COPY_SSH_KEY_BUTTON_CLICK"
| "GS_DEFAULT_CONFIGURATION_EDIT_BUTTON_CLICK"
| "GS_DEFAULT_CONFIGURATION_CHECKBOX_TOGGLED"
| "GS_CONNECT_BUTTON_ON_GIT_SYNC_MODAL_CLICK"
| "GS_IMPORT_VIA_GIT_CARD_CLICK"
| "GS_CONTACT_SALES_CLICK"
| "GS_REGENERATE_SSH_KEY_CONFIRM_CLICK"
| "GS_REGENERATE_SSH_KEY_MORE_CLICK"
| "GS_SWITCH_BRANCH"
| "ADMIN_SETTINGS_CLICK"
| "ADMIN_SETTINGS_RESET"
| "ADMIN_SETTINGS_SAVE"
| "ADMIN_SETTINGS_ERROR"
| "ADMIN_SETTINGS_DISCONNECT_AUTH_METHOD"
| "ADMIN_SETTINGS_UPGRADE_AUTH_METHOD"
| "ADMIN_SETTINGS_EDIT_AUTH_METHOD"
| "ADMIN_SETTINGS_ENABLE_AUTH_METHOD"
| "ADMIN_SETTINGS_UPGRADE_HOOK"
| "BILLING_UPGRADE_ADMIN_SETTINGS"
| "AUDIT_LOGS_UPGRADE_ADMIN_SETTINGS"
| "GAC_UPGRADE_CLICK_ADMIN_SETTINGS"
| "REFLOW_BETA_FLAG"
| "CONTAINER_JUMP"
| "CONNECT_GIT_CLICK"
| "REPO_URL_EDIT"
| "GENERATE_KEY_BUTTON_CLICK"
| "COPY_SSH_KEY_BUTTON_CLICK"
| "LEARN_MORE_LINK_FOR_REMOTEURL_CLICK"
| "LEARN_MORE_LINK_FOR_SSH_CLICK"
| "DEFAULT_CONFIGURATION_EDIT_BUTTON_CLICK"
| "DEFAULT_CONFIGURATION_CHECKBOX_TOGGLED"
| "CONNECT_BUTTON_ON_GIT_SYNC_MODAL_CLICK"
| "DATASOURCE_AUTH_COMPLETE"
| "APP_THEMING_CHOOSE_THEME"
| "APP_THEMING_APPLY_THEME"
| "APP_THEMING_CUSTOMIZE_THEME"
| "APP_THEMING_SAVE_THEME_START"
| "APP_THEMING_SAVE_THEME_SUCCESS"
| "APP_THEMING_DELETE_THEME"
| "RECONNECTING_DATASOURCE_ITEM_CLICK"
| "ADD_MISSING_DATASOURCE_LINK_CLICK"
| "RECONNECTING_SKIP_TO_APPLICATION_BUTTON_CLICK"
| "TEMPLATE_FILTER_SELECTED"
| "MANUAL_UPGRADE_CLICK"
| "PAGE_NOT_FOUND"
| "SIMILAR_TEMPLATE_CLICK"
| "TEMPLATES_TAB_CLICK"
| "PROPERTY_PANE_KEYPRESS"
| "PAGE_NAME_CLICK"
| "BACK_BUTTON_CLICK"
| "WIDGET_TAB_CLICK"
| "ENTITY_EXPLORER_CLICK"
| "ADMIN_SETTINGS_UPGRADE_WATERMARK"
| "ADMIN_SETTINGS_UPGRADE"
| "PRETTIFY_CODE_MANUAL_TRIGGER"
| "PRETTIFY_CODE_KEYBOARD_SHORTCUT"
| "JS_OBJECT_CREATED"
| "JS_OBJECT_FUNCTION_ADDED"
| "JS_OBJECT_FUNCTION_RUN"
| "JS_OBJECT_SETTINGS_CHANGED"
| "SHOW_BINDINGS_TRIGGERED"
| "BINDING_COPIED"
| "AUTO_HEIGHT_OVERLAY_HANDLES_UPDATE"
| "ENTITY_EXPLORER_ADD_PAGE_CLICK"
| "CANVAS_BLANK_PAGE_CTA_CLICK"
| AUDIT_LOGS_EVENT_NAMES
| GAC_EVENT_NAMES
| "BRANDING_UPGRADE_CLICK"
| "BRANDING_PROPERTY_UPDATE"
| "BRANDING_SUBMIT_CLICK"
| "Cmd+Click Navigation"
| "WIDGET_PROPERTY_SEARCH"
| "PEEK_OVERLAY_OPENED"
| "PEEK_OVERLAY_COLLAPSE_EXPAND_CLICK"
| "PEEK_OVERLAY_VALUE_COPIED"
| LIBRARY_EVENTS
| "APP_SETTINGS_BUTTON_CLICK"
| "APP_SETTINGS_SECTION_CLICK"
| APP_NAVIGATION_EVENT_NAMES
| ACTION_SELECTOR_EVENT_NAMES
| "PRETTIFY_AND_SAVE_KEYBOARD_SHORTCUT"
| "OPEN_DOCS"
| "RESTORE_SNAPSHOT"
| "CONVERSION_FAILURE"
| "CONVERT_AUTO_TO_FIXED"
| "CONVERT_FIXED_TO_AUTO"
| "DATASOURCE_AUTHORIZE_CLICK"
| "NAVIGATE_TO_CREATE_NEW_DATASOURCE_PAGE"
| "EDIT_DATASOURCE_CLICK"
| "DISCARD_DATASOURCE_CHANGES"
| "TEST_DATA_SOURCE_FAILED"
| "DATASOURCE_SCHEMA_FETCH"
| "DATASOURCE_SCHEMA_FETCH_SUCCESS"
| "DATASOURCE_SCHEMA_FETCH_FAILURE"
| "EDIT_ACTION_CLICK"
| "QUERY_TEMPLATE_SELECTED"
| "RUN_API_FAILURE"
| "RUN_QUERY_FAILURE"
| "RUN_SAAS_API_FAILURE"
| "EXECUTE_ACTION_SUCCESS"
| "EXECUTE_ACTION_FAILURE"
| "GOOGLE_SHEET_FILE_PICKER_INITIATED"
| "GOOGLE_SHEET_FILE_PICKER_FILES_LISTED"
| "GOOGLE_SHEET_FILE_PICKER_CANCEL"
| "GOOGLE_SHEET_FILE_PICKER_PICKED"
| "TELEMETRY_DISABLED"
| "GENERAL_SETTINGS_UPDATE"
| "HELP_MENU_WELCOME_TOUR_CLICK"
| "DISPLAY_TELEMETRY_CALLOUT"
| "VISIT_ADMIN_SETTINGS_TELEMETRY_CALLOUT"
| "LEARN_MORE_TELEMETRY_CALLOUT"
| AI_EVENTS
| ONE_CLICK_BINDING_EVENT_NAMES
| "JS_VARIABLE_CREATED"
| "JS_VARIABLE_MUTATED"
| "EXPLORER_WIDGET_CLICK"
| "WIDGET_SEARCH"
| "MAKE_APPLICATION_PUBLIC";
export type AI_EVENTS =
| "AI_QUERY_SENT"
| "AI_RESPONSE_GENERATED"
| "AI_RESPONSE_COPIED"
| "AI_RESPONSE_EXECUTION_FAILED"
| "AI_RESPONSE_FEEDBACK"
| "AI_RESPONSE_EXECUTION_INIT";
export type LIBRARY_EVENTS =
| "INSTALL_LIBRARY"
| "DEFINITIONS_GENERATION"
| "UNINSTALL_LIBRARY"
| "EDIT_LIBRARY_URL";
export type AUDIT_LOGS_EVENT_NAMES =
| "AUDIT_LOGS_CLEAR_FILTERS"
| "AUDIT_LOGS_FILTER_BY_RESOURCE_ID"
| "AUDIT_LOGS_FILTER_BY_EMAIL"
| "AUDIT_LOGS_FILTER_BY_EVENT"
| "AUDIT_LOGS_FILTER_BY_DATE"
| "AUDIT_LOGS_COLLAPSIBLE_ROW_OPENED"
| "AUDIT_LOGS_COLLAPSIBLE_ROW_CLOSED";
export type GAC_EVENT_NAMES =
| "GAC_USER_CLICK"
| "GAC_USER_ROLE_UPDATE"
| "GAC_USER_GROUP_UPDATE"
| "GAC_GROUP_ROLE_UPDATE"
| "GAC_INVITE_USER_CLICK"
| "GAC_ADD_USER_CLICK";
export type APP_NAVIGATION_EVENT_NAMES =
| "APP_NAVIGATION_SHOW_NAV"
| "APP_NAVIGATION_ORIENTATION"
| "APP_NAVIGATION_VARIANT"
| "APP_NAVIGATION_BACKGROUND_COLOR"
| "APP_NAVIGATION_SHOW_SIGN_IN";
export type ACTION_SELECTOR_EVENT_NAMES =
| "ACTION_ADDED"
| "ACTION_DELETED"
| "ACTION_MODIFIED";
export type ONE_CLICK_BINDING_EVENT_NAMES =
| "BIND_EXISTING_QUERY_TO_WIDGET"
| "GENERATE_QUERY_FOR_WIDGET"
| "BIND_OTHER_ACTIONS"
| "GENERATE_QUERY_SELECT_DATA_TABLE"
| "GENERATE_QUERY_SET_COLUMN"
| "GENERATE_QUERY_CONNECT_DATA_CLICK"
| "QUERY_GENERATION_BINDING_SUCCESS"
| "1_CLICK_BINDING_SUCCESS"
| "WIDGET_CONNECT_DATA_CLICK"
| "GENERATE_QUERY_SELECT_SHEET_GSHEET";
function getApplicationId(location: Location) {
const pathSplit = location.pathname.split("/");
const applicationsIndex = pathSplit.findIndex(
(path) => path === "applications",
);
const appId = pathSplit[applicationsIndex + 1];
return appId;
}
class AnalyticsUtil {
static cachedAnonymoustId: string;
static cachedUserId: string;
static user?: User = undefined;
static blockTrackEvent: boolean | undefined;
static instanceId?: string = "";
static initializeSmartLook(id: string) {
smartlookClient.init(id);
}
static initializeSegment(key: string) {
const initPromise = new Promise<boolean>((resolve) => {
(function init(window: any) {
const analytics = (window.analytics = window.analytics || []);
if (!analytics.initialize) {
if (analytics.invoked) {
log.error("Segment snippet included twice.");
} else {
analytics.invoked = !0;
analytics.methods = [
"trackSubmit",
"trackClick",
"trackLink",
"trackForm",
"pageview",
"identify",
"reset",
"group",
"track",
"ready",
"alias",
"debug",
"page",
"once",
"off",
"on",
];
analytics.factory = function (t: any) {
return function () {
const e = Array.prototype.slice.call(arguments); //eslint-disable-line prefer-rest-params
e.unshift(t);
analytics.push(e);
return analytics;
};
};
}
for (let t: any = 0; t < analytics.methods.length; t++) {
const e = analytics.methods[t];
analytics[e] = analytics.factory(e);
}
analytics.load = function (t: any, e: any) {
const n = document.createElement("script");
n.type = "text/javascript";
n.async = !0;
// Ref: https://www.notion.so/appsmith/530051a2083040b5bcec15a46121aea3
n.src = "https://a.appsmith.com/reroute/" + t + "/main.js";
const a: any = document.getElementsByTagName("script")[0];
a.parentNode.insertBefore(n, a);
analytics._loadOptions = e;
};
analytics.ready(() => {
resolve(true);
});
setTimeout(() => {
resolve(false);
}, 2000);
analytics.SNIPPET_VERSION = "4.1.0";
// Ref: https://segment.com/docs/connections/sources/catalog/libraries/website/javascript/#batching
analytics.load(key, {
integrations: {
"Segment.io": {
deliveryStrategy: {
strategy: "batching", // The delivery strategy used for sending events to Segment
config: {
size: 100, // The batch size is the threshold that forces all batched events to be sent once its reached.
timeout: 1000, // The number of milliseconds that forces all events queued for batching to be sent, regardless of the batch size, once its reached
},
},
},
},
});
if (!AnalyticsUtil.blockTrackEvent) {
analytics.page();
}
}
})(window);
});
return initPromise;
}
static logEvent(eventName: EventName, eventData: any = {}) {
if (AnalyticsUtil.blockTrackEvent) {
return;
}
const windowDoc: any = window;
let finalEventData = eventData;
const userData = AnalyticsUtil.user;
const instanceId = AnalyticsUtil.instanceId;
const appId = getApplicationId(windowDoc.location);
if (userData) {
const { segment } = getAppsmithConfigs();
let user: any = {};
if (segment.apiKey) {
user = {
userId: userData.username,
email: userData.email,
appId: appId,
source: "cloud",
};
} else {
const userId = userData.username;
if (userId !== AnalyticsUtil.cachedUserId) {
AnalyticsUtil.cachedAnonymoustId = sha256(userId);
AnalyticsUtil.cachedUserId = userId;
}
user = {
userId: AnalyticsUtil.cachedAnonymoustId,
source: "ce",
};
}
finalEventData = {
...eventData,
userData: user.userId === ANONYMOUS_USERNAME ? undefined : user,
};
}
finalEventData = { ...finalEventData, instanceId };
if (windowDoc.analytics) {
log.debug("Event fired", eventName, finalEventData);
windowDoc.analytics.track(eventName, finalEventData);
} else {
log.debug("Event fired locally", eventName, finalEventData);
}
}
static identifyUser(userData: User) {
const { segment, sentry, smartLook } = getAppsmithConfigs();
const windowDoc: any = window;
const userId = userData.username;
if (windowDoc.analytics) {
// This flag is only set on Appsmith Cloud. In this case, we get more detailed analytics of the user
if (segment.apiKey) {
const userProperties = {
email: userData.email,
name: userData.name,
userId: userId,
source: "cloud",
};
AnalyticsUtil.user = userData;
log.debug("Identify User " + userId);
windowDoc.analytics.identify(userId, userProperties);
} else if (segment.ceKey) {
// This is a self-hosted instance. Only send data if the analytics are NOT disabled by the user
if (userId !== AnalyticsUtil.cachedUserId) {
AnalyticsUtil.cachedAnonymoustId = sha256(userId);
AnalyticsUtil.cachedUserId = userId;
}
const userProperties = {
userId: AnalyticsUtil.cachedAnonymoustId,
source: "ce",
};
log.debug(
"Identify Anonymous User " + AnalyticsUtil.cachedAnonymoustId,
);
windowDoc.analytics.identify(
AnalyticsUtil.cachedAnonymoustId,
userProperties,
);
}
}
if (sentry.enabled) {
Sentry.configureScope(function (scope) {
scope.setUser({
id: userId,
username: userData.username,
email: userData.email,
});
});
}
if (smartLook.enabled) {
smartlookClient.identify(userId, { email: userData.email });
}
// If zipy was included, identify this user on the platform
if (window.zipy && userId) {
window.zipy.identify(userId, {
email: userData.email,
username: userData.username,
});
}
AnalyticsUtil.blockTrackEvent = false;
}
static initInstanceId(instanceId: string) {
AnalyticsUtil.instanceId = instanceId;
}
static getAnonymousId() {
const windowDoc: any = window;
const { segment } = getAppsmithConfigs();
if (windowDoc.analytics && windowDoc.analytics.user) {
return windowDoc.analytics.user().anonymousId();
} else if (segment.enabled) {
return localStorage.getItem("ajs_anonymous_id")?.replaceAll('"', "");
}
}
static reset() {
const windowDoc: any = window;
if (windowDoc.Intercom) {
windowDoc.Intercom("shutdown");
}
windowDoc.analytics && windowDoc.analytics.reset();
windowDoc.mixpanel && windowDoc.mixpanel.reset();
window.zipy && window.zipy.anonymize();
}
static removeAnalytics() {
AnalyticsUtil.blockTrackEvent = false;
(window as any).analytics = undefined;
}
}
export default AnalyticsUtil;