Identify users and send events

Turn anonymous visitors into named contacts, attach their plan and company, and record the actions and payments that matter in your product.

5 min readUpdated 24 days ago
Before you start. The Rectify script must be on your site, and Analytics must be on for the project. Events count toward your plan's monthly analytics events, shown in Compare plans.
The script records page views, clicks and other activity on its own. Two things need your code: telling Rectify who a visitor is, and recording the actions that matter in your product. Rectify then links the visitor's activity, feedback and chats to one contact under Customers, Contacts.
Identify signed-in users
Pick one of these. Both work the same way.
In the script
Add userInfo to the object at the end of your Rectify script when someone is signed in. Rectify identifies them on every page load.
JavaScript
userInfo: {
  userId: 'user_123',
  email: '[email protected]',
  name: 'Jane Doe',
},
After sign-in
Call identify() once your app knows who the user is, for example after sign-in or sign-up, or in your root layout when a session exists.
JavaScript
window.RectifyInstance?.identify(user.id, {
  email: user.email,
  name: user.name,
  plan: 'pro',
});
Rectify remembers the identity in the visitor's browser, so you don't need to call it on every page. Calling it again with the same details sends nothing new.
Identify users and track revenue, in Setup guide under Customers, Contacts.
Identify users and track revenue, in Setup guide under Customers, Contacts.
You'll find these snippets under Customers, Contacts, Setup guide, and under Publish, Widget, Install.
What happens when you identify someone
•
Their earlier anonymous visits on that browser join their contact, so you see what they did before signing in.
•
Feedback and chats sent with the same email link to the contact.
•
Each trait is saved on its own. A later call without plan doesn't erase the plan you sent before.
•
If someone else already used that browser, the new person gets their own contact.
•
The first time a visitor becomes a contact, Rectify sends the Visitor becomes a contact event to your webhooks. See Signed webhooks.
If you pass no user ID, Rectify uses the email as the ID.
Traits Rectify uses
You can send any traits you like. These ones drive contact stages, companies and revenue:
TraitWhat it does
emailNames the contact and links their feedback and chats.
nameThe contact's display name.
planAny plan other than free makes them a Customer.
mrrA value above 0 makes them a Customer.
statuschurned, canceled or cancelled makes them Churned.
companyGroups contacts into a company. See below.
Every contact has one stage, worked out in this order:
StageWhen
Churnedstatus is churned, canceled or cancelled, or churned is true
Customermrr is above 0, or plan is set and isn't free
UserYou passed a user ID
LeadRectify knows their email
VisitorAnyone else
Rectify also reads plan, mrr and status from company when the contact has none of their own.
Group contacts into companies
Send a company object to group people from the same account:
JavaScript
window.RectifyInstance?.identify(user.id, {
  email: user.email,
  company: {
    id: 'acct_42',
    name: 'Acme',
    domain: 'acme.com',
    plan: 'pro',
    mrr: 490,
    seats: 20,
  },
});
•
company.id is your own account ID. It's the most reliable way to group people.
•
Without an ID, Rectify groups by company.domain, then by the domain of the person's work email. Personal email providers such as Gmail and Outlook are never grouped.
•
mrr, seats and plan show on the company under Customers, Contacts, Companies.
Record actions with track()
Track three to five actions that show someone is getting value, such as a project created or a report exported. Page views, clicks, form submissions, errors, downloads, outbound links and site searches are already recorded, so don't track those yourself.
JavaScript
window.RectifyInstance?.track('project_created', { template: 'blank' });
Use the same name every time for the same action. Custom events show on the contact's timeline, and you can build goals, segments and lead scoring on them.
Record payments with revenue()
JavaScript
window.RectifyInstance?.revenue(49, 'USD', { plan: 'pro' });
The amount must be a number. The currency defaults to USD. Revenue goals and the Revenue alert use these payments.
Keep sensitive things out
Form field values are never sent, only field names and whether each one was filled. For anything else, mark your HTML:
HTML
<div class="rectify-no-capture">Nothing in here produces an event.</div>
<div data-rectify-mask>Events still fire, but text and values are dropped.</div>
<input name="coupon" data-rectify-capture-value />
data-rectify-capture-value opts a single field's value in. It never works for card numbers, security codes and similar fields.
Never put passwords, card numbers or tokens in traits or event properties.
Check it worked
1.
Sign in to your own site.
2.
In Rectify, open Customers, Contacts. Your contact shows with your name and email.
3.
Open the contact. Your page views, and any custom events, show on the timeline.
Troubleshooting
The contact never gets a name or email
Rectify only accepts identity from your own site. If your project has a website address, identify() and userInfo count only on that domain, its subdomains and localhost. Check that your project's website address matches your live site.
Nothing arrives at all
•
Check Analytics Settings shows On. Open Customers, Analytics and select the settings button at the top right.
•
Browsers that send Do Not Track are skipped while Respect Do Not Track is on, under Capture.
•
A visitor who opted out with optOut() sends nothing until optIn() runs.
Two people share one computer
When a second person signs in on the same browser, call identify() with their details. Rectify gives them their own contact instead of overwriting the first one.

Was this helpful?

Your feedback shapes what we write next.

Related articles