: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(error-tracking): offer to email affected people on resolve (#120557)
Daniel Marchuk80fbeefa7a72
diff --git a/products/error_tracking/frontend/components/IssueActions/issueActionsLogic.tsx b/products/error_tracking/frontend/components/IssueActions/issueActionsLogic.tsxindex 9dafc190f833..dd108e826698 100644--- a/products/error_tracking/frontend/components/IssueActions/issueActionsLogic.tsx+++ b/products/error_tracking/frontend/components/IssueActions/issueActionsLogic.tsx@@ -262,14 +262,19 @@ export const issueActionsLogic = kea<issueActionsLogicType>([})},updateIssueStatus: async ({ id, status }) => {- await runMutation('updateIssueStatus', async () => {- posthog.capture('error_tracking_issue_update_status', {- status,- issue_id: id,- ui_source: 'issue_actions',- })- await api.errorTracking.updateIssue(id, { status })- })+ await runMutation(+ 'updateIssueStatus',+ async () => {+ posthog.capture('error_tracking_issue_update_status', {+ status,+ issue_id: id,+ ui_source: 'issue_actions',+ })+ await api.errorTracking.updateIssue(id, { status })+ },+ undefined,+ id+ )},updateIssueSeverity: async ({ id, severity }) => {await runMutation(diff --git a/products/error_tracking/frontend/scenes/ErrorTrackingIssueScene/ScenePanel/issueAffectedBroadcastLogic.test.ts b/products/error_tracking/frontend/scenes/ErrorTrackingIssueScene/ScenePanel/issueAffectedBroadcastLogic.test.tsindex 7d1824aa9b60..06831ebe5614 100644--- a/products/error_tracking/frontend/scenes/ErrorTrackingIssueScene/ScenePanel/issueAffectedBroadcastLogic.test.ts+++ b/products/error_tracking/frontend/scenes/ErrorTrackingIssueScene/ScenePanel/issueAffectedBroadcastLogic.test.ts@@ -1,10 +1,14 @@import { router } from 'kea-router'import { expectLogic } from 'kea-test-utils'+import { lemonToast } from '@posthog/lemon-ui'++import { hogqlQuery } from '~/queries/query'import { initKeaTests } from '~/test/init'import { cohortsCreate } from 'products/cohorts/frontend/generated/api'import { parseBroadcastAudiencePrefill } from 'products/workflows/frontend/Broadcasts/broadcastAudiencePrefill'+import * as messageAudience from 'products/workflows/frontend/MessageAudience/messageAudience'import { issueAffectedBroadcastLogic } from './issueAffectedBroadcastLogic'@@ -12,7 +16,10 @@ jest.mock('products/cohorts/frontend/generated/api', () => ({cohortsCreate: jest.fn(),}))+jest.mock('~/queries/query', () => ({ hogqlQuery: jest.fn() }))+const mockCohortsCreate = jest.mocked(cohortsCreate)+const mockHogqlQuery = jest.mocked(hogqlQuery)describe('issueAffectedBroadcastLogic', () => {beforeEach(() => {@@ -52,4 +59,31 @@ describe('issueAffectedBroadcastLogic', () => {])logic.unmount()})++ it.each([+ { scenario: 'people with an email were hit', count: () => Promise.resolve([3, 2]), offered: true },+ { scenario: 'no one hit has an email', count: () => Promise.resolve([3, 0]), offered: false },+ { scenario: 'the count fails', count: () => Promise.reject(new Error('timeout')), offered: false },+ ])('offers the fixed email after resolve only when $scenario', async ({ count, offered }) => {+ jest.spyOn(messageAudience, 'messageAudienceAccessDisabledReason').mockReturnValue(null)+ mockHogqlQuery.mockImplementation(async () => ({ results: [await count()] }) as never)+ const success = jest.spyOn(lemonToast, 'success')+ const logic = issueAffectedBroadcastLogic({ issueId: 'issue-1', issueName: 'Checkout timeout' })+ logic.mount()++ await expectLogic(logic, () => {+ logic.actions.offerAfterResolve()+ }).toFinishAllListeners()++ expect(success).toHaveBeenCalledTimes(offered ? 1 : 0)+ if (offered) {+ success.mock.calls[0][1]?.button?.action?.()+ expect(logic.values.isModalOpen).toBe(true)+ await expectLogic(logic, () => {+ logic.actions.createAudience()+ }).toDispatchActions(['createAudienceSuccess'])+ expect(router.values.currentLocation.searchParams.source).toEqual('error_tracking_resolved')+ }+ logic.unmount()+ })})diff --git a/products/error_tracking/frontend/scenes/ErrorTrackingIssueScene/ScenePanel/issueAffectedBroadcastLogic.ts b/products/error_tracking/frontend/scenes/ErrorTrackingIssueScene/ScenePanel/issueAffectedBroadcastLogic.tsindex 20bd54039900..3fdebe15dea5 100644--- a/products/error_tracking/frontend/scenes/ErrorTrackingIssueScene/ScenePanel/issueAffectedBroadcastLogic.ts+++ b/products/error_tracking/frontend/scenes/ErrorTrackingIssueScene/ScenePanel/issueAffectedBroadcastLogic.ts@@ -4,7 +4,7 @@ import { router } from 'kea-router'import { lemonToast } from '@posthog/lemon-ui'-import { truncate } from 'lib/utils/strings'+import { pluralize, truncate } from 'lib/utils/strings'import { teamLogic } from 'scenes/teamLogic'import { hogqlQuery } from '~/queries/query'@@ -16,6 +16,7 @@ import type { CohortApi } from 'products/cohorts/frontend/generated/api.schemas'import {captureMessageAudienceClicked,cohortAudienceProperties,+ messageAudienceAccessDisabledReason,messageAudienceUrl,} from 'products/workflows/frontend/MessageAudience/messageAudience'import { loadMessageAudienceWarnings } from 'products/workflows/frontend/MessageAudience/messageAudienceWarnings'@@ -24,6 +25,7 @@ import { draftMessage } from 'products/workflows/frontend/MessageAudience/messagexport const AFFECTED_LOOKBACK_DAYS = 30// pinned: sent as the broadcast's entry_source and the click event's source, so renaming it splits the historyconst SOURCE = 'error_tracking_affected'+const RESOLVED_SOURCE = 'error_tracking_resolved'const MAX_NAME_LENGTH = 200export interface IssueAffectedBroadcastLogicProps {@@ -54,6 +56,7 @@ export interface issueAffectedBroadcastLogicValues {isModalOpen: booleansendWarnings: string[]sendWarningsLoading: boolean+ source: string}// Generated by kea-typegen. Update if you're an agent, ignore if you're human.@@ -112,9 +115,15 @@ export interface issueAffectedBroadcastLogicActions {sendWarnings: string[]payload?: any}+ offerAfterResolve: () => {+ value: true+ }openModal: () => {value: true}+ openModalAfterResolve: () => {+ value: true+ }}// Generated by kea-typegen. Update if you're an agent, ignore if you're human.@@ -145,7 +154,9 @@ export const issueAffectedBroadcastLogic = kea<issueAffectedBroadcastLogicType>(actions({openModal: true,+ openModalAfterResolve: true,closeModal: true,+ offerAfterResolve: true,}),reducers({@@ -153,9 +164,17 @@ export const issueAffectedBroadcastLogic = kea<issueAffectedBroadcastLogicType>(false,{openModal: () => true,+ openModalAfterResolve: () => true,closeModal: () => false,},],+ source: [+ SOURCE as string,+ {+ openModal: () => SOURCE,+ openModalAfterResolve: () => RESOLVED_SOURCE,+ },+ ],countFailed: [false,{@@ -199,13 +218,49 @@ export const issueAffectedBroadcastLogic = kea<issueAffectedBroadcastLogicType>(],})),- listeners(({ actions, props }) => ({+ listeners(({ actions, props, values, cache }) => ({openModal: () => {// The click on the entry point, before any outcome, so abandoned attempts count too.captureMessageAudienceClicked(SOURCE, 'broadcast')actions.loadAffectedCount()actions.loadSendWarnings()},+ openModalAfterResolve: () => {+ captureMessageAudienceClicked(RESOLVED_SOURCE, 'broadcast')+ actions.loadAffectedCount()+ actions.loadSendWarnings()+ },+ offerAfterResolve: () => {+ if (messageAudienceAccessDisabledReason()) {+ return+ }+ cache.offerOnCount = true+ actions.loadAffectedCount()+ },+ loadAffectedCountSuccess: ({ affectedCount }) => {+ if (!cache.offerOnCount) {+ return+ }+ cache.offerOnCount = false+ if (!affectedCount.withEmail) {+ return+ }+ lemonToast.success(+ `Issue resolved. ${pluralize(affectedCount.withEmail, 'person', 'people')} with an email address hit it in the last ${AFFECTED_LOOKBACK_DAYS} days.`,+ {+ // The default id is a hash of the message, so two issues with the same count would share one toast.+ toastId: `issue-resolved-${props.issueId}`,+ button: {+ label: "Tell them it's fixed",+ dataAttr: 'issue-resolved-broadcast',+ action: () => issueAffectedBroadcastLogic.findMounted(props)?.actions.openModalAfterResolve(),+ },+ }+ )+ },+ loadAffectedCountFailure: () => {+ cache.offerOnCount = false+ },createAudienceSuccess: ({ audienceCohort }) => {if (!audienceCohort) {return@@ -215,7 +270,7 @@ export const issueAffectedBroadcastLogic = kea<issueAffectedBroadcastLogicType>(messageAudienceUrl({properties: cohortAudienceProperties(audienceCohort),- source: SOURCE,+ source: values.source,broadcastName: truncate(`We fixed ${props.issueName || 'an error'}`, MAX_NAME_LENGTH),broadcastEmail: draftMessage({ kind: 'issue_fixed' }),draftSource: { source: 'error_tracking', source_id: props.issueId },diff --git a/products/error_tracking/frontend/scenes/ErrorTrackingIssueScene/errorTrackingIssueSceneLogic.ts b/products/error_tracking/frontend/scenes/ErrorTrackingIssueScene/errorTrackingIssueSceneLogic.tsindex 9c0944db4293..88349c489e6f 100644--- a/products/error_tracking/frontend/scenes/ErrorTrackingIssueScene/errorTrackingIssueSceneLogic.ts+++ b/products/error_tracking/frontend/scenes/ErrorTrackingIssueScene/errorTrackingIssueSceneLogic.ts@@ -67,6 +67,7 @@ import { errorTrackingIssueEventsQuery, errorTrackingIssueQuery } from '../../quimport { syncSearchParams } from '../../utils'import { ERROR_TRACKING_DETAILS_RESOLUTION, dateRangeToIsoBounds } from '../../utils'import { linkedReportsLogic } from './linkedReportsLogic'+import { issueAffectedBroadcastLogic } from './ScenePanel/issueAffectedBroadcastLogic'export interface ErrorTrackingIssueSceneLogicProps {id: ErrorTrackingIssue['id']@@ -1099,6 +1100,17 @@ export const errorTrackingIssueSceneLogic = kea<errorTrackingIssueSceneLogicType)}},+ [issueActionsLogic.actionTypes.mutationSuccess]: ({ mutationName, issueId }) => {+ if (+ mutationName === 'updateIssueStatus' &&+ issueId === props.id &&+ values.issue?.status === 'resolved'+ ) {+ issueAffectedBroadcastLogic+ .findMounted({ issueId: props.id, issueName: values.issue.name })+ ?.actions.offerAfterResolve()+ }+ },}}),