Browse Source

Feat/additional options for org analytics (#35606)

The new analytics functions created by makeAnalyticsFunction were supposed to require an organization object so we can pull out the role information (and potentially more fields later) for all analytics events. However, in some cases we might only have an organization ID or OrganizationSummry which does not have the role information. In those cases, we should still be able to pass an organization ID. To remedy this, I am adding the additional option to support the organization option to analytics events as a string. However, in order to reduce the chances someone accidentally passes in a string when the full organization is available, I am making the organization required for the trackAdvancedAnalyticsEvent function. We can make a specific function just to handle cases where the organization is just an ID.
Stephen Cefali 2 years ago
parent
commit
0576f6d122

+ 5 - 1
static/app/types/hooks.tsx

@@ -310,7 +310,11 @@ type AnalyticsTrackEventV2 = (
      * The Amplitude event name. Set to null if event should not go to Amplitude.
      */
     eventName: string | null;
-    organization: Organization | null;
+    /**
+     * Organization to pass in. If full org object not available, pass in just the Id.
+     * If no org, pass in null.
+     */
+    organization: Organization | string | null;
   },
   options?: {
     /**

+ 3 - 1
static/app/utils/analytics/makeAnalyticsFunction.tsx

@@ -4,7 +4,9 @@ import {trackAnalyticsEventV2} from 'sentry/utils/analytics';
 
 const hasAnalyticsDebug = () => window.localStorage?.getItem('DEBUG_ANALYTICS') === '1';
 
-type OptionalOrg = {organization: Organization | null};
+type OptionalOrg = {
+  organization: Organization | string | null;
+};
 type Options = Parameters<Hooks['analytics:track-event-v2']>[1];
 
 /**