Skip to content

Commit

Permalink
fix: align the survey reasons to the survey in posthog (#24197)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
zlwaterfield and github-actions[bot] authored Aug 6, 2024
1 parent ce49493 commit 381d4b8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
4 changes: 2 additions & 2 deletions cypress/e2e/billing.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ describe('Billing', () => {
expect(matchingEvent.properties.$survey_id).to.equal(UNSUBSCRIBE_SURVEY_ID)
expect(matchingEvent.properties.$survey_response).to.equal('Product analytics')
expect(matchingEvent.properties.$survey_response_1).to.equal('product_analytics')
expect(matchingEvent.properties.$survey_reasons.length).to.equal(1)
expect(matchingEvent.properties.$survey_reasons[0]).to.equal('Too expensive')
expect(matchingEvent.properties.$survey_response_2.length).to.equal(1)
expect(matchingEvent.properties.$survey_response_2[0]).to.equal('Too expensive')
})

cy.get('.LemonModal').should('not.exist')
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/scenes/billing/UnsubscribeSurveyModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export const UnsubscribeSurveyModal = ({
key={reason}
label={reason}
dataAttr={`unsubscribe-reason-${reason.toLowerCase().replace(' ', '-')}`}
checked={surveyResponse['$survey_reasons'].includes(reason)}
checked={surveyResponse['$survey_response_2'].includes(reason)}
onChange={() => toggleSurveyReason(reason)}
className="w-full"
labelClassName="w-full"
Expand Down
20 changes: 14 additions & 6 deletions frontend/src/scenes/billing/billingProductLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,19 @@ export const billingProductLogic = kea<billingProductLogicType>([
},
],
surveyResponse: [
{ $survey_reasons: [], $survey_response: '' } as { $survey_reasons: string[]; $survey_response: string },
{ $survey_response_2: [], $survey_response: '' } as {
$survey_response_2: string[]
$survey_response: string
},
{
setSurveyResponse: (state, { key, value }) => {
return { ...state, [key]: value }
},
toggleSurveyReason: (state, { reason }) => {
const reasons = state.$survey_reasons.includes(reason)
? state.$survey_reasons.filter((r) => r !== reason)
: [...state.$survey_reasons, reason]
return { ...state, $survey_reasons: reasons }
const reasons = state.$survey_response_2.includes(reason)
? state.$survey_response_2.filter((r) => r !== reason)
: [...state.$survey_response_2, reason]
return { ...state, $survey_response_2: reasons }
},
},
],
Expand Down Expand Up @@ -281,6 +284,11 @@ export const billingProductLogic = kea<billingProductLogicType>([
actions.setSurveyID(surveyID)
},
reportSurveySent: ({ surveyID, surveyResponse }) => {
// @note(zach): this is submitting to https://us.posthog.com/project/2/surveys/018b6e13-590c-0000-decb-c727a2b3f462?edit=true
// $survey_response: open text response
// $survey_response_1: this is the product type
// $survey_response_2: list of reasons
// The order is due to the form being built before reasons we're supported. Please do not change the order.
posthog.capture('survey sent', {
$survey_id: surveyID,
...surveyResponse,
Expand All @@ -295,7 +303,7 @@ export const billingProductLogic = kea<billingProductLogicType>([
},
deactivateProductSuccess: async (_, breakpoint) => {
if (!values.unsubscribeError) {
const hasSurveyReasons = values.surveyResponse['$survey_reasons']?.length > 0
const hasSurveyReasons = values.surveyResponse['$survey_response_2']?.length > 0
const textAreaNotEmpty = values.surveyResponse['$survey_response']?.length > 0
const shouldReportSurvey = hasSurveyReasons || textAreaNotEmpty
shouldReportSurvey
Expand Down

0 comments on commit 381d4b8

Please sign in to comment.