Discourse Surveys

:discourse2: Summary Discourse Surveys plugin allows you to create surveys directly within your Discourse forum posts using simple Markdown syntax.
:hammer_and_wrench: Repository Link https://github.com/discourse/discourse-surveys
:open_book: Install Guide How to install plugins in Discourse

The Discourse Surveys Plugin allows you to create surveys directly within your Discourse forum posts using simple Markdown syntax. The plugin currently supports a variety of question types such as radio buttons, checkboxes, dropdowns, number inputs, text areas, star ratings, and thumbs up/down ratings.

Basic Survey Markdown

Here is a basic example of survey Markdown including all available fields:

[survey name="awesome-survey-thumbs" title="Awesome Survey"]

[radio question="Choose any one option:"]
- cat
- dog
[/radio]

[checkbox question="Choose multiple options:"]
- red
- blue
- green
[/checkbox]

[dropdown question="Gender:"]
- Male
- Female
[/dropdown]

[number question="Rate this survey from 1 to 10:"]
[/number]

[textarea question="What is your feedback about xyz?" required="false"]
[/textarea]

[star question="How would you rate overall experience?"]
[/star]

[thumbs question="Were you satisfied with our services?"]
[/thumbs]

[/survey]

Survey Rendering

Below is an example of how the above Markdown renders in Discourse:

Survey Results

Currently, this plugin does not have any backend UX to view the survey results directly. Instead, you can rely on Data Explorer queries to fetch and analyze survey responses. Here is an example query:

-- [params]
-- text :survey_name = survey

SELECT s.id, s.name, s.post_id, sf.question, COALESCE(sr.value, sfo.html) AS value, sr.user_id, sr.created_at as responded_at
FROM surveys s
JOIN survey_fields sf ON sf.survey_id = s.id
JOIN survey_responses sr ON sr.survey_field_id = sf.id
LEFT JOIN survey_field_options sfo ON sfo.id = sr.survey_field_option_id
WHERE s.name = :survey_name
ORDER BY s.id DESC

Future Scope

The plugin has potential for many improvements. Feel free to join the discussion, and submit pull requests on the plugin’s repository.

26 Likes

So users can’t see results (unless they have rights to use query) and this is totally for admins/background staff?

3 Likes

Yes, that is correct.

7 Likes

It doesn’t feel very practical :cry:

3 Likes

Need option to publish survey results. Otherwise better to use multiple polls.

3 Likes

Could this be presented at the topics page, so that the users can rate topics with it? Once installed, I don’t see any settings, other than the ā€˜Enable’ checkbox.

That would be completely outside the scope of this plugin, maybe you are looking for Discourse Topic Voting Plugin ?

Thanks, but I need users to rate 1-5 instead of vote up/down. There’s also the Topics Rating Plugin, but it requires users to click into the topic and rate inside the composer.

Hello

The sample Markdown renders in a new Topic as per below. My Discourse is updated to the latest version.

What could the the problem?

Regards

Hey @ppcole,

The above is what is shown in composer preview when you’re creating the survey. Once you create the topic it will render properly as expected.

Its not even working on my own side, sigh.

Thanks Arpit. It worked. Looking forward to enhancements

1 Like

Hi!

Tried to install it but have an error message: Import Error: about.json does not exist, or is invalid. Are you sure this is a Discourse Theme?

This is a plugin, not a theme: Install plugins on a self-hosted site

4 Likes

@techAPJ Is this project still live?

1 Like

Hi @techAPJ,
Does documentation exist for this aspect of the plugin?

This feature was mentioned by mistake and I’ve removed the ā€œevent integrationā€ section from the first post. Apologies for the confusion.

1 Like

May I know if you folks are working on this but not with actual priority?

It would be great to have this continue to be developed - it has masses of potential.

I found that the SQL above did pull out the results, but it wasn’t in an easy to work with format; basically it would require a tonne of transformation at the spreadsheet level to enable useful analysis.

However, with a bit of Gen AI help, I was able to produce a very sweet Data Explorer query. Due to some limitations of Data Explorer, it isn’t possible to make it dynamic enough to cope with a variety of surveys; basically you need a bespoke query per survey.

Fortunately, Gen AI can make that pretty straight forward. Here is a sample prompt that will probably work in most Gen AI services (if you don’t have the AI plugin active) - just plugin in your survey markdown and you should be away:

Gen AI Prompt to Produce Tailored SQL Query for a Specific Survey

I have a survey defined in markdown format, and I need a SQL query to extract the survey results from a Discourse database using the Data Explorer Plugin. The survey includes various types of questions such as radio, dropdown, star, checkbox, textarea, thumbs, and number. I want the query to output results with each user having a single row and each question having its own column. For checkbox questions, multiple responses should be concatenated into a single string.

Here is the survey markdown:

Paste your survey markdown here

Here is the original query used to obtain survey results:

-- [params]
-- text :survey_name = survey

SELECT s.id, s.name, s.post_id, sf.question, COALESCE(sr.value, sfo.html) AS value, sr.user_id, sr.created_at as responded_at
FROM surveys s
JOIN survey_fields sf ON sf.survey_id = s.id
JOIN survey_responses sr ON sr.survey_field_id = sf.id
LEFT JOIN survey_field_options sfo ON sfo.id = sr.survey_field_option_id
WHERE s.name = :survey_name
ORDER BY s.id DESC

Please generate a SQL query that:

  • Hardcodes the survey name.
  • Uses conditional aggregation to pivot the data, with each question as a column.
  • Utilizes STRING_AGG for checkbox questions to handle multiple responses.
  • Ensures the output is grouped by user_id and ordered by user_id.
  • Is formatted for readability and includes comments explaining the logic where necessary.

Additional Guidance for Data Explorer Plugin:

  • The query should be compatible with the Discourse Data Explorer Plugin, which means it should not end with a semicolon.
  • Use column names like user_id to leverage automatic linking features within the Data Explorer.
  • Avoid using dynamic SQL, as the plugin does not support it.
  • Ensure the query is efficient and optimized for performance, as it may be run on large datasets.
2 Likes