chore: Send telemetry option in user profile to client (#9535)
Signed-off-by: Shrikant Sharat Kandula <shrikant@appsmith.com> Co-authored-by: sbalaji1192 <balaji@appsmith.com>
This commit is contained in:
parent
0b8181c229
commit
77caf4c536
15
app/client/cypress/fixtures/user.json
Normal file
15
app/client/cypress/fixtures/user.json
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"accountNonExpired": true,
|
||||
"accountNonLocked": true,
|
||||
"credentialsNonExpired": true,
|
||||
"email": "test@appsmith.com",
|
||||
"emptyInstance": false,
|
||||
"enableTelemetry": false,
|
||||
"isAnonymous": false,
|
||||
"isConfigurable": true,
|
||||
"isEnabled": true,
|
||||
"isSuperUser": true,
|
||||
"name": "test",
|
||||
"organizationIds": ["61a8a112ccc8b629d92a1aad"],
|
||||
"username": "test@appsmith.com"
|
||||
}
|
||||
|
|
@ -0,0 +1,116 @@
|
|||
import User from "../../../../fixtures/user.json";
|
||||
|
||||
let appId;
|
||||
|
||||
describe("Checks for analytics initialization", function() {
|
||||
it("Should check analytics is not initialised when enableTelemtry is false", function() {
|
||||
cy.intercept("GET", "/api/v1/users/me", {
|
||||
body: { responseMeta: { status: 200, success: true }, data: User },
|
||||
}).as("getUsersWithoutTelemetry");
|
||||
cy.visit("/applications");
|
||||
cy.reload();
|
||||
cy.wait("@getUsersWithoutTelemetry");
|
||||
cy.window().then((window) => {
|
||||
expect(window.analytics).to.be.equal(undefined);
|
||||
});
|
||||
let interceptFlag = false;
|
||||
cy.intercept("POST", "https://api.segment.io/**", (req) => {
|
||||
interceptFlag = true;
|
||||
req.continue();
|
||||
});
|
||||
cy.generateUUID().then((id) => {
|
||||
appId = id;
|
||||
cy.CreateAppInFirstListedOrg(id);
|
||||
localStorage.setItem("AppName", appId);
|
||||
});
|
||||
cy.wait(3000);
|
||||
cy.window().then(() => {
|
||||
cy.wrap(interceptFlag).should("eq", false);
|
||||
});
|
||||
});
|
||||
it("Should check analytics is initialised when enableTelemtry is true", function() {
|
||||
cy.intercept("GET", "/api/v1/users/me", {
|
||||
body: {
|
||||
responseMeta: { status: 200, success: true },
|
||||
data: {
|
||||
...User,
|
||||
enableTelemetry: true,
|
||||
},
|
||||
},
|
||||
}).as("getUsersWithTelemetry");
|
||||
cy.visit("/applications");
|
||||
cy.reload();
|
||||
cy.wait("@getUsersWithTelemetry");
|
||||
cy.wait(5000);
|
||||
cy.window().then((window) => {
|
||||
expect(window.analytics).not.to.be.undefined;
|
||||
});
|
||||
cy.wait(3000);
|
||||
let interceptFlag = false;
|
||||
cy.intercept("POST", "https://api.segment.io/**", (req) => {
|
||||
interceptFlag = true;
|
||||
req.continue();
|
||||
}).as("segment");
|
||||
cy.generateUUID().then((id) => {
|
||||
appId = id;
|
||||
cy.CreateAppInFirstListedOrg(id);
|
||||
localStorage.setItem("AppName", appId);
|
||||
});
|
||||
cy.wait("@segment");
|
||||
cy.window().then(() => {
|
||||
cy.wrap(interceptFlag).should("eq", true);
|
||||
});
|
||||
});
|
||||
|
||||
it("Should check smartlook is not initialised when enableTelemtry is false", function() {
|
||||
cy.intercept("GET", "/api/v1/users/me", {
|
||||
body: { responseMeta: { status: 200, success: true }, data: User },
|
||||
}).as("getUsersWithoutTelemetry");
|
||||
cy.visit("/applications");
|
||||
cy.reload();
|
||||
cy.wait("@getUsersWithoutTelemetry");
|
||||
cy.window().then((window) => {
|
||||
expect(window.smartlook).to.be.equal(undefined);
|
||||
});
|
||||
let interceptFlag = false;
|
||||
cy.intercept("POST", "https://**.smartlook.**", (req) => {
|
||||
interceptFlag = true;
|
||||
req.continue();
|
||||
});
|
||||
cy.generateUUID().then((id) => {
|
||||
appId = id;
|
||||
cy.CreateAppInFirstListedOrg(id);
|
||||
localStorage.setItem("AppName", appId);
|
||||
});
|
||||
cy.wait(3000);
|
||||
cy.window().then(() => {
|
||||
cy.wrap(interceptFlag).should("eq", false);
|
||||
});
|
||||
});
|
||||
|
||||
it("Should check Sentry is not initialised when enableTelemtry is false", function() {
|
||||
cy.intercept("GET", "/api/v1/users/me", {
|
||||
body: { responseMeta: { status: 200, success: true }, data: User },
|
||||
}).as("getUsersWithoutTelemetry");
|
||||
cy.visit("/applications");
|
||||
cy.reload();
|
||||
cy.wait("@getUsersWithoutTelemetry");
|
||||
cy.window().then((window) => {
|
||||
expect(window.Sentry).to.be.equal(undefined);
|
||||
});
|
||||
let interceptFlag = false;
|
||||
cy.intercept("POST", "https://**.sentry.io/**", (req) => {
|
||||
interceptFlag = true;
|
||||
req.continue();
|
||||
});
|
||||
cy.generateUUID().then((id) => {
|
||||
appId = id;
|
||||
cy.CreateAppInFirstListedOrg(id);
|
||||
localStorage.setItem("AppName", appId);
|
||||
});
|
||||
cy.wait(3000);
|
||||
cy.window().then(() => {
|
||||
cy.wrap(interceptFlag).should("eq", false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -170,7 +170,6 @@
|
|||
const CONFIG_LOG_LEVEL_INDEX = LOG_LEVELS.indexOf(parseConfig("__APPSMITH_CLIENT_LOG_LEVEL__"));
|
||||
|
||||
const INTERCOM_APP_ID = parseConfig("%REACT_APP_INTERCOM_APP_ID%") || parseConfig("__APPSMITH_INTERCOM_APP_ID__");
|
||||
const DISABLE_TELEMETRY = parseConfig("__APPSMITH_DISABLE_TELEMETRY__");
|
||||
const DISABLE_INTERCOM = parseConfig("__APPSMITH_DISABLE_INTERCOM__");
|
||||
|
||||
// Initialize the Intercom library
|
||||
|
|
@ -215,7 +214,6 @@
|
|||
},
|
||||
intercomAppID: INTERCOM_APP_ID,
|
||||
mailEnabled: parseConfig("__APPSMITH_MAIL_ENABLED__"),
|
||||
disableTelemetry: DISABLE_TELEMETRY === "" || DISABLE_TELEMETRY,
|
||||
cloudServicesBaseUrl: parseConfig("__APPSMITH_CLOUD_SERVICES_BASE_URL__") || "https://cs.appsmith.com",
|
||||
googleRecaptchaSiteKey: parseConfig("__APPSMITH_RECAPTCHA_SITE_KEY__"),
|
||||
};
|
||||
|
|
|
|||
|
|
@ -42,7 +42,6 @@ export type INJECTED_CONFIGS = {
|
|||
};
|
||||
intercomAppID: string;
|
||||
mailEnabled: boolean;
|
||||
disableTelemetry: boolean;
|
||||
cloudServicesBaseUrl: string;
|
||||
googleRecaptchaSiteKey: string;
|
||||
supportEmail: string;
|
||||
|
|
@ -120,7 +119,6 @@ const getConfigsFromEnvVars = (): INJECTED_CONFIGS => {
|
|||
mailEnabled: process.env.REACT_APP_MAIL_ENABLED
|
||||
? process.env.REACT_APP_MAIL_ENABLED.length > 0
|
||||
: false,
|
||||
disableTelemetry: true,
|
||||
cloudServicesBaseUrl: process.env.REACT_APP_CLOUD_SERVICES_BASE_URL || "",
|
||||
googleRecaptchaSiteKey:
|
||||
process.env.REACT_APP_GOOGLE_RECAPTCHA_SITE_KEY || "",
|
||||
|
|
@ -212,21 +210,9 @@ export const getAppsmithConfigs = (): AppsmithUIConfigs => {
|
|||
// We enable segment tracking if either the Cloud API key is set or the self-hosted CE key is set
|
||||
segment.enabled = segment.enabled || segmentCEKey.enabled;
|
||||
|
||||
let sentryTelemetry = true;
|
||||
// Turn off all analytics if telemetry is disabled
|
||||
if (APPSMITH_FEATURE_CONFIGS.disableTelemetry) {
|
||||
smartLook.enabled = false;
|
||||
segment.enabled = false;
|
||||
sentryTelemetry = false;
|
||||
}
|
||||
|
||||
return {
|
||||
sentry: {
|
||||
enabled:
|
||||
sentryDSN.enabled &&
|
||||
sentryRelease.enabled &&
|
||||
sentryENV.enabled &&
|
||||
sentryTelemetry,
|
||||
enabled: sentryDSN.enabled && sentryRelease.enabled && sentryENV.enabled,
|
||||
dsn: sentryDSN.value,
|
||||
release: sentryRelease.value,
|
||||
environment: sentryENV.value,
|
||||
|
|
@ -288,7 +274,6 @@ export const getAppsmithConfigs = (): AppsmithUIConfigs => {
|
|||
intercomAppID:
|
||||
ENV_CONFIG.intercomAppID || APPSMITH_FEATURE_CONFIGS.intercomAppID,
|
||||
mailEnabled: ENV_CONFIG.mailEnabled || APPSMITH_FEATURE_CONFIGS.mailEnabled,
|
||||
disableTelemetry: APPSMITH_FEATURE_CONFIGS.disableTelemetry,
|
||||
commentsTestModeEnabled: false,
|
||||
cloudServicesBaseUrl:
|
||||
ENV_CONFIG.cloudServicesBaseUrl ||
|
||||
|
|
|
|||
|
|
@ -68,8 +68,6 @@ export type AppsmithUIConfigs = {
|
|||
};
|
||||
intercomAppID: string;
|
||||
mailEnabled: boolean;
|
||||
|
||||
disableTelemetry: boolean;
|
||||
commentsTestModeEnabled: boolean;
|
||||
|
||||
cloudServicesBaseUrl: string;
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ export type User = {
|
|||
role?: string;
|
||||
useCase?: string;
|
||||
isConfigurable: boolean;
|
||||
enableTelemetry: boolean;
|
||||
};
|
||||
|
||||
export interface UserApplication {
|
||||
|
|
@ -39,6 +40,7 @@ export const DefaultCurrentUserDetails: User = {
|
|||
gender: "MALE",
|
||||
isSuperUser: false,
|
||||
isConfigurable: false,
|
||||
enableTelemetry: false,
|
||||
};
|
||||
|
||||
// TODO keeping it here instead of the USER_API since it leads to cyclic deps errors during tests
|
||||
|
|
|
|||
|
|
@ -65,6 +65,7 @@ import {
|
|||
getFirstTimeUserOnboardingApplicationId,
|
||||
getFirstTimeUserOnboardingIntroModalVisibility,
|
||||
} from "utils/storage";
|
||||
import { initializeAnalyticsAndTrackers } from "utils/AppsmithUtils";
|
||||
|
||||
export function* createUserSaga(
|
||||
action: ReduxActionWithPromise<CreateUserRequest>,
|
||||
|
|
@ -113,13 +114,17 @@ export function* getCurrentUserSaga() {
|
|||
|
||||
const isValidResponse = yield validateResponse(response);
|
||||
if (isValidResponse) {
|
||||
const { enableTelemetry } = response.data;
|
||||
if (enableTelemetry) {
|
||||
initializeAnalyticsAndTrackers();
|
||||
}
|
||||
yield put(initAppLevelSocketConnection());
|
||||
yield put(initPageLevelSocketConnection());
|
||||
if (
|
||||
!response.data.isAnonymous &&
|
||||
response.data.username !== ANONYMOUS_USERNAME
|
||||
) {
|
||||
AnalyticsUtil.identifyUser(response.data);
|
||||
enableTelemetry && AnalyticsUtil.identifyUser(response.data);
|
||||
// make fetch feature call only if logged in
|
||||
yield put(fetchFeatureFlagsInit());
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -267,7 +267,7 @@ class AnalyticsUtil {
|
|||
if (userData) {
|
||||
const { segment } = getAppsmithConfigs();
|
||||
let user: any = {};
|
||||
if (segment.enabled && segment.apiKey) {
|
||||
if (userData.enableTelemetry && segment.apiKey) {
|
||||
user = {
|
||||
userId: userData.username,
|
||||
email: userData.email,
|
||||
|
|
@ -291,7 +291,7 @@ class AnalyticsUtil {
|
|||
};
|
||||
}
|
||||
|
||||
if (windowDoc.analytics) {
|
||||
if (userData?.enableTelemetry && windowDoc.analytics) {
|
||||
log.debug("Event fired", eventName, finalEventData);
|
||||
windowDoc.analytics.track(eventName, finalEventData);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -53,6 +53,11 @@ export const createImmerReducer = (
|
|||
export const appInitializer = () => {
|
||||
FormControlRegistry.registerFormControlBuilders();
|
||||
const appsmithConfigs = getAppsmithConfigs();
|
||||
log.setLevel(getEnvLogLevel(appsmithConfigs.logLevel));
|
||||
};
|
||||
|
||||
export const initializeAnalyticsAndTrackers = () => {
|
||||
const appsmithConfigs = getAppsmithConfigs();
|
||||
|
||||
if (appsmithConfigs.sentry.enabled) {
|
||||
window.Sentry = Sentry;
|
||||
|
|
@ -92,8 +97,6 @@ export const appInitializer = () => {
|
|||
AnalyticsUtil.initializeSegment(appsmithConfigs.segment.ceKey);
|
||||
}
|
||||
}
|
||||
|
||||
log.setLevel(getEnvLogLevel(appsmithConfigs.logLevel));
|
||||
};
|
||||
|
||||
export const mapToPropList = (map: Record<string, string>): Property[] => {
|
||||
|
|
|
|||
|
|
@ -41,6 +41,8 @@ public class UserProfileDTO {
|
|||
|
||||
String useCase;
|
||||
|
||||
boolean enableTelemetry = false;
|
||||
|
||||
public boolean isAccountNonExpired() {
|
||||
return this.isEnabled;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -912,6 +912,7 @@ public class UserServiceImpl extends BaseService<UserRepository, User, String> i
|
|||
profile.setRole(userData.getRole());
|
||||
profile.setUseCase(userData.getUseCase());
|
||||
profile.setPhotoId(userData.getProfilePhotoAssetId());
|
||||
profile.setEnableTelemetry(!commonConfig.isTelemetryDisabled());
|
||||
|
||||
profile.setSuperUser(policyUtils.isPermissionPresentForUser(
|
||||
userFromDb.getPolicies(),
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user