Storing poll data

Using Kirby as db for React frontend - storing all texts and images in Kirby and then getting them in frontend via REST API calls. So far is good.
Now have request to create visitors poll. So question - how and where to store visitors filled poll data? Poll could be just some rating and some comment as well.

Solutions which Im thinking of -

  1. create separate page in Kirby admin panel with structured field and each visitor would post to Kirby and add entry in structured field…
  2. Not to use Kirby at all - and store poll data in Firebase
  3. Use Google Analytics events for saving poll answers

Maybe there is better solution how to achieve that?

I think anything that works for you would be good. As options to consider I’d add databases, also file based ones like SQLite, rather than firebase. Just because I feel like firebase makes aggregations cumbersome (in my experience at least) and polls are all about their aggregatated form :).

1 Like

You may have to consider an issue with concurrent writes here: in order to “update” the structure field, Kirby needs to first read the existing content file, update the YAML data and then write it back to disk; the file is not write protected between those two steps. With two users voting at exactly the same moment (the probability of course depending on traffic volume, but it’s never zero), the second write could be based on data that was read before the first write.

Such a poll feature would not work for users who have not consented to GA use or who themselves or by browser default have blocked GA for privacy reasons?

A lightweight database (my personal preference would be SQLite as well) can deal with concurrent writes. Or collecting votes into a plain text log file (Kirby’s F::write with $append = true already adds LOCK_EX and FILE_APPEND flags to mitigate the concurrency issue) and processing it asynchronously to aggregate the results…