The use of Gravity Forms to implement a simple double opt-in method for any newsletter app. In this example I’m using Campaign Monitor. Currently Campaign Monitor has a simple double opt-in routine however this can (at the time of writing this) be switched on and off and no record is kept whether an email address went through single or double opt-in. As far as I’m aware and I’m no legal beagle is that for General Data Protection Regulation (GDPR) which will be enforced on 25 May 2018 is that consent must be given for the purpose of data processing which includes recording that consent was given. More about that legal stuff here: https://www.eugdpr.org/
Our set up will include four forms are:
Email Campaign – Sign up
Email Campaign – Double Opt In
Email Campaign – Unsubscribe
Email Campaign – Something has gone wrong!
The double opt-in process is fairly straight forward for a visitor.
- Enter an email address requesting to sign up to the newsletter.
- The address entered receives an email asking them to confirm the request and provides a unique link to process that request.
- The email address is passed to Campaign Monitor via API.
Step 1: Setting up Campaign Monitor.
Get your Campaign Monitor API key. Instructions here https://help.campaignmonitor.com/api-keys
Create a new single opt-in (no confirmation required) list, for this example I’m naming it “Opted-In Subscribers”.
Under “Unsubscribe settings” edit the “Redirect unsubscribers to your own confirmation page” and set to your yet to be created unsubscribe page and end the URL with /?verify=[verify]& entryid=[entryid]
Under “Custom fields” add a new text field named “”verify” and a new number field named “entryid”
Step 2: Setting up your website.
You should have Gravity Forms https://www.gravityforms.com/ and the Gravity Forms Campaign Monitor Add-On https://www.gravityforms.com/add-ons/campaign-monitor/ installed.
Copy this code into a text editor and save it as a .json file. ie double-opt-in.json
On the code that you have just saved, conduct a find and replace on the following:
Find “YOUR-COMPANY-NAME” and replace with the from name for the emails sent to end users
Find “YOUR-COMPANY@EMAIL.COM” and replace with the public facing email address
Find “YOUR-COMPANY-SUBSCRIBE_URL” and replace you’re your yet to be created subscribe page ie www.YOURDOMAIN.com/subscribe/
Once that’s done save the file and then import as follows: goto Gravity forms > Import/Export and import your new file double-opt-in.json
This will create the four forms required.
Step 3. Connect the API.
Goto Forms > Settings > Campaign Monitor and enter the API Key that you got earlier.
Goto the form “Email Campaign – Double Opt In” settings > Campaign Monitor and add a new feed.
Choose “Opted-In Subscribers” from the drop down
Map the following:
Email Address > Email
Verify > verify
Entryid > Entry ID
Tick the resubscribe option
Step 4. Check the Forms.
Goto the form “Email Campaign – Sign up” settings and make sure your happy with the text that you are going to send out to the people who sign up. I’d recommend adding your company address to the “Confirm Email Opt In” notification email.
Step 5. Website Pages.
Create a new page called “Subscribe”
Add the shortcode:
[campaign_email_confirmed]Thanks for Joining [/campaign_email_confirmed]
Between these shortcodes you could display an image or a promo code etc.
It’s what will be displayed once a user has clicked the link in their email to confirm the subscription.
Create a new page called “Unsubscribe”
Add the text and shortcode :
You have successfully unsubscribed.
Step 6. Functions file.
Copy the following code to your favourite text editor and conduct a find and replace:
Find “Form-A” and replace with the ID number of the form – “Email Campaign – Sign up”
Find “Form-B and replace with the ID number of the form – “Email Campaign – Double Opt In”
Find “Form-C” and replace with the ID number of the form – “Email Campaign – Unsubscribe”
Find “Form-D” and replace with the ID number of the form – “Email Campaign – Something has gone wrong!
Find “Key-A” and replace with a secret code ie FGFG£$%&FGH$334445e4
Find “Key-B” and replace with a secret code ie 740345445
Once you have completed the find and replace copy the code block into your functions.php file (hopefully in your child theme :)).
Step 7. Htaccess or any form of redirect.
#Email new subscriber
redirect 302 /email-signup https://www.YOURDOMAIN.com/subscribe/?verify=new
You can direct your visitors to the URL
https://www.YOURDOMAIN.com/email-signup and they will be presented with a form to enter their email address. You could also use a pop-up method on the “Sign up” form.
Once the email address is submitted one of the following will happen:
If the email address is new or has not been through the double opt-in process then a message will be displayed to the user “Thanks for subscribing” etc. then a email will be sent to the address with the confirmation link.
If the email address has already been through the double opt-in process then a message will be given to say the address is already registered.
An email address will be sent to the given email address with the confirmation link. If the user ignores the email then no further action will be taken.
If the user clicks on the confirmation link they will be taken to your website subscribe page
The “Thanks for joining message” will be displayed or any image/copy that you have entered between the
[campaign_email_confirmed] short codes.
If the confirmation link is clicked again or the page refreshed then a message is displayed stating that the address is already registered to receive emails.
If the confirmation link is malformed then the “Something has gone wrong!” form will be displayed for the user to provide feedback.
Unsubscribing will use the standard method of one click unsubscribe as implemented by Campaign Monitor. However once a user unsubscribes they will be redirected to the unsubscribe page set up earlier with the following link:
the verify will be the confirmation link they used to signup and the entryid is the entry number of the form “Email Campaign – Double Opt In”.
When the user lands on the unsubscribe page their entry in the “Email Campaign – Double Opt In” is removed and then a form displayed “Email Campaign – Unsubscribe” asking for some feedback which is optional.
Notes on email delivery.
I personally use Mailgun https://www.mailgun.com/ and their respective plugin to ensure mail delivery for WordPress, nothing worse than not getting that initial email invite.
[send_campaign_join_email] can be used on checkout for example as it will silently run the code and only process the request if the normal conditions are met to send the confirmation email. For example
do_shortcode( '[send_campaign_join_email email_address="' . $subscribeEmail . '"]');