feat: support other newsletter signup forms#836
Conversation
adekbadek
left a comment
There was a problem hiding this comment.
the default implementation assumes that the first field in any Gravity Form block is the email address
That feels like casting a much wider net than expected. Any submission of a GF form would mark the reader as a subscriber. And even if the form is a newsletter signup form, the assumption that the email input is the first input is not very reliable IMO. I think this implementation would result in a high rate of false positives for subscriber segmentation.
It might be possible to use DOMXpath to find the name attribute of a type="email" input inside a form. If that's not possible, I'd rather opt for dropping the direct GF integration and instruct users to add newspack-subscribe-form class to any email-signup form:
@adekbadek That's a good point. 7a53a80 avoids false positives by requiring the following for a Gravity Forms form to be tracked as a subscribe form within a prompt:
|
|
🎉 This PR is included in version 1.52.0-alpha.1 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
# [1.52.0](v1.51.0...v1.52.0) (2022-04-20) ### Bug Fixes * insertion of prompts around Group blocks ([#855](#855)) ([6ae5ea9](6ae5ea9)) * make "scroll" the default inline trigger_type ([#846](#846)) ([a2ffee4](a2ffee4)) ### Features * support other newsletter signup forms ([#836](#836)) ([c30702d](c30702d))
|
🎉 This PR is included in version 1.52.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |

All Submissions:
Changes proposed in this Pull Request:
The plugin currently fully tracks only Jetpack Mailchimp block forms as newsletter subscribe form submissions. This PR adds handling for MC4WP forms, Gravity Forms, and arbitrary forms, the latter two via a
.newspack-subscribe-formclass name. The class name and the name of the field containing the user's email address are now filterable via the following filters:newspack_campaigns_form_class- The class name of the subscribe form.newspack_campaigns_form_selector- The CSS selector used to target the form for tracking submit events. If the form being tracked is a Jetpack Mailchimp or MC4WP form, it will be the selector for those form types (which generate consistent markup). Otherwise it will use the result ofnewspack_campaigns_form_classto build a selector.newspack_campaigns_email_form_field_name- The value of thenameattribute of the input field containing the user's email address. The value of this field will be reported as the user's email address upon form submission. This filter also reports the value of the selector as the second argument so you have an idea of whether a form in each prompt is a Jetpack block, MC4WP block, a Gravity Form, or a custom form.Note:
The Gravity Forms UI does not allow for customization of input7a53a80 fixes this issue by requiring Gravity Forms forms to have thenameattribute values, so the default implementation assumes that the first field in any Gravity Form block is the email address. You can use thenewspack_campaigns_email_form_field_namefilter to alter this assumption if your Gravity Form has a different field structure. Because of this behavior, any Gravity Form inside a prompt will be assumed to be a newsletter subscribe form unless thenewspack_campaigns_email_form_field_namefilter returns a falsy value.newspack-subscribe-form(specifically the filtered result ofnewspack_campaigns_form_class) class name applied via form settings, as well as a field of typeemail. This is to prevent false positives from tracking Gravity Forms forms that may not be intended as subscribe forms.Closes #791.
How to test the changes in this Pull Request:
Make sure you test with a site that's fully connected to Jetpack, Mailchimp, and Google Analytics via Site Kit. Note that you may need to test this with a live staging site rather than a local environment. ngrok environments in particular may not be able to connect to GA and therefore may not print all of the event config needed to test.
"on":"amp-form-submit"and confirm there are two event config objects in source: one should have an event name ofForm Submissionand the other should have anextraUrlParamsproperty containing the client ID, email address input name, and other data.newspack-subscribe-formclass name to the form. Replace the Jetpack Mailchimp block in your prompt with a Gravity Forms block pointing to your newsletter form.name="email"attribute. Replace the form in your prompt with a "Mailchimp for WordPress Form" block pointing to your MC4WP form.Other information: