This project is not covered by Drupal’s security advisory policy.

Visitor Attributes Example is a recipe for Drupal CMS sites built with the Haven site template. It adds a Get involved page whose middle section depends on the campaign link the visitor last arrived from:

  • utm_campaign=spring: a "Spring planting days are here" banner.
  • utm_campaign=summer: a "Summer shoreline clean-ups" banner.
  • Any other campaign, no campaign, or no consent: a general "Ways to help" section.

The page remembers the campaign on later visits, even when the URL no longer has the parameter. A new campaign link switches it.

It shows Visitor Attributes working with Canvas Conditional Container and Context. The page uses a Condition Group: two conditional containers in priority order, of which only the first whose rules pass is shown, and a Default for everyone else.

Never use it for access control

Visitors control their own UTM parameters: anyone can add ?utm_campaign=spring to a link. Use visitor attributes to choose what content to show, never to hide private content or grant access.

Built for demos

The README includes a demo script of about ten minutes. It walks through consent, both campaigns, a campaign that isn't on the allowlist, and caching. With Twig debugging on, the page's HTML source shows how the rules were evaluated: which variant the group showed, and why each container was shown or hidden:


<!-- Condition Group … shows variant 2, … (container). --> <!-- Conditional container … hidden: failed. Rule group 1, rule 1: context:spring_campaign_visitors (Spring campaign visitors), ok, false → false. Context "spring_campaign_visitors" is not active. --> <!-- Conditional container … shown: passed. Rule group 1, rule 1: context:summer_campaign_visitors (Summer campaign visitors), ok, true → true. Context "summer_campaign_visitors" is active. -->

What it adds

  • The Canvas, Context, Klaro, Canvas Conditional Container, Visitor Attributes and Visitor Attributes Klaro modules.
  • Visitor Attributes settings: Klaro decides whether attributes may be stored, and the utm_campaign allowlist is set to spring and summer. This replaces any existing utm_campaign allowlist.
  • Contexts: Spring campaign visitors and Summer campaign visitors, each based on the visitor's latest campaign, and Home page.
  • A Canvas page at /get-involved.
  • The Use Contexts in conditional containers permission for the Content editor role.
  • A site-wide change to Haven's page template: the footer's newsletter form moves into a conditional container, so it shows on the home page only. Webform forms can't be cached, so a page showing one is never stored in Dynamic Page Cache. Haven puts the form in the footer of every page, so before this change no page can be stored there. After it, every page except the home page can be.

Requirements

  • A Drupal CMS site built with the Haven site template.
  • Visitor Attributes 1.0.0-alpha2 or later.
  • Canvas Conditional Container 1.0.0-beta2 or later.
  • Context 5.0.0-rc4 or later.
  • Canvas 1.12 or later, and Klaro 3.1 or later.

The footer change finds the newsletter form by the IDs Haven ships it with. If you removed or replaced that form, remove the page template action from recipe.yml before applying the recipe.

Getting started

Several of the required projects are still alpha, beta or release candidate versions. Composer applies stability flags only from your site's root composer.json, so allow them there:


composer require drupal/visitor_attributes_example drupal/visitor_attributes:^1.0@alpha drupal/canvas_conditional_container:^1.0@beta drupal/context:^5.0@RC drush recipe ../recipes/visitor_attributes_example

Visitor Attributes stores nothing until a visitor allows it in Klaro. Drupal CMS keeps Klaro's dialog mode on Silent, with no banner, but adds a My privacy settings link to the footer that opens Klaro. If your site doesn't have that link, choose another Klaro dialog mode or show Klaro's toggle button. The recipe doesn't change Klaro's settings.

Caching

The group decides while the page is built, so /get-involved isn't stored in Internal Page Cache and is sent with Cache-Control: no-cache. Dynamic Page Cache still stores one copy of the page per campaign value, shared by every visitor with that value. Pages without the group are unaffected.

Related projects

Project information

Releases