-
Notifications
You must be signed in to change notification settings - Fork 145
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
chore: send survey partial responses event #1788
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -16,7 +16,7 @@ const window = _window as Window & typeof globalThis | |||||
const document = _document as Document | ||||||
const SurveySeenPrefix = 'seenSurvey_' | ||||||
|
||||||
const logger = createLogger('[Surveys]') | ||||||
const logger = createLogger('[Surveys Utils]') | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
any reason to change it? its easier to filter logs by [Surveys] rather than many other options There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. those logs are just not working, i was just testing it out to make sure. the only logs who are working are from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. quickfix? :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not that quick (really confused why it's not working) but I do wanna take a look |
||||||
|
||||||
export const SURVEY_DEFAULT_Z_INDEX = 2147483647 | ||||||
|
||||||
|
@@ -563,19 +563,41 @@ export const createShadow = (styleSheet: string, surveyId: string, element?: Ele | |||||
return shadow | ||||||
} | ||||||
|
||||||
export const sendSurveyEvent = ( | ||||||
responses: Record<string, string | number | string[] | null> = {}, | ||||||
survey: Survey, | ||||||
type SendSurveyEventArgs = { | ||||||
responses: Record<string, string | number | string[] | null> | ||||||
survey: Survey | ||||||
posthog?: PostHog | ||||||
) => { | ||||||
isSurveyCompleted: boolean | ||||||
surveySubmissionId: string | ||||||
} | ||||||
|
||||||
export const sendSurveyEvent = ({ | ||||||
responses, | ||||||
survey, | ||||||
posthog, | ||||||
isSurveyCompleted, | ||||||
surveySubmissionId, | ||||||
}: SendSurveyEventArgs) => { | ||||||
if (!posthog) { | ||||||
logger.error('[survey sent] event not captured, PostHog instance not found.') | ||||||
return | ||||||
} | ||||||
if (!isSurveyCompleted && !survey.enable_partial_responses) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this bit of logic here should be on the calling side There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah we also check for survey complete on the callsite to fire the survey sent popup callback, so better to avoid dupe checks and keep in a single place |
||||||
return | ||||||
} | ||||||
localStorage.setItem(getSurveySeenKey(survey), 'true') | ||||||
|
||||||
logger.info('[PostHog Surveys] survey partial response payload', { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
createLogger already has a prefix |
||||||
surveyId: survey.id, | ||||||
surveyName: survey.name, | ||||||
surveyCompleted: isSurveyCompleted, | ||||||
surveySubmissionId, | ||||||
responses, | ||||||
}) | ||||||
|
||||||
posthog.capture('survey sent', { | ||||||
$survey_name: survey.name, | ||||||
$survey_completed: isSurveyCompleted, | ||||||
$survey_id: survey.id, | ||||||
$survey_iteration: survey.current_iteration, | ||||||
$survey_iteration_start_date: survey.current_iteration_start_date, | ||||||
|
@@ -585,12 +607,16 @@ export const sendSurveyEvent = ( | |||||
index, | ||||||
})), | ||||||
sessionRecordingUrl: posthog.get_session_replay_url?.(), | ||||||
$survey_submission_id: surveySubmissionId, | ||||||
...responses, | ||||||
$set: { | ||||||
[getSurveyInteractionProperty(survey, 'responded')]: true, | ||||||
}, | ||||||
}) | ||||||
window.dispatchEvent(new Event('PHSurveySent')) | ||||||
|
||||||
if (isSurveyCompleted) { | ||||||
window.dispatchEvent(new Event('PHSurveySent')) | ||||||
} | ||||||
} | ||||||
|
||||||
export const dismissedSurveyEvent = (survey: Survey, posthog?: PostHog, readOnly?: boolean) => { | ||||||
|
@@ -742,6 +768,7 @@ interface SurveyContextProps { | |||||
isPopup: boolean | ||||||
onPreviewSubmit: (res: string | string[] | number | null) => void | ||||||
onPopupSurveySent: () => void | ||||||
surveySubmissionId: string | ||||||
} | ||||||
|
||||||
export const SurveyContext = createContext<SurveyContextProps>({ | ||||||
|
@@ -751,6 +778,7 @@ export const SurveyContext = createContext<SurveyContextProps>({ | |||||
isPopup: true, | ||||||
onPreviewSubmit: () => {}, | ||||||
onPopupSurveySent: () => {}, | ||||||
surveySubmissionId: '', | ||||||
}) | ||||||
|
||||||
interface RenderProps { | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: surveyResponseId is regenerated on every render due to useMemo dependencies. Should be stored in state or ref to maintain consistency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No idea if this stands but this would mean a new uuid on every render right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not correct, as
uuidv7()
is a stable function (outside of preact component lifecycle)it would only change when SurveyPopup is unmounted then rendered again, as expected
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could it be that the user answers 1 question, refresh the page, generates another uuid, and answers the 2nd question?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or rather, how do we keep track of the current state of responses if the user refresh the page, comes back later, etc? is that gonna be an issue? (eg, even if starting from zero, having multiple answers for the same question, with a different uuid)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
than the survey will not be shown, as after one question is answered, it's marked as if it is responded
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we'd have to do a more complex logic to handle a bigger user session that might involve refreshing. because, right now, if they answer one question, at this point the survey is marked as responded, so once it's gone, no longer it'll show up
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems like we should address then, because previously, the user had a chance to answer the full survey, even if from the very beginning (annoying but possible).
now if the user just goes to another page (that is not a match anymore and survey is closed), or refreshes the page, the user cant answer anything anymore, leading to maybe an even poorer experience than before, with lots of surveys half answered
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revisiting this discussion, so we're talking about the case:
while it is not ideal, i'm not sure if we should optimize for this case specifically. we can though, might involve however keeping the surveyResponseId on the session data until it's fully answered.
however, it'll also require a lot of logic changes on other parts, like showing a survey that was already in progress, which is not exactly trivial.
I'd instead release this as is, get a few people to early access it, and see if this feedback will happen again. what do you think? we have plenty of customers who'd like partial responses so we can find customers to iterate on it with them