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

The Webform JavaScript Setting module provides a hidden Webform element that captures a value from a JavaScript property or method and includes it with the submission. The module can capture properties from window.navigator, drupalSettings, JavaScript-based tracking software, and browser cookies.

Use cases

The module can be used to capture information such as:

  • A Google Analytics client ID, allowing Webform submissions to be correlated with Analytics sessions.
  • The browser user agent, such as Chrome or Firefox.
  • An identifier or other value stored in a browser cookie available to JavaScript.

Configuration

  1. Go to the Webform configuration page and open the third-party settings.
  2. Add each JavaScript setting with a machine name, JavaScript declaration, and label.
  3. Add a JavaScript Setting element to a webform and select the declaration to capture.

Supported declarations

JavaScript properties can be entered using dot notation. Methods without arguments are also supported.

Examples include:

  • navigator.userAgent captures the browser's user agent.
  • drupalSettings.user.uid captures the current Drupal user ID.
  • WebformJavaScriptSettingTest.get calls the get() method and captures its return value.
  • document.cookie captures the complete cookie string available to JavaScript.
  • document.cookie.[name] captures the raw value of the named cookie. For example, document.cookie.analytics_id captures the value of the analytics_id cookie.

Cookies that are unavailable to JavaScript, including cookies marked HttpOnly, cannot be captured.

Supporting organizations: 

Project information

Releases