Identify()

identify() lets you identify a person so that they don't have to manually enter their data (eg: email address, name, etc). This is particularly useful, for example, when you embed Maître on an internal page of your website where you already know the user's email (eg: a section of the website only logged in users can access).

To use  identify() you must call the following function AFTER the Maîte Tracking Code.

mtr("identify", {
  email: "john@smith.com",
  name: "John Smith",
  extra_field: "USA",
  extra_field_2: null,
  terms: true,
  upsert: false
}, false);

Properties

The mtr() function accepts three parameters:

  • The first parameter is a string that must always be "identify"
  • The second parameter is an object with the user data. At the bare minimum, the object must contain the email address of the user.
  • The third parameter is a boolean that informs us whether you want to override an existing session (see section "Force identification" for more details). The default is false and if you don't want to override the session, you can skip this altogether.

How it works

When the identify() function is called, Maître will check if a subscriber with that specific email address exists. If a subscriber is not found, a new subscriber is automatically created using the data sent over but the confirmation email (or the verification SMS) is not sent.

When a subscriber is identified (or created), a cookie is stored on their browser and, if present, the subscriberLoaded callback is triggered.

If you don't want to automatically create a new subscriber if one isn't found (for example if you want to allow your users to manually opt-in), set the upsert property to false.

If your form requires the acceptance of terms and conditions, you must set the terms property to true otherwise the identification will fail. Of course, you only need to do this in case you want to create a subscriber when none is found. In other words, you can ignore this if you set the upsert property to false.

Force identification

If a cookie session is already present (for example if the user has already been identified in the past), by default Maître will not attempt to identify the user again. We do this to improve the user experience so that your users don't have to wait (usually around 1 second) to be identified again.

If instead you want to identify your users every time, you must set the third parameter of the mtr() function to true. For example:

mtr("identify", {
  email: "john@smith.com",
  name: "John Smith",
  extra_field: "USA",
 }, true);

By doing so, Maître will ignore any existing cookie session and will try to identify the user again.

Our recommendation is to avoid this as much as possible because if you force the identification, Maître will attempt to check the existence of the subscriber every single time a person visits that page, causing a significant slow down of your website.

If you're using identify() on a page accessible only by logged in users you probably don't need to force the verification.

ReCaptcha

Unfortunately, if you're using ReCaptcha, identify() will not work. 

Full example

In the following example, we identify a user on our website and listen to the subscriberLoaded callback to print the subscriber's data in the console.

<html>
  <head>

    <!-- Maitre configuration file -->
    <script type="text/javascript">
      window.MaitreConfig = {
        callbacks: {
	  subscriberLoaded: function(response, data) {
            console.log(response);
            console.log(data);
          }
        }
      }
    </script>

   <!-- Maitre tracking code -->
   <script>!function(m,a,i,t,r,e){if(m.Maitre)return;r=m.Maitre={},r.uuid=t,r.loaded=0,r.base_url=i,r.queue=[],m.mtr=function(){r.queue.push(arguments)};e=a.getElementsByTagName('script')[0],c=a.createElement('script');c.async=!0,c.src=i+'/widget/'+t+'.js',e.parentNode.insertBefore(c,e)}(window,document,'https://maitreapp.co','MFe04ce5d062');</script>

   <!-- Maitre identify() -->
   <script type="text/javascript">
     mtr("identify", {
       email: "john@smith.com",
       name: "John Smith",
       extra_field: "USA",
       terms: true
      });
   </script>

  </head>

</html>

Still need help? Contact Us Contact Us