chore: Tracking organizationId in analytics for cloud billing (#40719)

## Description



Fixes #`Issue Number`  
_or_  
Fixes `Issue URL`
> [!WARNING]  
> _If no issue exists, please create an issue first, and check with the
maintainers if the issue is valid._

## Automation

/test sanity

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!CAUTION]
> 🔴 🔴 🔴 Some tests have failed.
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/15163916169>
> Commit: 3695abfed6d9db0af99289e71dbb7447ff68311d
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=15163916169&attempt=1&selectiontype=test&testsstatus=failed&specsstatus=fail"
target="_blank">Cypress dashboard</a>.
> Tags: @tag.Sanity
> Spec: 
> The following are new failures, please fix them before merging the PR:
<ol>
>
<li>cypress/e2e/Regression/ClientSide/Widgets/TableV2/AddNewRow2_spec.js</ol>
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/identified-flaky-tests-65890b3c81d7400d08fa9ee3?branch=master"
target="_blank">List of identified flaky tests</a>.
> <hr>Wed, 21 May 2025 14:33:26 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**
- Analytics events and user identification now include organization ID
for enhanced tracking and reporting.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Trisha Anand 2025-05-22 11:34:01 +05:30 committed by GitHub
parent d64361e225
commit c733ae0b63
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -125,6 +125,7 @@ public class AnalyticsServiceCEImpl implements AnalyticsServiceCE {
String name = savedUser.getName();
String email = savedUser.getEmail();
final String emailDomainHash = getEmailDomainHash(email);
String organizationId = savedUser.getOrganizationId();
if (!commonConfig.isCloudHosting()) {
username = hash(username);
@ -135,15 +136,26 @@ public class AnalyticsServiceCEImpl implements AnalyticsServiceCE {
analytics.enqueue(IdentifyMessage.builder()
.userId(ObjectUtils.defaultIfNull(username, ""))
.traits(Map.of(
"name", ObjectUtils.defaultIfNull(name, ""),
"email", ObjectUtils.defaultIfNull(email, ""),
"emailDomainHash", emailDomainHash,
"isSuperUser", isSuperUser,
"instanceId", instanceId,
"mostRecentlyUsedWorkspaceId", tuple.getT4(),
"role", "",
"proficiency", ObjectUtils.defaultIfNull(userData.getProficiency(), ""),
"goal", ObjectUtils.defaultIfNull(userData.getUseCase(), ""))));
"name",
ObjectUtils.defaultIfNull(name, ""),
"email",
ObjectUtils.defaultIfNull(email, ""),
"emailDomainHash",
emailDomainHash,
"isSuperUser",
isSuperUser,
"instanceId",
instanceId,
"organizationId",
ObjectUtils.defaultIfNull(organizationId, ""),
"mostRecentlyUsedWorkspaceId",
tuple.getT4(),
"role",
"",
"proficiency",
ObjectUtils.defaultIfNull(userData.getProficiency(), ""),
"goal",
ObjectUtils.defaultIfNull(userData.getUseCase(), ""))));
analytics.flush();
return savedUser;
});
@ -329,11 +341,14 @@ public class AnalyticsServiceCEImpl implements AnalyticsServiceCE {
return Mono.just(object);
}
String organizationId = user.getOrganizationId();
final String username = (object instanceof User objectAsUser ? objectAsUser : user).getUsername();
HashMap<String, Object> analyticsProperties = new HashMap<>();
analyticsProperties.put("id", id);
analyticsProperties.put("oid", ((Identifiable) object).getId());
analyticsProperties.put("organizationId", ObjectUtils.defaultIfNull(organizationId, ""));
if (extraProperties != null) {
analyticsProperties.putAll(extraProperties);
// To avoid sending extra event data to analytics