Repository: strapi/strapi
File: packages/core/core/src/services/metrics/sender.ts (TypeScript)

Code before:
    isCI: ciEnv.isCI,
    version: strapi.config.get('info.strapi'),
    useTypescriptOnServer: tsUtils.isUsingTypeScriptSync(serverRootPath),
    useTypescriptOnAdmin: tsUtils.isUsingTypeScriptSync(adminRootPath),
    projectId: uuid,
    isHostedOnStrapiCloud: env('STRAPI_HOSTING', null) === 'strapi.cloud',
    aiLicenseKey: env('STRAPI_ADMIN_AI_LICENSE', null),
  };

  addPackageJsonStrapiMetadata(anonymousGroupProperties, strapi);

  return async (event: string, payload: Payload = {}, opts = {}) => {
    const userId = generateAdminUserHash(strapi);

    const reqParams = {
      method: 'POST',
      body: JSON.stringify({
        event,
        userId,
        installId,
        eventProperties: payload.eventProperties,
        userProperties: userId ? { ...anonymousUserProperties, ...payload.userProperties } : {},
        groupProperties: {
          ...anonymousGroupProperties,
          projectType: strapi.EE ? 'Enterprise' : 'Community',
          ...strapi.ee,
          ...payload.groupProperties,
        },
      }),
      ..._.merge({ headers: { 'X-Strapi-Event': event } }, defaultQueryOpts, opts),
    };

    try {
      const analyticsUrl = env('STRAPI_ANALYTICS_URL', 'https://analytics.strapi.io');
      const res = await strapi.fetch(`${analyticsUrl}/api/v2/track`, reqParams);
      return res.ok;
    } catch (err) {
      return false;
    }
  };
};


Review comment (refactor):
Do we want to copy to entire ee object into here? I think it might be better to extract the specific properties we want to be sent ?

Code after:
    isCI: ciEnv.isCI,
    version: strapi.config.get('info.strapi'),
    useTypescriptOnServer: tsUtils.isUsingTypeScriptSync(serverRootPath),
    useTypescriptOnAdmin: tsUtils.isUsingTypeScriptSync(adminRootPath),
    projectId: uuid,
    isHostedOnStrapiCloud: env('STRAPI_HOSTING', null) === 'strapi.cloud',
    aiLicenseKey: env('STRAPI_ADMIN_AI_LICENSE', null),
  };

  addPackageJsonStrapiMetadata(anonymousGroupProperties, strapi);

  return async (event: string, payload: Payload = {}, opts = {}) => {
    const userId = generateAdminUserHash(strapi);

    const eeGroupProps: Record<string, unknown> = {};
    if (strapi.ee?.subscriptionId !== undefined && strapi.ee?.subscriptionId !== null) {
      eeGroupProps.subscriptionId = strapi.ee.subscriptionId;
    }
    if (strapi.ee?.planPriceId !== undefined && strapi.ee?.planPriceId !== null) {
      eeGroupProps.planPriceId = strapi.ee.planPriceId;
    }

    const reqParams = {
      method: 'POST',
      body: JSON.stringify({
        event,
        userId,
        installId,
        eventProperties: payload.eventProperties,
        userProperties: userId ? { ...anonymousUserProperties, ...payload.userProperties } : {},
        groupProperties: {
          ...anonymousGroupProperties,
          projectType: strapi.EE ? 'Enterprise' : 'Community',
          ...eeGroupProps,
          ...payload.groupProperties,
        },
      }),
      ..._.merge({ headers: { 'X-Strapi-Event': event } }, defaultQueryOpts, opts),
    };

    try {
      const analyticsUrl = env('STRAPI_ANALYTICS_URL', 'https://analytics.strapi.io');
      const res = await strapi.fetch(`${analyticsUrl}/api/v2/track`, reqParams);
      return res.ok;
    } catch (err) {
      return false;
    }
  };
};