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

feat(surveys): add configurable delay to popup surveys #22780

Merged
merged 87 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
bf16859
initial commit
dmarticus Jun 6, 2024
5b2c1d5
Update UI snapshots for `chromium` (2)
github-actions[bot] Jun 6, 2024
59d5f71
Update UI snapshots for `chromium` (2)
github-actions[bot] Jun 7, 2024
d19810a
Update UI snapshots for `chromium` (1)
github-actions[bot] Jun 7, 2024
1e3c800
Update UI snapshots for `chromium` (1)
github-actions[bot] Jun 7, 2024
c48c4f6
Update UI snapshots for `chromium` (2)
github-actions[bot] Jun 7, 2024
728eef7
Update UI snapshots for `chromium` (2)
github-actions[bot] Jun 7, 2024
456c864
Update UI snapshots for `chromium` (2)
github-actions[bot] Jun 7, 2024
d2a526d
Update UI snapshots for `chromium` (2)
github-actions[bot] Jun 7, 2024
1531f6f
Update UI snapshots for `chromium` (2)
github-actions[bot] Jun 7, 2024
9afbdc5
Update UI snapshots for `chromium` (2)
github-actions[bot] Jun 7, 2024
64e68b8
fixing the ui a bit
dmarticus Jun 7, 2024
46a4b47
Merge branch 'feat/delay-survey-popup' of github.com:PostHog/posthog …
dmarticus Jun 7, 2024
d3ca624
write tests for the survey_popup_delay api
dmarticus Jun 7, 2024
1557789
remove todos that were todone
dmarticus Jun 7, 2024
f77b0b7
Update UI snapshots for `chromium` (2)
github-actions[bot] Jun 7, 2024
e6e8bad
Update UI snapshots for `chromium` (2)
github-actions[bot] Jun 7, 2024
c0cc810
Update UI snapshots for `chromium` (2)
github-actions[bot] Jun 7, 2024
c2eef3a
Update UI snapshots for `chromium` (2)
github-actions[bot] Jun 8, 2024
69e3ff3
Update UI snapshots for `chromium` (2)
github-actions[bot] Jun 8, 2024
02e6ace
Update UI snapshots for `chromium` (2)
github-actions[bot] Jun 8, 2024
1a096af
merge main
dmarticus Jun 18, 2024
daab9c7
Update UI snapshots for `chromium` (2)
github-actions[bot] Jun 18, 2024
cb1d5db
Update UI snapshots for `chromium` (2)
github-actions[bot] Jun 18, 2024
4ea8f8c
Update UI snapshots for `chromium` (2)
github-actions[bot] Jun 18, 2024
b31f67c
Update frontend/src/scenes/surveys/SurveyCustomization.tsx
dmarticus Jun 18, 2024
207ebc7
Update frontend/src/types.ts
dmarticus Jun 18, 2024
45aeb93
Update UI snapshots for `chromium` (1)
github-actions[bot] Jun 18, 2024
902352a
Update UI snapshots for `chromium` (2)
github-actions[bot] Jun 18, 2024
38273c1
Update UI snapshots for `chromium` (1)
github-actions[bot] Jun 18, 2024
7f82937
Update UI snapshots for `chromium` (2)
github-actions[bot] Jun 18, 2024
3414f79
code review feedback
dmarticus Jun 18, 2024
e973579
add hour max to survey delay
dmarticus Jun 18, 2024
dd015db
Merge branch 'feat/delay-survey-popup' of github.com:PostHog/posthog …
dmarticus Jun 18, 2024
a73184c
Merge branch 'master' into feat/delay-survey-popup
dmarticus Jun 18, 2024
c127648
Update UI snapshots for `chromium` (1)
github-actions[bot] Jun 18, 2024
cd7cc7f
Merge branch 'master' into feat/delay-survey-popup
dmarticus Jun 18, 2024
1928ead
Update UI snapshots for `chromium` (1)
github-actions[bot] Jun 18, 2024
926be64
Update UI snapshots for `chromium` (1)
github-actions[bot] Jun 18, 2024
f472115
Update UI snapshots for `chromium` (2)
github-actions[bot] Jun 18, 2024
b9d82f0
Update UI snapshots for `chromium` (2)
github-actions[bot] Jun 18, 2024
9bddb36
Update UI snapshots for `chromium` (1)
github-actions[bot] Jun 18, 2024
62e8e7d
Update UI snapshots for `chromium` (1)
github-actions[bot] Jun 18, 2024
1206c9e
Update UI snapshots for `chromium` (2)
github-actions[bot] Jun 18, 2024
d2a4104
Update UI snapshots for `chromium` (2)
github-actions[bot] Jun 19, 2024
bf7e465
Update UI snapshots for `chromium` (2)
github-actions[bot] Jun 19, 2024
57a6804
Update UI snapshots for `chromium` (1)
github-actions[bot] Jun 19, 2024
3533c40
Update UI snapshots for `chromium` (2)
github-actions[bot] Jun 19, 2024
6c06b35
Update UI snapshots for `chromium` (1)
github-actions[bot] Jun 19, 2024
8c95e8e
Update UI snapshots for `chromium` (1)
github-actions[bot] Jun 19, 2024
25403ff
Update UI snapshots for `chromium` (2)
github-actions[bot] Jun 19, 2024
392c01e
not sure how this was reverted, but it's back now
dmarticus Jun 19, 2024
28461a1
Merge branch 'feat/delay-survey-popup' of github.com:PostHog/posthog …
dmarticus Jun 19, 2024
df9c769
was this it?
dmarticus Jun 19, 2024
45815fa
was this it?
dmarticus Jun 19, 2024
e7d250e
Update UI snapshots for `chromium` (1)
github-actions[bot] Jun 19, 2024
c4a77b5
Update UI snapshots for `chromium` (1)
github-actions[bot] Jun 19, 2024
aa64630
Update UI snapshots for `chromium` (1)
github-actions[bot] Jun 19, 2024
c46cc62
Update UI snapshots for `chromium` (2)
github-actions[bot] Jun 19, 2024
69c45ce
Update UI snapshots for `chromium` (1)
github-actions[bot] Jun 20, 2024
25e342c
Update UI snapshots for `chromium` (2)
github-actions[bot] Jun 20, 2024
b5d277d
Update UI snapshots for `chromium` (2)
github-actions[bot] Jun 20, 2024
e48389f
Update UI snapshots for `chromium` (2)
github-actions[bot] Jun 20, 2024
60c9ba3
Merge branch 'master' into feat/delay-survey-popup
dmarticus Jun 24, 2024
837e446
Update query snapshots
github-actions[bot] Jun 24, 2024
7d89379
Update query snapshots
github-actions[bot] Jun 24, 2024
fdb4f6a
Update query snapshots
github-actions[bot] Jun 24, 2024
7aa6782
Update query snapshots
github-actions[bot] Jun 24, 2024
033b6bd
use latest version of posthog-js to activate the survey popup delay f…
dmarticus Jun 24, 2024
220a291
Merge branch 'feat/delay-survey-popup' of github.com:PostHog/posthog …
dmarticus Jun 24, 2024
45f9546
forgot to commit the lockfile
dmarticus Jun 24, 2024
0ba5e0f
Merge branch 'master' into feat/delay-survey-popup
dmarticus Jun 24, 2024
de4fac0
Update query snapshots
github-actions[bot] Jun 24, 2024
a8c7f6a
Update UI snapshots for `chromium` (2)
github-actions[bot] Jun 24, 2024
2354c1f
Update query snapshots
github-actions[bot] Jun 24, 2024
fa28581
Update UI snapshots for `chromium` (2)
github-actions[bot] Jun 24, 2024
f537add
Update query snapshots
github-actions[bot] Jun 24, 2024
bf0db84
Update query snapshots
github-actions[bot] Jun 24, 2024
ca1d4a9
Update query snapshots
github-actions[bot] Jun 24, 2024
260e930
Update query snapshots
github-actions[bot] Jun 24, 2024
f162eef
Update query snapshots
github-actions[bot] Jun 24, 2024
2ee6ce7
Update query snapshots
github-actions[bot] Jun 24, 2024
7f9b27f
Update UI snapshots for `chromium` (2)
github-actions[bot] Jun 24, 2024
dfcb609
Update UI snapshots for `chromium` (2)
github-actions[bot] Jun 24, 2024
ec3673b
Update query snapshots
github-actions[bot] Jun 24, 2024
262f597
Update query snapshots
github-actions[bot] Jun 24, 2024
4669828
Update query snapshots
github-actions[bot] Jun 24, 2024
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
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.
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.
35 changes: 35 additions & 0 deletions frontend/src/scenes/surveys/SurveyCustomization.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { LemonButton, LemonCheckbox, LemonDialog, LemonInput, LemonSelect } from
import { useActions, useValues } from 'kea'
import { PayGateMini } from 'lib/components/PayGateMini/PayGateMini'
import { upgradeModalLogic } from 'lib/components/UpgradeModal/upgradeModalLogic'
import { LemonField } from 'lib/lemon-ui/LemonField'
import { surveyLogic } from 'scenes/surveys/surveyLogic'

import {
Expand Down Expand Up @@ -162,6 +163,40 @@ export function Customization({ appearance, surveyQuestionItem, onAppearanceChan
checked={appearance?.shuffleQuestions}
/>
</div>
<div className="mt-1">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Up to you, but we might want to gate by a feature flag here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, I'm electing to not feature flag this, because we

  1. don't have that many users on surveys, so a staged rollout here seems like overkill
  2. this is really easy to revert and doesn't leave many lasting (and scary) changes to our schema, etc, if we do.

<LemonField.Pure>
<div className="flex flex-row gap-2 items-center font-medium">
<LemonCheckbox
checked={!!appearance?.surveyPopupDelaySeconds}
onChange={(checked) => {
const surveyPopupDelaySeconds = checked ? 5 : undefined
onAppearanceChange({ ...appearance, surveyPopupDelaySeconds })
}}
/>
Delay survey popup after page load by at least{' '}
<LemonInput
type="number"
data-attr="survey-popup-delay-input"
size="small"
min={1}
max={3600}
value={appearance?.surveyPopupDelaySeconds || NaN}
onChange={(newValue) => {
if (newValue && newValue > 0) {
onAppearanceChange({ ...appearance, surveyPopupDelaySeconds: newValue })
} else {
onAppearanceChange({
...appearance,
surveyPopupDelaySeconds: undefined,
})
}
}}
className="w-12"
/>{' '}
seconds.
</div>
</LemonField.Pure>
</div>
</div>
</>
)
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2653,12 +2653,13 @@ export interface SurveyAppearance {
thankYouMessageDescriptionContentType?: SurveyQuestionDescriptionContentType
autoDisappear?: boolean
position?: string
shuffleQuestions?: boolean
surveyPopupDelaySeconds?: number
// widget only
widgetType?: 'button' | 'tab' | 'selector'
widgetSelector?: string
widgetLabel?: string
widgetColor?: string
shuffleQuestions?: boolean
}

export interface SurveyQuestionBase {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
"pmtiles": "^2.11.0",
"postcss": "^8.4.31",
"postcss-preset-env": "^9.3.0",
"posthog-js": "1.140.1",
"posthog-js": "1.141.0",
"posthog-js-lite": "3.0.0",
"prettier": "^2.8.8",
"prop-types": "^15.7.2",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 9 additions & 6 deletions posthog/api/survey.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import nh3
from django.db.models import Min
from django.http import JsonResponse
from django.utils.text import slugify
from django.views.decorators.csrf import csrf_exempt
from rest_framework import status
from nanoid import generate
from rest_framework import request, serializers, status, viewsets
from rest_framework.decorators import action
from rest_framework.request import Request
from rest_framework.response import Response
Expand All @@ -20,13 +22,10 @@
from posthog.api.shared import UserBasicSerializer
from posthog.api.utils import get_token
from posthog.client import sync_execute
from posthog.exceptions import generate_exception_response
from posthog.models.feedback.survey import Survey
from django.utils.text import slugify
from nanoid import generate
from rest_framework import request, serializers, viewsets
from posthog.constants import AvailableFeature
from posthog.exceptions import generate_exception_response
from posthog.models.feature_flag.feature_flag import FeatureFlag
from posthog.models.feedback.survey import Survey
from posthog.models.team.team import Team
from posthog.utils_cors import cors_response

Expand Down Expand Up @@ -134,6 +133,10 @@ def validate_appearance(self, value):
"You need to upgrade to PostHog Enterprise to use HTML in survey thank you message"
)

survey_popup_delay_seconds = value.get("surveyPopupDelaySeconds")
if survey_popup_delay_seconds and survey_popup_delay_seconds < 0:
raise serializers.ValidationError("Survey popup delay seconds must be a positive integer")

return value

def validate_questions(self, value):
Expand Down
8 changes: 4 additions & 4 deletions posthog/api/test/__snapshots__/test_properties_timeline.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@
ORDER BY timestamp ASC ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING) AS end_event_number
FROM
(SELECT timestamp, person_properties AS properties,
array(replaceRegexpAll(JSONExtractRaw(person_properties, 'bar'), '^"|"$', ''), replaceRegexpAll(JSONExtractRaw(person_properties, 'foo'), '^"|"$', '')) AS relevant_property_values,
array(replaceRegexpAll(JSONExtractRaw(person_properties, 'foo'), '^"|"$', ''), replaceRegexpAll(JSONExtractRaw(person_properties, 'bar'), '^"|"$', '')) AS relevant_property_values,
lagInFrame(relevant_property_values) OVER (
ORDER BY timestamp ASC ROWS BETWEEN 1 PRECEDING AND CURRENT ROW) AS previous_relevant_property_values,
row_number() OVER (
Expand Down Expand Up @@ -482,7 +482,7 @@
ORDER BY timestamp ASC ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING) AS end_event_number
FROM
(SELECT timestamp, person_properties AS properties,
array("mat_pp_bar", "mat_pp_foo") AS relevant_property_values,
array("mat_pp_foo", "mat_pp_bar") AS relevant_property_values,
lagInFrame(relevant_property_values) OVER (
ORDER BY timestamp ASC ROWS BETWEEN 1 PRECEDING AND CURRENT ROW) AS previous_relevant_property_values,
row_number() OVER (
Expand Down Expand Up @@ -522,7 +522,7 @@
ORDER BY timestamp ASC ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING) AS end_event_number
FROM
(SELECT timestamp, person_properties AS properties,
array(replaceRegexpAll(JSONExtractRaw(person_properties, 'bar'), '^"|"$', ''), replaceRegexpAll(JSONExtractRaw(person_properties, 'foo'), '^"|"$', '')) AS relevant_property_values,
array(replaceRegexpAll(JSONExtractRaw(person_properties, 'foo'), '^"|"$', ''), replaceRegexpAll(JSONExtractRaw(person_properties, 'bar'), '^"|"$', '')) AS relevant_property_values,
lagInFrame(relevant_property_values) OVER (
ORDER BY timestamp ASC ROWS BETWEEN 1 PRECEDING AND CURRENT ROW) AS previous_relevant_property_values,
row_number() OVER (
Expand Down Expand Up @@ -558,7 +558,7 @@
ORDER BY timestamp ASC ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING) AS end_event_number
FROM
(SELECT timestamp, person_properties AS properties,
array("mat_pp_bar", "mat_pp_foo") AS relevant_property_values,
array("mat_pp_foo", "mat_pp_bar") AS relevant_property_values,
lagInFrame(relevant_property_values) OVER (
ORDER BY timestamp ASC ROWS BETWEEN 1 PRECEDING AND CURRENT ROW) AS previous_relevant_property_values,
row_number() OVER (
Expand Down
35 changes: 34 additions & 1 deletion posthog/api/test/test_survey.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from posthog.api.survey import nh3_clean_with_allow_list
from posthog.models.cohort.cohort import Cohort
from nanoid import generate

from rest_framework import status

from posthog.constants import AvailableFeature
Expand Down Expand Up @@ -1249,6 +1248,7 @@ def test_create_basic_survey_question_validation(self):
"thankYouMessageHeader": "Thanks for your feedback!",
"thankYouMessageDescription": "<b>We'll use it to make notebooks better.<script>alert(0)</script>",
"shuffleQuestions": True,
"surveyPopupDelaySeconds": 60,
},
},
format="json",
Expand All @@ -1271,6 +1271,7 @@ def test_create_basic_survey_question_validation(self):
"thankYouMessageHeader": "Thanks for your feedback!",
"thankYouMessageDescription": "<b>We'll use it to make notebooks better.</b>",
"shuffleQuestions": True,
"surveyPopupDelaySeconds": 60,
}
assert response_data["created_by"]["id"] == self.user.id

Expand Down Expand Up @@ -1676,6 +1677,38 @@ def test_validate_thank_you_description_content_type(self):
assert response.status_code == status.HTTP_400_BAD_REQUEST, response_data
assert response_data["detail"] == "thankYouMessageDescriptionContentType must be one of ['text', 'html']"

def test_create_survey_with_survey_popup_delay(self):
response = self.client.post(
f"/api/projects/{self.team.id}/surveys/",
data={
"name": "Notebooks beta release survey",
"type": "popover",
"appearance": {
"surveyPopupDelaySeconds": 6000,
},
},
format="json",
)
response_data = response.json()
assert response.status_code == status.HTTP_201_CREATED, response_data
assert response_data["appearance"]["surveyPopupDelaySeconds"] == 6000

def test_validate_survey_popup_delay(self):
response = self.client.post(
f"/api/projects/{self.team.id}/surveys/",
data={
"name": "Notebooks beta release survey",
"type": "popover",
"appearance": {
"surveyPopupDelaySeconds": -100,
},
},
format="json",
)
response_data = response.json()
assert response.status_code == status.HTTP_400_BAD_REQUEST, response_data
assert response_data["detail"] == "Survey popup delay seconds must be a positive integer"

def test_create_survey_with_valid_question_description_content_type_html(self):
response = self.client.post(
f"/api/projects/{self.team.id}/surveys/",
Expand Down
Loading