Skip to content
webmanufakturPublic

About

ProcessWire module: polls with a CTA above and below your content and a popover dialog — targeted by page, template or selector, cache-safe (ProCache), no dependencies

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

Votee

Polls for ProcessWire that live next to your content and stay correct behind a full-page cache.

Votee shows a poll as a call to action above your content (a slide-in overlay bar) and below it (inline). Visitors click, vote in a native <dialog> popover, see a thank-you note and the results, and the CTAs disappear for good. Each poll has its own random hash. localStorage and a cookie remember that the visitor has voted.

Built to run behind ProCache or any other full-page cache: the pages only contain two empty slots, and the polls are fetched after load. Polls start, end and change without clearing the cache.

Features

  • Targeting by page (optionally with children), template or selector. Every matching active poll is shown, ordered by its position in the page tree
  • Single or multiple choice, with an optional "Other" answer with free text
  • Start/end date and audience (everyone, guests only, logged-in users only)
  • No layout shift: the top CTA is a fixed overlay bar that slides in on first scroll or after a delay. The bottom CTA sits in the flow below the fold
  • Accessible popover: native <dialog> with focus trap, Esc and backdrop
  • Results after voting, can be hidden per poll
  • Abuse protection without personal data: server-side cookie check, honeypot, minimum time, a same-origin check instead of a CSRF token (which cached HTML can't carry) and a per-day rate limit keyed by a pseudonymous HMAC of the IP with a daily rotating key. LazyCron deletes those entries after 24 h
  • Admin page "Polls": overview, result bars, participants per day and per page, moderation of "Other" texts, CSV export (results and raw data), reset votes, regenerate hash
  • Targeting preview in the poll editor: how many pages and which ones a poll hits
  • Bring your own markup: override templates in /site/templates/votee/ as PHP or Twig, and replace or extend the CSS with /site/templates/votee/votee-styles.css
  • No dependencies: vanilla JS (~3 KB gzipped), PHP templates, plain CSS with custom properties. All strings are translatable

Requirements

  • ProcessWire 3.0.173+ (URL hooks), PHP 8.1+
  • Core modules FieldtypeRepeater and FieldtypeSelector
  • Optional: Twig available via Composer (\Twig\Environment) for .html.twig overrides

Installation

  1. Copy the module to site/modules/Votee/ (or git clone https://github.com/webmanufaktur/Votee).

  2. Modules → Refresh, install Votee. It also installs ProcessVotee (admin page Polls, permission votee-admin), the fields and templates, the hidden parent page /votee/ and two tables.

  3. Output the two slots and the script in your layout:

    <?php $votee = $modules->get('Votee'); ?>
    <?= $votee->slot('top') ?>        <!-- before your content -->
    … your content …
    <?= $votee->slot('bottom') ?>     <!-- after your content -->
    <?= $votee->script() ?>           <!-- before </body> -->

    Twig or plain HTML works too:

    <div data-votee-slot="top"></div>
    …
    <div data-votee-slot="bottom"></div>
    <script defer src="/site/modules/Votee/assets/votee.js"></script>

    Instead of the script tag you can enable Inject votee.js before </body> automatically in the module config.

  4. Votee needs the current page ID. It reads <body data-id="…">, or data-votee-page="…" on a slot:

    <div data-votee-slot="top" data-votee-page="<?= $page->id ?>"></div>
  5. Using a full-page cache? Clear it once after adding the slots.

Creating a poll

Polls → New poll (or add a page below /votee/):

Field Purpose
Question, Answers The question and its answers (repeater)
Allow multiple answers Checkboxes instead of radio buttons
"Other" option Adds a free-text answer (max. 200 characters)
CTA text / button Per poll. Empty = defaults from the module config
Target: pages / children / templates / selector Where the poll appears (OR-combined)
Start / End Optional time window
Audience Everyone, guests only, logged-in users only
Hide results after voting Show only the thank-you note
Hash Random ID, generated on first save

A poll is active when it is published, inside its time window, has at least one answer and at least one target. Editing texts keeps the hash. Only Regenerate hash on the results page lets everyone vote again.

Selector targets are checked with $page->matches(), which does not support every sub-field selector. The Targeted pages preview in the editor shows what actually matches.

Customizing

Templates

Votee looks for each template (cta, dialog, results) in this order:

  1. /site/templates/votee/{name}.html.twig (if Twig is available)
  2. /site/templates/votee/{name}.php
  3. site/modules/Votee/templates/{name}.php

Copy a file from templates/ and edit it. The contract is the set of data-votee-* attributes documented at the top of each template, not the CSS classes. Variables: $poll, $hash, $position (top/bottom), $question, $multi, $options, $other, $otherLabel, $ctaText, $ctaButton, $state, $showResults, $results, $votee.

CSS

assets/votee.css uses BEM classes (.votee-cta, .votee-dialog, …) and custom properties:

body {
  --votee-accent: #00406b;   /* buttons, bars, selection */
  --votee-radius: 0.5rem;
  --votee-font: inherit;
}

Set them on body, not :root: votee.css is loaded after your stylesheet.

If /site/templates/votee/votee-styles.css exists, it is loaded instead of votee.css (default) or in addition to it (module config). Both are only loaded on pages that actually show a poll.

Tailwind CSS

Templates in /site/templates/votee/ must be covered by your @source paths, e.g. @source '../templates/votee/**/*'; relative to your Tailwind input file. The module directory is usually not scanned, so the default templates don't use Tailwind classes.

Translations

All admin and frontend strings use __()/$this->_(). Translate them under Setup → Languages → (language) → Site files: Votee.module.php, ProcessVotee.module.php and templates/*.php. Client-side messages come from the data-votee-msg-* attributes in dialog.php, so they are translated there as well.

How it works

page (cached)  ──  <div data-votee-slot>  ──  votee.js
                                               │ GET  /votee-api/polls?page=123
                                               │      → 204, or {polls:[{hash, top, bottom, dialog}], css, config}
                                               │ filter polls already voted (localStorage / cookie)
                                               │ insert CTAs + <dialog>, load CSS
                                               │ POST /votee-api/vote {hash, options, other, page, hp, t}
                                               └──    → 200 {ok, html} | 409 already | 410 ended | 422 | 429 | 403
  • GET /votee-api/polls is cached per page with WireCache until the next start/end time (max. 10 min). Saving a poll clears that cache.
  • POST /votee-api/vote requires X-Requested-With: votee and a same-origin Origin / Sec-Fetch-Site. It checks the cookie votee_<hash>, honeypot, minimum time, options, audience and rate limit, stores one row per chosen option and sets the cookie.
  • Tables: votee_votes (poll, option, page, submission ID, time, optional "Other" text, no personal data) and votee_ratelimit (IP HMAC, poll, hits, time; purged after 24 h).

Privacy

What Votee stores, so you can describe it in your privacy policy:

Where What How long
votee_votes (DB) poll, chosen option, page ID, submission ID, time, optional "Other" text until you reset the poll
votee_ratelimit (DB) HMAC of the IP address, poll, hit count, time 24 h (LazyCron)
Cookie votee_<hash> "has voted" flag end of poll + 30 days, or 1 year without an end date; the JS fallback cookie always uses 1 year
localStorage votee:v1:<hash> "has voted" timestamp until the visitor clears it
sessionStorage votee:dismiss:<hash> top bar closed end of the browser session
  • Votes are anonymous: no IP address and no user ID are stored with them. The "Other" free text can contain whatever visitors type, so moderate it in the admin.
  • The rate-limit hash is pseudonymous, not anonymous. It is HMAC(ip, sha256(userAuthSalt|votee|date)). The key is never stored, but it can be derived from the site's auth salt and the date, so the operator could recompute the hash for a known IP on the same day. Treat it as personal data for 24 hours. Typical legal basis: legitimate interest in protecting results from manipulation (Art. 6 (1) (f) GDPR).
  • Cookie and web storage only serve a feature the visitor actively uses, so they usually count as strictly necessary (in Germany § 25 (2) no. 2 TDDDG) and need no consent. They still belong in your privacy policy.
  • If Pirsch Analytics is present, votee.js sends the events votee_open and votee_vote with the poll hash as metadata (never the answer). Mention this under your analytics section.

This is a technical description, not legal advice.

Configuration

Modules → Votee: default CTA text and button, handling of votee-styles.css (replace/add), rate limit per day (0 = off), minimum time before submitting, top bar delay, automatic script injection, and whether to drop the vote tables on uninstall.

Uninstalling

Fields, templates and poll pages are kept. The vote tables are only dropped if you enabled that in the module config. Reinstalling is idempotent.

License

MIT, see LICENSE.

About

ProcessWire module: polls with a CTA above and below your content and a popover dialog — targeted by page, template or selector, cache-safe (ProCache), no dependencies

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages