How to trigger a conversion event in NinjaForms using Javascript?

Got asked this one today, and stumped me for a little bit.

Ended up writing the following script to patch their account and deployed it as a Bento Personalization. This could have very well have just been placed in the footer of their site too.

First, it looks for all text fields submitted by NinjaForm and queues those fields in Bento. It then, looks for the email field and identifies the visitor then finally submits the event. 

var grabTextFields = Marionette.Object.extend({

  fieldType: 'textbox',

  initialize: function() {
    Backbone.Radio.channel( this.fieldType ).reply("get:submitData", this.getSubmitData );
  },
  
  getSubmitData: function( fieldData ) {
    bento.updateFields(fieldData);
  }
});

new grabTextFields();

var grabEmail = Marionette.Object.extend({

  fieldType: 'email',

  initialize: function() {
    Backbone.Radio.channel( this.fieldType ).reply("get:submitData", this.getSubmitData );
  },
  
  getSubmitData: function( fieldData ) {
    bento.identify(fieldData.value);
    bento.track("$optIn", {placement: "NinjaForms"});
  }
});

new grabEmail();
Leave a reply