Setting cookie upon successful form submission

Is there a way to set a cookie upon successful form submission of a popup? If so, how?

Please note, I would like for the cookie to be set on a successful form submission, not just any click on the submission button for a form.

Also, for my particular use case, I am not redirecting visitors to a confirmation page, so setting the cookie on a new page won’t work.

You can set a JavaScript cookie on the form confirmation window

https://www.w3schools.com/js/js_cookies.asp

Sorry, realized you said there isn’t a confirmation. Can you use onsubmit?
https://www.w3schools.com/tags/ev_onsubmit.asp

Or possibly test if an element is visible after the form is submitted?

Hey @Andy2,

You can set a cookie by pausing the form submit, setting the cookie and then releasing the form. This way only successful form submits would be “tagged”.

However, if you are using an Unbounce popup they are in an iFrame so you’ll run into issues retrieving the cookie afterwards.

Best,
Hristian

Thanks very much. Unfortunately, I am using an Unbounce popup. Given that, do you have any other suggestions? I also considered what @ravispl suggested, but it doesn’t appear that Unbounce offers any native way to fire off a cookie from the form confirmation dialog.

I’ve been trying to see if there’d be a trigger in GTM that I could base this on, but haven’t been ablet o figure that out either. If you are familiar with GTM and the triggers that may occur on a successful form submit from an Unbounce popup, do you have any ideas for how it could be accomplished that way?

Thank you!

This seems pretty straightforward; just fire some custom code (an alert or console log or something) in GTM listening for the gtm.formsubmit event.

When that’s working, add some cookie code instead (eg. https://www.analyticsmania.com/post/cookies-with-google-tag-manager/)

Cookies can be a pain to work with as they’re fussy over domains, but don’t see any problems as long as you only need to read the value from GTM.

Thanks very much for the reply. I have tried to do what you suggested, but in preview mode for GTM, it doesn’t seem to give me any info on actions that happen within the Unbounce popup, so I don’t know what rules I should be setting for when the tag should be triggered.

Do you have any suggestions for how to overcome this? Perhaps there’s a more sophisticated way to determine what rules to set?

So many opportunities to go wrong here, little vid for you - https://www.loom.com/share/40d3c6b70eae48a4b11a765f8726a995

That’s super helpful, thank you! I have GTM installed at the domain level via script manager in Unbounce, but I guess that that does not apply to popups?

As for the form submission trigger, I want to add a filter to ensure it only applies to a specific form. I assume that something like “Form Classes”, “Form Element” or “Form ID” would be best to use? Do you have any suggestions for which to use, and also to identify the proper value to use for whichever I select?

No prob. I’m not aware of any reason domain level script wouldn’t work, just wanted to convey that it does need to be installed on Unbounce :slight_smile:

Form class or ID are fine. Specificity is normally best so normally I’d say ID, but in Unbounce it’s possible to have a form ID of #lp-pom-form-16 (for example) on multiple forms (weird), so I would recommend giving your form a custom class like this:

image

… and then targeting it in GTM like this (“Form classes” is a built in variable):

Alternatively, you can just do it by the page location if that fits your needs.

Thanks again! I just added a custom class, but when I preview in GTM with a click listener, I don’t see my custom value showing up in “Form Classes” or any other field. Any thoughts?