Identify Users On Wix
Identify Users on Wix
Learn how to automatically identify website visitors when they submit forms on your Wix site, enabling cross-device tracking and enriched visitor profiles in Lytical.
What this enables: When a visitor fills out a form (contact form, newsletter signup), Lytical will link their anonymous browsing history to their real identity. You'll see their name and email in the Identified Users report, and can track them across multiple devices and sessions.
Prerequisites
- Lytical tracking code installed on your Wix site
- Wix Premium plan (required for custom code)
- One or more Wix Forms on your site
Where to Add the Code
Wix offers two ways to add custom tracking code:
Method 1: Custom Code in Dashboard (Recommended)
- Go to your Wix Dashboard
- Click Settings → Custom Code
- Click + Add Custom Code
- Paste the script
- Set placement to Body - end
- Apply to All pages
- Click Apply
Method 2: Wix Editor (Dev Mode)
- Open Wix Editor
- Enable Dev Mode (toggle in top menu)
- Click the code panel at the bottom
- Add code to the masterPage.js file for site-wide execution
Wix Forms Integration
Wix Forms use a custom event system. This script listens for form submissions and captures the email field.
<script>
// Lytical + Wix Form Integration
(function() {
// Store form data before submit
var pendingForms = new WeakMap();
// Helper: Extract fields from form
function extractFields(form) {
var data = {};
var inputs = form.querySelectorAll('input, textarea, select');
inputs.forEach(function(input) {
var name = input.name || input.getAttribute('data-field-label') ||
input.placeholder || input.id || '';
var value = input.value;
if (name && value) {
data[name.toLowerCase()] = value;
}
});
var result = {};
// Find email
for (var key in data) {
if (key.includes('email') || key.includes('e-mail')) {
result.email = data[key];
break;
}
}
// Find name
for (var key in data) {
if (key === 'name' || key.includes('full name') || key.includes('your name')) {
result.name = data[key];
break;
}
}
if (!result.name) {
var firstName = '', lastName = '';
for (var key in data) {
if (key.includes('first')) firstName = data[key];
if (key.includes('last')) lastName = data[key];
}
if (firstName || lastName) {
result.name = [firstName, lastName].filter(Boolean).join(' ');
}
}
// Find phone
for (var key in data) {
if (key.includes('phone') || key.includes('tel') || key.includes('mobile')) {
result.phone = data[key];
break;
}
}
return result;
}
// Detect source from page URL
function detectSource() {
var path = location.pathname.toLowerCase();
if (path.includes('contact')) return 'contact_form';
if (path.includes('newsletter')) return 'newsletter_signup';
if (path.includes('booking')) return 'booking_request';
return 'wix_form';
}
// Capture form data on submit
document.addEventListener('submit', function(e) {
var form = e.target;
if (form && form.tagName === 'FORM') {
pendingForms.set(form, extractFields(form));
}
}, true);
// Watch for Wix form success states
// Wix shows a success message after submission
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
mutation.addedNodes.forEach(function(node) {
if (node.nodeType === 1) {
// Check for Wix form success message
if ((node.getAttribute && node.getAttribute('data-testid') === 'thankYouMessage') ||
(node.className && node.className.includes && node.className.includes('thank-you')) ||
(node.className && node.className.includes && node.className.includes('success'))) {
// Find the associated form
var formContainer = node.closest('[data-testid="form-container"]') ||
node.closest('.wix-form') ||
node.parentElement;
if (formContainer) {
var form = formContainer.querySelector('form');
if (form) {
var fields = pendingForms.get(form);
if (fields && fields.email && typeof lyt !== 'undefined') {
lyt.identify(fields.email, {
email: fields.email,
name: fields.name || '',
phone: fields.phone || '',
source: detectSource()
});
console.log('[Lytical] Identified user:', fields.email);
}
}
}
}
}
});
});
});
observer.observe(document.body, {
childList: true,
subtree: true
});
// Alternative: Capture on submit (before success confirmation)
// Use this if the MutationObserver method doesn't work
document.addEventListener('click', function(e) {
var button = e.target.closest('button[type="submit"], input[type="submit"], [data-testid="submit-button"]');
if (!button) return;
var form = button.closest('form');
if (!form) return;
// Small delay to let form validate
setTimeout(function() {
var fields = extractFields(form);
if (fields.email && typeof lyt !== 'undefined') {
lyt.identify(fields.email, {
email: fields.email,
name: fields.name || '',
phone: fields.phone || '',
source: detectSource()
});
console.log('[Lytical] Identified user:', fields.email);
}
}, 100);
}, true);
})();
</script>
Wix Members Area
If you're using Wix Members, you can identify logged-in members. Add this script to identify users when they log in:
<script>
// Identify Wix Members
// Note: Wix member data access is limited in custom code
(function() {
// Check if user appears to be logged in
// Wix doesn't expose member data directly, but you can detect login state
// Method 1: Check for member area indicators
var memberIndicators = document.querySelectorAll(
'[data-testid="member-avatar"], ' +
'.member-avatar, ' +
'[data-hook="account-info"]'
);
if (memberIndicators.length > 0) {
console.log('[Lytical] Detected logged-in Wix member');
// Member is logged in, but email isn't directly accessible
// The form integration will still work when they submit forms
}
// Method 2: If using Wix Velo (Dev Mode), you can access member data
// Add this code to your page's code in Wix Editor:
/*
import wixUsers from 'wix-users';
$w.onReady(function () {
if (wixUsers.currentUser.loggedIn) {
wixUsers.currentUser.getEmail()
.then((email) => {
if (email && typeof lyt !== 'undefined') {
lyt.identify(email, {
email: email,
source: 'wix_member'
});
}
});
}
});
*/
})();
</script>
Using Wix Velo? If you have Dev Mode enabled, you can use Wix Velo's wix-users API to get member email directly. See the commented code above.
Wix Stores (E-commerce)
For Wix Stores, identifying customers at checkout is limited because Wix handles checkout on their own pages. However, you can identify customers when they:
- Log in to their member account (use the Members script above)
- Submit a contact form or newsletter signup
- Create an account during checkout (they'll be logged in afterward)
Wix Velo Method (Advanced)
If you're comfortable with Wix Velo (Dev Mode), you can get more reliable form tracking using Wix's built-in APIs. Add this to your site's masterPage.js:
// masterPage.js (Wix Velo)
import wixUsers from 'wix-users';
$w.onReady(function () {
// Identify logged-in members
if (wixUsers.currentUser.loggedIn) {
wixUsers.currentUser.getEmail()
.then((email) => {
if (email && typeof lyt !== 'undefined') {
lyt.identify(email, {
email: email,
wix_member_id: wixUsers.currentUser.id,
source: 'wix_member'
});
}
});
}
// Listen for member login
wixUsers.onLogin((user) => {
user.getEmail()
.then((email) => {
if (email && typeof lyt !== 'undefined') {
lyt.identify(email, {
email: email,
wix_member_id: user.id,
source: 'wix_login'
});
console.log('[Lytical] Identified user:', email);
}
});
});
});
// For Wix Forms, add this to pages with forms:
//
// import wixForms from 'wix-crm';
//
// $w('#form1').onWixFormSubmitted((event) => {
// const fields = event.fields;
// const email = fields.find(f => f.fieldType === 'email')?.fieldValue;
// const name = fields.find(f => f.fieldType === 'text' && f.label.toLowerCase().includes('name'))?.fieldValue;
//
// if (email && typeof lyt !== 'undefined') {
// lyt.identify(email, {
// email: email,
// name: name || '',
// source: 'wix_form'
// });
// }
// });
Troubleshooting
Users aren't appearing in Identified Users
- Make sure you have a Wix Premium plan (required for custom code)
- Verify the script placement is set to "Body - end"
- Check that Lytical tracking code loads before the identify script
- Open browser DevTools → Console and look for
[Lytical] Identified user:messages
Form field names vary
Wix Forms don't use consistent field names. The script tries to detect email/name fields by their labels and placeholders. If it's not working, open DevTools and inspect your form to see the actual field names, then update the script accordingly.
Testing the integration
- Open your website in an incognito/private browser window
- Open DevTools → Console before submitting the form
- Browse a few pages to generate anonymous activity
- Submit a form with a test email address
- Look for
[Lytical] Identified user: test@example.comin the console - Wait 1-2 minutes, then check the Identified Users page in Lytical
Need help? If you're having trouble with the integration, reach out to our support team and we'll help you get it set up. Email support@lytical.ai.