Browse Source

feat(growth): adds analytics:track-event-v2 hook (#27551)

This PR adds the new analytics:track-event-v2 hook definition that is used in this getsentry PR: getsentry/getsentry#5947. A more detailed discussion is found there.
Stephen Cefali 3 years ago
parent
commit
3b2fd05a7c
2 changed files with 48 additions and 1 deletions
  1. 1 0
      static/app/stores/hookStore.tsx
  2. 47 1
      static/app/types/hooks.tsx

+ 1 - 0
static/app/stores/hookStore.tsx

@@ -13,6 +13,7 @@ const validHookNames = new Set<HookName>([
   'analytics:init-user',
   'analytics:track-adhoc-event',
   'analytics:track-event',
+  'analytics:track-event-v2',
   'analytics:log-experiment',
   'component:disabled-member',
   'component:disabled-member-tooltip',

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

@@ -5,7 +5,14 @@ import {ChildrenRenderFn} from 'app/components/acl/feature';
 import DateRange from 'app/components/organizations/timeRangeSelector/dateRange';
 import SelectorItems from 'app/components/organizations/timeRangeSelector/dateRange/selectorItems';
 import SidebarItem from 'app/components/sidebar/sidebarItem';
-import {IntegrationProvider, Member, Organization, Project, User} from 'app/types';
+import {
+  IntegrationProvider,
+  LightWeightOrganization,
+  Member,
+  Organization,
+  Project,
+  User,
+} from 'app/types';
 import {ExperimentKey} from 'app/types/experiments';
 import {NavigationItem, NavigationSection} from 'app/views/settings/types';
 
@@ -89,6 +96,7 @@ export type CustomizationHooks = {
 export type AnalyticsHooks = {
   'analytics:init-user': AnalyticsInitUser;
   'analytics:track-event': AnalyticsTrackEvent;
+  'analytics:track-event-v2': AnalyticsTrackEventV2;
   'analytics:track-adhoc-event': AnalyticsTrackAdhocEvent;
   'analytics:log-experiment': AnalyticsLogExperiment;
   'metrics:event': MetricsEvent;
@@ -242,6 +250,44 @@ type AnalyticsTrackEvent = (opts: {
   [key: string]: any;
 }) => void;
 
+/**
+ * Trigger analytics tracking in the hook store.
+ */
+type AnalyticsTrackEventV2 = (
+  data: {
+    /**
+     * The Reload event key.
+     */
+    eventKey: string;
+    /**
+     * The Amplitude event name. Set to null if event should not go to Amplitude.
+     */
+    eventName: string | null;
+
+    organization: LightWeightOrganization | null;
+    /**
+     * Arbitrary data to track
+     */
+    [key: string]: any;
+  },
+  options: {
+    /**
+     * If true, send the event to marketing analytics
+     */
+    sendMarketing?: boolean;
+    /**
+     * If true, starts an analytics session. This session can be used
+     * to construct funnels. The start of the funnel should have
+     * startSession set to true.
+     */
+    startSession?: boolean;
+    /**
+     * An arbitrary function to map the parameters to new parameters
+     */
+    mapValuesFn?: (params: Record<string, any>) => Record<string, any>;
+  }
+) => void;
+
 /**
  * Trigger ad hoc analytics tracking in the hook store.
  */