Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: align the survey reasons to the survey in posthog #24197

Merged
merged 7 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 @@ -280,6 +283,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 @@ -294,7 +302,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
Loading