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: add renderSurvey option #1324

Merged
merged 26 commits into from
Jul 31, 2024
Merged

feat: add renderSurvey option #1324

merged 26 commits into from
Jul 31, 2024

Conversation

timgl
Copy link
Collaborator

@timgl timgl commented Jul 27, 2024

Changes

Adds a posthog.renderSurvey('[survey-id]', '[js-selector]', (survey) => !survey && console.log('survey not found')) function which will render any survey on an element on a page. This will allow users to use surveys as forms.

Decided to go unformatted so that the formatting will match wherever it's embedded

Checklist

  • Tests for new code (see advice on the tests we use)
  • Accounted for the impact of any changes across different browsers
  • Accounted for backwards compatibility of any changes (no breaking changes in posthog-js!)

Copy link

vercel bot commented Jul 27, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
posthog-js ✅ Ready (Inspect) Visit Preview Jul 31, 2024 3:43pm

Copy link

github-actions bot commented Jul 27, 2024

Size Change: +4.08 kB (+0.35%)

Total Size: 1.16 MB

Filename Size Change
dist/array.full.js 332 kB +1.44 kB (+0.44%)
dist/array.js 153 kB +737 B (+0.48%)
dist/main.js 154 kB +737 B (+0.48%)
dist/module.js 153 kB +737 B (+0.48%)
dist/surveys-preview.js 59.5 kB -264 B (-0.44%)
dist/surveys.js 65.6 kB +693 B (+1.07%)
ℹ️ View Unchanged
Filename Size
dist/exception-autocapture.js 10.4 kB
dist/recorder-v2.js 110 kB
dist/recorder.js 110 kB
dist/tracing-headers.js 8.26 kB
dist/web-vitals.js 5.79 kB

compressed-size-action

playground/nextjs/pages/survey.tsx Outdated Show resolved Hide resolved
playground/nextjs/pages/survey.tsx Outdated Show resolved Hide resolved
Copy link
Contributor

@dmarticus dmarticus left a comment

Choose a reason for hiding this comment

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

I think I figured out a fix for the issue I noticed, so going to push that up.


export default function Survey() {
const posthog = usePostHog()
const [surveys, setSurveys] = useState([] as unknown as Survey[])
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI, when I try to build this locally, I get a failure:

./pages/survey.tsx:6:61
Type error: 'Survey' refers to a value, but is being used as a type here. Did you mean 'typeof Survey'?

  4 | export default function Survey() {
  5 |     const posthog = usePostHog()
> 6 |     const [surveys, setSurveys] = useState([] as unknown as Survey[])
    |                                                             ^
  7 |     const [selectedSurvey, setSelectedSurvey] = useState('0190bc7b-7096-0000-126d-1e5e7021a80e')
  8 |     const handleChange = (event) => {
  9 |         setSelectedSurvey(event.target.value)
 

because I don't think the playground has access to these types.

Copy link
Contributor

Choose a reason for hiding this comment

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

fixed


export default function Survey() {
const posthog = usePostHog()
const [surveys, setSurveys] = useState([] as unknown as Survey[])
Copy link
Contributor

Choose a reason for hiding this comment

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

fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bump minor Bump minor version when this PR gets merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants