JS Form

Webform Conversion-Tracking provides the ability to execute custom JavaScript on the webform confirmation page, typically used for conversion tracking.

Security notice:
The currently used logic to execute JavaScript on the confirmation page needs a security review. Please help to find the best possible implementation! Ensure to grant permissions carefully!

Solved problem & Use-case

In many cases, like for ads and statistics, you may need to run a conversion tracking script for each successfully submitted form. Typically, this is done by JavaScript event snippets provided by the ad companies to include on the confirmation page. Anyway JavaScript is being filtered out on the Webform success message and while Webform provides the "Custom JavaScript" textarea for the whole form and all webform pages, it doesn't provide such a functionality just for the confirmation page / message. Also, it currently misses a good way to detect that kind of page.

Background:
Based on the closed (won't fix) discussion in #2985633: Execute javascript on submission (e.g. conversion tracking) we created this module to provide a simple alternative for site admins to execute a custom (e.g. conversion tracking code) JavaScript on the form confirmation page.

Note: This currently only works with the following confirmation types:

  • Page
  • Inline

For details, see: #3314878: Module currently only works with Confirmation type "Page" and "Inline" (Module tests fail, because they check ALL confirmation types, we let them fail, until the issue is resolved.)

Security

Being able to set custom JavaScript is potentially dangerous. So be careful who you grant the permission to administer the JavaScript or change the configuration (where the JS is stored).

Installation

  • Require the module and dependency via composer require drupal/webform drupal/webform_ct.
  • Install the module using drush en webform_ct.

Usage

  • Go to the webform, you would like to apply the custom confirmation javascript code to and edit the webform's settings. (/admin/structure/webform/manage/my-webform/settings)
  • Click the "Confirmation" Tab and select either the "Page" or "Inline" confirmation type.
  • Once selected a "Confimation Javascript Code" text-field will appear on the bottom of the form.
  • Type in your custom javascript code and save.
  • Done! Now your custom javascript will execute on every webform submit!

Alternatives

Supporting this module

Support DROWL's ♥ FOSS work on this module on OpenCollective!

Drupal and this module are FOSS. However, it takes dedicated people to develop and maintain. And they need YOU to give back!

We're committed to building and maintaining Drupal modules that benefit the entire community.

Supporting us on OpenCollective helps us continue to improve, innovate and contribute to Drupal's future. Every pledge makes a difference!

If this module has helped you, we would be very grateful for your donation to support its further development and maintenance.

Support our FOSS development ♥️

You can also speed up the development of features or bugfixes you'd love to see, by sponsoring and giving back!

Sponsor a feature or bugfix 🚀

Let's make Drupal even better, together!


Development proudly sponsored by German Drupal Friends & Companies:

webks: websolutions kept simple (https://www.webks.de)
and
DROWL: Drupalbasierte Lösungen aus Ostwestfalen-Lippe (OWL), Germany (https://www.drowl.de)

Supporting organizations: 
proudly developed this module for the community

Project information

Releases