Skip to content

Instantly share code, notes, and snippets.

@ianstormtaylor
Last active July 23, 2018 02:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ianstormtaylor/5111140 to your computer and use it in GitHub Desktop.
Save ianstormtaylor/5111140 to your computer and use it in GitHub Desktop.
Tracking an email signup form, where you don't know the user's identity until the form is submitted, and the form is actually submitted to a 3rd-party mailing list so you don't have control over what happens when it's submitted.
// Grab the form using whichever DOM library you're using, or
// even just with `querySelector`.
var $form = $('#my-form');
// Call `trackForm` with your form, and a callback function
// instead of a normal `properties` object. The function will
// receive the form element as it's first argument.
analytics.trackForm($form, "Email Signup", function (form) {
// Find the email input and get it's value.
var email = $(form).find('.email-address').val();
// Send off the identify.
analytics.identify(email);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment