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

Visitor Attributes ECA Example is a Drupal recipe that records where a new user came from. When a visitor registers, it copies three of their first-touch attributes onto the new account:

  • the first-touch UTM campaign;
  • the landing section, meaning the part of the site where they first arrived;
  • their country.

You can then report on which campaigns and sections bring in registrations, and follow up with new leads. The recipe is also a working example of lead attribution with Visitor Attributes and ECA, and you can adapt it to other entities such as Webform submissions or Commerce orders.

What it adds

  • The ECA, ECA Content, ECA Misc, Visitor Attributes and Visitor Attributes ECA modules.
  • Three plain text fields on user accounts: First-touch campaign, Landing section and Country (first touch). They aren't added to the user form or the user page, so users can't edit them, and only administrators can see them.
  • One ECA model, Visitor attributes: lead attribution at registration.

It doesn't change your Visitor Attributes consent settings, your consent manager (such as Klaro), or who is allowed to register.

How it works

The model runs just before a user account is saved. It only copies values when all of these are true:

  1. The account is new. Later saves, such as edits, logins and password resets, are ignored.
  2. The account is being created on the registration form. Accounts created by an administrator, Drush, a migration, SSO or a web service are skipped, because in those cases the visitor cookie doesn't belong to the new user.
  3. The visitor has consented, so the attribute isn't withheld. If it is withheld, nothing is stored, rather than the word "unknown".
  4. The field is still empty, so a value set some other way is kept.

Values are stored as they were captured. For example, a campaign called Q4 & sale is stored as written, not HTML-escaped.

Important: don't use it for access control

Visitors control their own UTM parameters and most other attributes. Anyone can add ?utm_campaign=spring to a link. Use these values for reporting and follow-up only. Never use them to grant a role, a permission or access to anything.

Requirements

  • Drupal 11.3 or later, ECA 3.1 or later, and Visitor Attributes 1.0.0-alpha4 or later.
  • A Visitor Attributes consent mode must be chosen at Configuration › System › Visitor attributes. Until one is chosen, every attribute reads as unknown and nothing is stored.
  • Visitors must be allowed to register (Configuration › People › Account settings).
  • If you use a consent integration such as Klaro, attributes are only kept from page to page for visitors who allow the Visitor attributes service.
  • The country needs a geo provider set up in the Visitor Attributes settings. Without one, that field stays empty.

Installation

composer require drupal/visitor_attributes_eca_example
drush recipe ../recipes/visitor_attributes_eca_example

Recipes can also be applied from the Project Browser in Drupal CMS.

The new fields aren't displayed anywhere by default. To see them, add them to the user display at Configuration › People › Account settings › Manage display. Keep in mind that anyone who can view user profiles will then see them too.

Removing it

Uninstalling the modules doesn't remove the fields or the model. To remove them, delete the model at Configuration › Workflow › ECA and the fields at Configuration › People › Account settings › Manage fields. Deleting the fields also deletes their stored values.

See the README for ways to adapt the recipe, such as also copying values at login, or using it with Webform, contact forms or Commerce.

Project information

Releases