Skip to content

User Identification

The identify() method is the core of ExtensionLogin. It captures user data and sends it to your configured CRMs.

Basic Usage

javascript
const result = await ExtensionLogin.identify({
  email: 'user@example.com'
});

if (result.success) {
  console.log('User identified:', result.user);
} else {
  console.error('Error:', result.error);
}

Identify Options

Required Fields

FieldTypeDescription
emailstringUser's email address (required)

Optional Fields

FieldTypeDescription
namestringUser's full name
firstNamestringUser's first name
lastNamestringUser's last name
phonestringPhone number
metadataobjectCustom key-value data

Full Example

javascript
const result = await ExtensionLogin.identify({
  // Required
  email: 'john.doe@example.com',

  // Standard fields
  name: 'John Doe',
  firstName: 'John',
  lastName: 'Doe',
  phone: '+1-555-123-4567',

  // Custom metadata
  metadata: {
    company: 'Acme Inc',
    plan: 'premium',
    source: 'chrome_extension'
  }
});

Response Format

Success Response

javascript
{
  success: true,
  user: {
    id: 'usr_a1b2c3d4e5',
    email: 'john.doe@example.com',
    name: 'John Doe',
    firstName: 'John',
    lastName: 'Doe',
    phone: '+1-555-123-4567',
    metadata: {
      company: 'Acme Inc',
      plan: 'premium',
      source: 'chrome_extension'
    },
    createdAt: '2024-01-15T10:30:00Z',
    updatedAt: '2024-01-15T10:30:00Z'
  }
}

Error Response

javascript
{
  success: false,
  error: {
    code: 'INVALID_EMAIL',
    message: 'Please provide a valid email address'
  }
}

Email Validation

ExtensionLogin validates email addresses before processing:

javascript
// Valid emails
await ExtensionLogin.identify({ email: 'user@example.com' }); // ✓
await ExtensionLogin.identify({ email: 'user.name@company.co.uk' }); // ✓

// Invalid emails
await ExtensionLogin.identify({ email: 'invalid' }); // ✗ Returns error
await ExtensionLogin.identify({ email: '' }); // ✗ Returns error
await ExtensionLogin.identify({ email: null }); // ✗ Returns error

Updating User Data

Calling identify() with the same email updates the existing user:

javascript
// First identification
await ExtensionLogin.identify({
  email: 'user@example.com',
  name: 'John'
});

// Later update - same email, new data
await ExtensionLogin.identify({
  email: 'user@example.com',
  name: 'John Doe',
  phone: '+1-555-123-4567'
});
// User is updated, not duplicated

Handling Form Input

Common pattern for capturing form data:

javascript
// HTML
// <input type="email" id="email" />
// <input type="text" id="name" />
// <button id="submit">Sign Up</button>

document.getElementById('submit').addEventListener('click', async () => {
  const email = document.getElementById('email').value.trim();
  const name = document.getElementById('name').value.trim();

  if (!email) {
    showError('Email is required');
    return;
  }

  const result = await ExtensionLogin.identify({
    email,
    name: name || undefined // Don't send empty strings
  });

  if (result.success) {
    showSuccess('Welcome!');
  } else {
    showError(result.error.message);
  }
});

Using with Custom Fields

Send additional data that gets passed to your CRMs:

javascript
const result = await ExtensionLogin.identify({
  email: 'user@example.com',
  name: 'John Doe',
  metadata: {
    // These can be mapped to CRM fields
    extensionVersion: chrome.runtime.getManifest().version,
    installedAt: new Date().toISOString(),
    referralSource: 'product_hunt',
    userAgent: navigator.userAgent
  }
});

See Custom Fields for CRM field mapping.

Async/Await vs Promises

Both patterns work:

javascript
// Async/await (recommended)
async function identifyUser() {
  const result = await ExtensionLogin.identify({
    email: 'user@example.com'
  });
  return result;
}

// Promises
function identifyUser() {
  return ExtensionLogin.identify({
    email: 'user@example.com'
  }).then(result => {
    return result;
  });
}

Error Handling Best Practices

Always handle potential errors:

javascript
async function safeIdentify(userData) {
  try {
    const result = await ExtensionLogin.identify(userData);

    if (result.success) {
      return { success: true, user: result.user };
    } else {
      // API returned an error
      console.error('Identify error:', result.error);
      return { success: false, error: result.error };
    }
  } catch (error) {
    // Network or unexpected error
    console.error('Network error:', error);
    return {
      success: false,
      error: { code: 'NETWORK_ERROR', message: 'Please check your connection' }
    };
  }
}

CRM Integration

When you call identify(), data is automatically sent to your configured CRMs:

javascript
// This single call:
await ExtensionLogin.identify({
  email: 'user@example.com',
  name: 'John Doe'
});

// Automatically sends data to:
// - ClickFunnels (if configured)
// - GoHighLevel (if configured)
// - Your webhook endpoints (if configured)

See CRM Integration for setup instructions.

Next Steps

Built for Chrome Extension Developers