Identify Users On Wordpress
Identify Users on WordPress
Learn how to automatically identify website visitors when they submit forms on your WordPress 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, registration), 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 WordPress site
- One or more forms on your site (using any plugin listed below)
Where to Add the Code
Add the integration script to your WordPress site using one of these methods:
Theme Footer (Recommended)
Go to Appearance → Theme Editor → footer.php and paste the script just before the closing </body> tag.
Code Snippets Plugin
Use a plugin like Code Snippets or WPCode to add the script site-wide without editing theme files. Set it to run in the footer on all pages.
Child Theme
If you're using a child theme, add the script to your child theme's functions.php using wp_footer hook.
Choose Your Form Plugin
Select the integration method that matches your form plugin:
| Form Plugin | Detection Method |
|---|---|
| Gravity Forms | gform_confirmation_loaded event |
| WPForms | wpformsAjaxSubmitSuccess event |
| Contact Form 7 | wpcf7mailsent event |
| Ninja Forms | nfFormSubmitResponse event |
| Elementor Forms | submit_success event |
| Formidable Forms | frmFormComplete event |
| Fluent Forms | fluentform_submission_success event |
Not sure which plugin you have? Use the Universal Script below — it listens for all major WordPress form plugins at once.
Universal Script (Recommended)
This script listens for form submission events from all major WordPress form plugins. Copy and paste it into your site footer.
<script>
// Lytical + WordPress Form Integration (Universal)
// Works with Gravity Forms, WPForms, Contact Form 7, Ninja Forms,
// Elementor, Formidable, and Fluent Forms
(function() {
// Helper: Extract email and name from form data
function extractFields(data) {
var result = {};
var emailKeys = ['email', 'your-email', 'email_address', 'user_email', 'contact_email'];
var nameKeys = ['name', 'your-name', 'full_name', 'contact_name'];
var firstNameKeys = ['first_name', 'firstname', 'fname', 'first-name', 'your-first-name'];
var lastNameKeys = ['last_name', 'lastname', 'lname', 'last-name', 'your-last-name'];
var phoneKeys = ['phone', 'telephone', 'mobile', 'phone_number', 'your-phone'];
// Find email
for (var key in data) {
var lowerKey = key.toLowerCase();
if (emailKeys.some(function(k) { return lowerKey.includes(k); })) {
result.email = data[key];
break;
}
}
// Find name (try full name first, then first + last)
for (var key in data) {
var lowerKey = key.toLowerCase();
if (nameKeys.some(function(k) { return lowerKey === k; })) {
result.name = data[key];
break;
}
}
if (!result.name) {
var firstName = '', lastName = '';
for (var key in data) {
var lowerKey = key.toLowerCase();
if (firstNameKeys.some(function(k) { return lowerKey.includes(k); })) firstName = data[key];
if (lastNameKeys.some(function(k) { return lowerKey.includes(k); })) lastName = data[key];
}
if (firstName || lastName) {
result.name = [firstName, lastName].filter(Boolean).join(' ');
}
}
// Find phone
for (var key in data) {
var lowerKey = key.toLowerCase();
if (phoneKeys.some(function(k) { return lowerKey.includes(k); })) {
result.phone = data[key];
break;
}
}
return result;
}
// Helper: Send identify call
function identifyUser(fields, source) {
if (!fields.email || typeof lyt === 'undefined') return;
lyt.identify(fields.email, {
email: fields.email,
name: fields.name || '',
phone: fields.phone || '',
source: source
});
console.log('[Lytical] Identified user:', fields.email);
}
// Store form data before submit (some plugins clear fields on success)
var pendingFormData = {};
document.addEventListener('submit', function(e) {
var form = e.target;
if (!form || form.tagName !== 'FORM') return;
var formId = form.id || form.getAttribute('data-formid') || 'form_' + Date.now();
pendingFormData[formId] = Object.fromEntries(new FormData(form));
}, true);
// Gravity Forms
if (typeof jQuery !== 'undefined') {
jQuery(document).on('gform_confirmation_loaded', function(event, formId) {
var data = pendingFormData['gform_' + formId] || pendingFormData['form_' + formId] || {};
var fields = extractFields(data);
identifyUser(fields, 'gravity_forms');
});
}
// WPForms
document.addEventListener('wpformsAjaxSubmitSuccess', function(e) {
var form = e.target;
if (!form) return;
var data = Object.fromEntries(new FormData(form));
var fields = extractFields(data);
identifyUser(fields, 'wpforms');
});
// Contact Form 7
document.addEventListener('wpcf7mailsent', function(e) {
var inputs = e.detail && e.detail.inputs ? e.detail.inputs : [];
var data = {};
inputs.forEach(function(input) {
data[input.name] = input.value;
});
var fields = extractFields(data);
identifyUser(fields, 'contact_form_7');
});
// Ninja Forms
if (typeof nfRadio !== 'undefined') {
nfRadio.channel('forms').on('submit:response', function(response) {
var data = {};
if (response.data && response.data.fields_by_key) {
Object.keys(response.data.fields_by_key).forEach(function(key) {
data[key] = response.data.fields_by_key[key].value;
});
}
var fields = extractFields(data);
identifyUser(fields, 'ninja_forms');
});
}
// Elementor Forms
if (typeof jQuery !== 'undefined') {
jQuery(document).on('submit_success', '.elementor-form', function(event, response) {
var form = event.target;
var formId = form.id || 'elementor_form';
var data = pendingFormData[formId] || {};
var fields = extractFields(data);
identifyUser(fields, 'elementor_forms');
});
}
// Formidable Forms
document.addEventListener('frmFormComplete', function(e) {
var form = e.target;
var data = Object.fromEntries(new FormData(form));
var fields = extractFields(data);
identifyUser(fields, 'formidable_forms');
});
// Fluent Forms
document.addEventListener('fluentform_submission_success', function(e) {
var data = e.detail || {};
var fields = extractFields(data);
identifyUser(fields, 'fluent_forms');
});
})();
</script>
Plugin-Specific Scripts
If you prefer a lighter script for a single form plugin, use one of these instead:
Gravity Forms
<script>
// Store form data before submit (Gravity Forms clears fields on success)
var gfFormData = {};
document.addEventListener('submit', function(e) {
var form = e.target;
if (form && form.classList.contains('gform_wrapper')) {
var formId = form.querySelector('input[name="gform_submit"]');
if (formId) {
gfFormData[formId.value] = Object.fromEntries(new FormData(form));
}
}
}, true);
jQuery(document).on('gform_confirmation_loaded', function(event, formId) {
var data = gfFormData[formId] || {};
var email = data['input_' + getEmailFieldId(formId)] || data.email;
if (email && typeof lyt !== 'undefined') {
lyt.identify(email, {
email: email,
name: data.name || '',
source: 'gravity_forms'
});
}
});
// Helper: Find email field ID (customize based on your form)
function getEmailFieldId(formId) {
// Default email field IDs - adjust to match your form
return '2'; // Usually input_2 for email in Gravity Forms
}
</script>
WPForms
<script>
document.addEventListener('wpformsAjaxSubmitSuccess', function(e) {
var form = e.target;
if (!form) return;
var emailInput = form.querySelector('input[type="email"]');
var nameInput = form.querySelector('input[name*="name"]');
if (emailInput && emailInput.value && typeof lyt !== 'undefined') {
lyt.identify(emailInput.value, {
email: emailInput.value,
name: nameInput ? nameInput.value : '',
source: 'wpforms'
});
console.log('[Lytical] Identified user:', emailInput.value);
}
});
</script>
Contact Form 7
<script>
document.addEventListener('wpcf7mailsent', function(e) {
var inputs = e.detail.inputs || [];
var data = {};
inputs.forEach(function(input) {
data[input.name] = input.value;
});
var email = data['your-email'] || data['email'];
var name = data['your-name'] || data['name'];
if (email && typeof lyt !== 'undefined') {
lyt.identify(email, {
email: email,
name: name || '',
source: 'contact_form_7'
});
console.log('[Lytical] Identified user:', email);
}
});
</script>
WordPress User Login
To identify users when they log in to WordPress, add this to your theme's functions.php:
<?php
// Add Lytical identify call for logged-in users
add_action('wp_footer', function() {
if (is_user_logged_in()) {
$user = wp_get_current_user();
?>
<script>
if (typeof lyt !== 'undefined') {
lyt.identify('<?php echo esc_js($user->user_email); ?>', {
email: '<?php echo esc_js($user->user_email); ?>',
name: '<?php echo esc_js($user->display_name); ?>',
wordpress_user_id: '<?php echo esc_js($user->ID); ?>',
source: 'wordpress_login'
});
}
</script>
<?php
}
});
?>
How It Works
- Visitor browses your site — Lytical tracks their pageviews, clicks, and behavior anonymously
- Visitor submits a form — The script captures their email and name from the form fields
- Identity is created — Lytical links all their previous anonymous activity to their real identity
- Cross-device tracking begins — If they visit from another device and submit a form with the same email, both devices are linked
Troubleshooting
Users aren't appearing in Identified Users
- Verify the Lytical tracking code loads before the identify script
- Check that your form has an email field (required for identification)
- Open browser DevTools → Console and look for
[Lytical] Identified user:messages - Check for JavaScript errors in the console
Form field names don't match
Different form plugins use different field naming conventions. If identification isn't working, add console.log(data) before the identify call to see what field names your form uses, 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.