This sample HTML snippet shows how to pick user attributes from a form being submitted and send those attributes back to Blueshift as an event.

This example demonstrates a basic unsubscribe form and creates an "identify" event to update the "unsubscribed" attribute of a user. This script can collect any form attribute and can be used to create any kind of event.


How to use this snippet

  1. Replace EVENT_API_KEY with your event api key. ( skip this step if blueshift.js is already loaded )
  2. Select your form via a css selector ( eg $("#bsftForm") )
  3. Update the keyMapping to map the names of your form inputs you want to capture with the corresponding attribute in Blueshift.

Mapping Attributes

Problem: Sometimes the same piece of data is called different names in different systems.

Example: The form below has an input named "does_not_accept_offers", which is represented as "unsubscribed" in Blueshift.

Solution: To solve this discrepancy, the script used the keyMapping to translate "does_not_accept_offers" into "unsubscribed" when the event is created.

var keyMapping = {
  'email': 'email',
  'does_not_accept_offers': 'unsubscribed',

** Note even though "email" is called "email" in both systems, it is including in the keyMapping as well to signify that it is an attribute to send along. The form tracking script only pays attention to attributes that are in the keyMapping.

  • Sample unsubscribe.html
<form action="" method="post" id="bsftForm">
  <label for="email">
    <input type="email" name="email">
  <label for="does_not_accept_offers">
    <select name="does_not_accept_offers" id="">
      <option value="true">Remove me from future emails</option>
      <option value="false">Keep sending me emails</option>
  <input type="submit" value="Submit">

  // get blueshift
  window._blueshiftid='EVENT_API_KEY';window.blueshift=window.blueshift||[];if(blueshift.constructor===Array){blueshift.load=function(){var d=function(a){return function(){blueshift.push([a].concat(,0)))}},e=["identify","track","click","pageload","capture","retarget"];for(var f=0;f<e.length;f++)blueshift[e[f]]=d(e[f])};}
  if(blueshift.constructor===Array){(function(){var b=document.createElement("script");b.type="text/javascript",b.async=!0,b.src=("https:"===document.location.protocol?"https:":"http:")+"//";var c=document.getElementsByTagName("script")[0];c.parentNode.insertBefore(b,c);})()}
  // get jQuery
  if (typeof jQuery == 'undefined') {
    function getJquery(success) {
      var script = document.createElement('script');
      script.src = '';
      var head = document.getElementsByTagName('head')[0],
      done = false;
      script.onload = script.onreadystatechange = function() {
        if (!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) {
          done = true;
          script.onload = script.onreadystatechange = null;
  } else {
  // track form submit
  var submitForm = false
  function trackForm() {
    var keyMapping = {
      'email': 'email',
      'does_not_accept_offers': 'unsubscribed',
    $("#bsftForm").submit( function(event) {
      var formData = $(this).serializeArray();
      var params = {};
      $(formData).each( function(index,input) {
        if (keyMapping[] && ( input.value || input.value === false )) {
          params[keyMapping[]] = input.value
      if ( {
      if ( $(this).attr('target') === "_blank" ) {
        submitForm = true
      } else {
        setTimeout(function() {
          submitForm = true
        }, 100);
      return submitForm
Was this article helpful?
0 out of 0 found this helpful



Please sign in to leave a comment.