Using hidden fields to pass UTM_campaign (etc) in the contact form

Here is the situation, and I know this can be done manually by editing the exported Sparkle code, but I’m wondering if there is a way to do this within Sparkle instead so I don’t have to edit manually each time.

The situation is this:

  • User comes to the site via Google Ads or Facebook Marketing;
  • The variable “utm_campaign” is available in POST;
  • We want to grab this variable and pass it to the contact form when the user submits, so that we know where the user originally came from to find the site.

Thanks!

For now I can only thank you for the suggestion.

The workaround would be to write some PHP that goes in an embed block. The immediate idea would be to have that PHP generate hidden form fields, but due to how Sparkle forms work, they wouldn’t be included in the form.

So what you can do is embed PHP code that generates JavaScript to inject the hidden fields into the form. Not for the faint of heart, but it should work.

Interesting idea, will give it a go. Thanks!