:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(early-access): email enrolled people when a feature goes GA (#120556)
Daniel Marchukeca3ee71f0b1
diff --git a/products/early_access_features/frontend/EarlyAccessFeature.tsx b/products/early_access_features/frontend/EarlyAccessFeature.tsxindex 391fa79baf8c..1c23d1fafcda 100644--- a/products/early_access_features/frontend/EarlyAccessFeature.tsx+++ b/products/early_access_features/frontend/EarlyAccessFeature.tsx@@ -82,11 +82,10 @@ import {} from 'products/error_tracking/frontend/components/Assignee/AssigneeDisplay'import { AssigneeSelect } from 'products/error_tracking/frontend/components/Assignee/AssigneeSelect'import { PersonDisplay } from 'products/persons/frontend/components/PersonDisplay'-import { MessageAudience } from 'products/workflows/frontend/MessageAudience/messageAudience'import { MessageAudienceButton } from 'products/workflows/frontend/MessageAudience/MessageAudienceButton'-import { draftMessage } from 'products/workflows/frontend/MessageAudience/messageDrafts'import { EarlyAccessFeatureLogicProps, earlyAccessFeatureLogic } from './earlyAccessFeatureLogic'+import { enrolledPeopleAudience } from './enrolledPeopleAudience'import { InstructionsModal } from './InstructionsModal'import { QuillEarlyAccessFeatureActions } from './QuillEarlyAccessFeatureActions'@@ -151,63 +150,6 @@ export const scene: SceneExport<EarlyAccessFeatureLogicProps> = {productKey: ProductKey.EARLY_ACCESS_FEATURES,}-function enrolledPeopleAudience(earlyAccessFeature: EarlyAccessFeatureType): MessageAudience {- const flagKey = earlyAccessFeature.feature_flag.key- return {- source: 'early_access',- properties: [- {- key: `$feature_enrollment/${flagKey}`,- type: PropertyFilterType.Person,- operator: PropertyOperator.Exact,- value: ['true'],- },- ],- broadcastName: `${earlyAccessFeature.name} is now available`,- broadcastEmail: draftMessage({- kind: 'feature_available',- featureName: earlyAccessFeature.name,- featureDescription: earlyAccessFeature.description,- }),- workflowEmail: draftMessage({- kind: 'feature_enrolled',- featureName: earlyAccessFeature.name,- featureDescription: earlyAccessFeature.description,- }),- draftSource: { source: 'early_access', source_id: earlyAccessFeature.id },- workflowTrigger: {- type: 'event',- filters: {- events: [- {- id: '$feature_enrollment_update',- name: '$feature_enrollment_update',- type: 'events',- order: 0,- properties: [- {- key: '$feature_flag',- value: [flagKey],- operator: PropertyOperator.Exact,- type: PropertyFilterType.Event,- },- // posthog-js sends a boolean here. Exact compiles to a string compare until the project- // has a Boolean definition for this property, so it would never match. Contains- // compares the stringified value, which works with or without that definition.- {- key: '$feature_enrollment',- value: 'true',- operator: PropertyOperator.IContains,- type: PropertyFilterType.Event,- },- ],- },- ],- },- },- }-}-export function EarlyAccessFeature({ id }: EarlyAccessFeatureLogicProps): JSX.Element {const {earlyAccessFeature,@@ -845,7 +787,7 @@ export function EarlyAccessFeature({ id }: EarlyAccessFeatureLogicProps): JSX.Elactions={<><MessageAudienceButton- audience={enrolledPeopleAudience(earlyAccessFeature)}+ audience={enrolledPeopleAudience(earlyAccessFeature, 'early_access')}label="Email opted-in users"size="medium"/>diff --git a/products/early_access_features/frontend/earlyAccessFeatureLogic.test.ts b/products/early_access_features/frontend/earlyAccessFeatureLogic.test.tsindex 01f15e891a8d..f90f0857026a 100644--- a/products/early_access_features/frontend/earlyAccessFeatureLogic.test.ts+++ b/products/early_access_features/frontend/earlyAccessFeatureLogic.test.ts@@ -4,6 +4,8 @@ import { router } from 'kea-router'/* oxlint-disable react-hooks/rules-of-hooks -- useMocks is a test helper, not a React hook */import { expectLogic } from 'kea-test-utils'+import { lemonToast } from '@posthog/lemon-ui'+import { preflightLogic } from 'scenes/PreflightCheck/preflightLogic'import { teamLogic } from 'scenes/teamLogic'@@ -11,6 +13,8 @@ import { useMocks } from '~/mocks/jest'import { initKeaTests } from '~/test/init'import { EarlyAccessFeatureStage, EarlyAccessFeatureType, FeatureFlagBasicType, Region } from '~/types'+import * as messageAudience from 'products/workflows/frontend/MessageAudience/messageAudience'+import { POSTHOG_TEAM_ID, earlyAccessFeatureLogic } from './earlyAccessFeatureLogic'import { earlyAccessFeaturesLogic } from './earlyAccessFeaturesLogic'@@ -113,6 +117,32 @@ describe('earlyAccessFeatureLogic', () => {expect(logic.values.isEditingFeature).toBe(false)})+ it.each([+ { from: EarlyAccessFeatureStage.Beta, to: EarlyAccessFeatureStage.GeneralAvailability, offered: true },+ { from: EarlyAccessFeatureStage.Beta, to: EarlyAccessFeatureStage.Alpha, offered: false },+ ])(+ 'offers to email opted-in users only on reaching general availability: $from to $to',+ async ({ from, to, offered }) => {+ const success = jest.spyOn(lemonToast, 'success')+ jest.spyOn(messageAudience, 'messageAudienceAccessDisabledReason').mockReturnValue(null)+ useMocks({+ get: { '/api/projects/:team_id/early_access_feature/:id': mockFeature({ stage: from }) },+ patch: { '/api/projects/:team_id/early_access_feature/:id': () => [200, mockFeature({ stage: to })] },+ })+ logic = earlyAccessFeatureLogic({ id: 'abc-123' })+ logic.mount()+ await expectLogic(logic).toDispatchActions(['loadEarlyAccessFeatureSuccess'])++ await expectLogic(logic, () => {+ logic.actions.saveEarlyAccessFeature({ ...logic.values.earlyAccessFeature, stage: to })+ }).toDispatchActions(['saveEarlyAccessFeatureSuccess'])++ const button = success.mock.calls.find(([message]) => message === 'Early access feature saved')?.[1]?.button+ expect(button?.label).toBe(offered ? 'Email opted-in users' : undefined)+ jest.restoreAllMocks()+ }+ )+it('deletes a feature, removes it from the list, and returns to the list page', async () => {let deleted = falseuseMocks({diff --git a/products/early_access_features/frontend/earlyAccessFeatureLogic.ts b/products/early_access_features/frontend/earlyAccessFeatureLogic.tsindex 4d134ff99914..70c3b1388f8a 100644--- a/products/early_access_features/frontend/earlyAccessFeatureLogic.ts+++ b/products/early_access_features/frontend/earlyAccessFeatureLogic.ts@@ -35,12 +35,22 @@ import {Region,} from '~/types'+import {+ captureMessageAudienceClicked,+ messageAudienceAccessDisabledReason,+} from 'products/workflows/frontend/MessageAudience/messageAudience'+import { openMessageAudience } from 'products/workflows/frontend/MessageAudience/messageAudienceWarnings'+import { earlyAccessFeaturesLogic } from './earlyAccessFeaturesLogic'+import { enrolledPeopleAudience } from './enrolledPeopleAudience'import { GAPromotionDialogContent } from './GAPromotionDialogContent'/** PostHog's own dogfooding project on US cloud — mirrors POSTHOG_TEAM_ID in the backend. */export const POSTHOG_TEAM_ID = 2+// pinned: the toast offered when a feature reaches general availability+const EARLY_ACCESS_GA_SOURCE = 'early_access_ga'+export const NEW_EARLY_ACCESS_FEATURE: NewEarlyAccessFeatureType = {name: '',description: '',@@ -505,7 +515,7 @@ export const earlyAccessFeatureLogic = kea<earlyAccessFeatureLogicType>([},],})),- listeners(({ actions, values }) => ({+ listeners(({ actions, values, selectors }) => ({saveEarlyAccessFeatureFailure: ({ errorObject }) => {// kea-loaders calls the failure action with (error.message, error), so:// `error` = the message string@@ -526,8 +536,28 @@ export const earlyAccessFeatureLogic = kea<earlyAccessFeatureLogicType>([}lemonToast.error('Could not save early access feature.')},- saveEarlyAccessFeatureSuccess: ({ earlyAccessFeature: _earlyAccessFeature }) => {- lemonToast.success('Early access feature saved')+ saveEarlyAccessFeatureSuccess: ({ earlyAccessFeature: _earlyAccessFeature }, _, __, previousState) => {+ const previousStage = selectors.originalEarlyAccessFeatureStage(previousState)+ const reachedGeneralAvailability =+ !!previousStage &&+ previousStage !== EarlyAccessFeatureStage.GeneralAvailability &&+ _earlyAccessFeature.stage === EarlyAccessFeatureStage.GeneralAvailability+ lemonToast.success('Early access feature saved', {+ button:+ reachedGeneralAvailability && !messageAudienceAccessDisabledReason()+ ? {+ label: 'Email opted-in users',+ dataAttr: 'early-access-ga-broadcast',+ action: () => {+ captureMessageAudienceClicked(EARLY_ACCESS_GA_SOURCE, 'broadcast')+ void openMessageAudience(+ enrolledPeopleAudience(_earlyAccessFeature, EARLY_ACCESS_GA_SOURCE),+ 'broadcast'+ )+ },+ }+ : undefined,+ })earlyAccessFeaturesLogic.findMounted()?.actions.loadEarlyAccessFeatures()if (_earlyAccessFeature.id) {refreshTreeItem('early_access_feature', _earlyAccessFeature.id)diff --git a/products/early_access_features/frontend/enrolledPeopleAudience.ts b/products/early_access_features/frontend/enrolledPeopleAudience.tsnew file mode 100644index 000000000000..fc8b089f82ab--- /dev/null+++ b/products/early_access_features/frontend/enrolledPeopleAudience.ts@@ -0,0 +1,61 @@+import { EarlyAccessFeatureType, PropertyFilterType, PropertyOperator } from '~/types'++import { MessageAudience } from 'products/workflows/frontend/MessageAudience/messageAudience'+import { draftMessage } from 'products/workflows/frontend/MessageAudience/messageDrafts'++export function enrolledPeopleAudience(earlyAccessFeature: EarlyAccessFeatureType, source: string): MessageAudience {+ const flagKey = earlyAccessFeature.feature_flag.key+ return {+ source,+ properties: [+ {+ key: `$feature_enrollment/${flagKey}`,+ type: PropertyFilterType.Person,+ operator: PropertyOperator.Exact,+ value: ['true'],+ },+ ],+ broadcastName: `${earlyAccessFeature.name} is now available`,+ broadcastEmail: draftMessage({+ kind: 'feature_available',+ featureName: earlyAccessFeature.name,+ featureDescription: earlyAccessFeature.description,+ }),+ workflowEmail: draftMessage({+ kind: 'feature_enrolled',+ featureName: earlyAccessFeature.name,+ featureDescription: earlyAccessFeature.description,+ }),+ draftSource: { source: 'early_access', source_id: earlyAccessFeature.id },+ workflowTrigger: {+ type: 'event',+ filters: {+ events: [+ {+ id: '$feature_enrollment_update',+ name: '$feature_enrollment_update',+ type: 'events',+ order: 0,+ properties: [+ {+ key: '$feature_flag',+ value: [flagKey],+ operator: PropertyOperator.Exact,+ type: PropertyFilterType.Event,+ },+ // posthog-js sends a boolean here. Exact compiles to a string compare until the project+ // has a Boolean definition for this property, so it would never match. Contains+ // compares the stringified value, which works with or without that definition.+ {+ key: '$feature_enrollment',+ value: 'true',+ operator: PropertyOperator.IContains,+ type: PropertyFilterType.Event,+ },+ ],+ },+ ],+ },+ },+ }+}