Setting identity of a visitor

Sometimes you need to identify visitors by sending form data into Triggerbee. This article will take you through how to do it with javascript. 

Triggerbee contact fields and variables 

Contact information Default Js Variable
Email Yes mtr_custom.session.email
Name Yes mtr_custom.session.name
Organization Yes mtr_custom.session.organization
Telephone Yes mtr_custom.session.telephone
Title Yes mtr_custom.session.title
Username Yes mtr_custom.session.username
Shoe size No mtr_custom.session. shoesize
Gender No mtr_custom.session. gender
Website No mtr_custom.session. website
Country No mtr_custom.session. country
Any custom variable No mtr_custom.session. my-own-variable


How to identify a visitor from a form submission

Here's a full example of how to identify a visitor from a form submission such as a login form or contact form. 

This javascript needs to be run when the form is submitted.

// Start by finding the form class or ID<br>// Declare variables for each field you want to send to Triggerbee
// Declare a goal name to be set when the form is submitted
var form = document.querySelector('.myform');
var emailIdentifier = 'input[type="email"]';
var firstNameIdentifier = 'input[name="your-firstname"]';
var goalName = 'Form submission';

// Add an event listener and listen for the submit event
form.addEventListener('submit', function () {

 // Start by storing any existing customer variables or create a new object locally
 var tbContact = window.mtr_custom || {};

 // Get existing session/visit data or create a new object
 tbContact.session = tbContact.session || {};

 // Find the input for email, and set it as a contact variable
 var email = document.querySelector(emailIdentifier).value;
 tbContact.session.email = email;

 // Find the input for first name and set it as a contact variable
 var name = document.querySelector(firstNameIdentifier).value;
 tbContact.session.name = name;

 // Make sure Triggerbee's tracker picks up the contact data
 window.mtr_custom = tbContact;

 // The last step is to send the contact data to Triggerbee and identify the visitor by setting a goal
 mtr.goal(goalName);

});

Tip: If you don't want to add a goal you can use mtr.log ("Form submission"); instead. 

Extending the Contact object with Custom Fields

You can extend the Contact object with custom fields. Read more here.

Still need help? Contact Us Contact Us