Goldilocks Docs
Developers

Contact Tracking

Identify contacts for personalized support and conversation continuity

Contact tracking lets you identify visitors so Goldilocks can provide personalized support and maintain conversation history across sessions.

Why Track Contacts?

Without identification, each visit is anonymous:

  • No conversation history
  • No personalization
  • No memory of preferences
  • Each session starts fresh

With identification:

  • Conversations persist across sessions
  • Contact memory is applied
  • Personalized responses
  • Better analytics

Basic Identification

Using Settings

Pass contact ID when loading the widget:

window.goldilocksSettings = {
  apiKey: 'your-key',
  customerId: 'cust_12345',
  customerLabel: 'John Smith'
};

Minimum Required

At minimum, provide customerId:

window.goldilocksSettings = {
  apiKey: 'your-key',
  customerId: 'your-unique-id'
};

Contact Properties

Available Fields

FieldTypeDescription
customerIdstringUnique identifier (required for tracking)
customerLabelstringDisplay name
customerEmailstringEmail address
customerDataobjectAdditional attributes

Example with All Fields

window.goldilocksSettings = {
  apiKey: 'your-key',
  customerId: 'cust_12345',
  customerLabel: 'John Smith',
  customerEmail: 'john@example.com',
  customerData: {
    plan: 'pro',
    company: 'Acme Corp',
    signupDate: '2023-01-15',
    totalOrders: 12,
    lastPurchase: '2024-01-10'
  }
};

Dynamic Identification

After Page Load

If contact logs in after widget loads:

// User logs in
function onUserLogin(user) {
  Goldilocks.setCustomer({
    id: user.id,
    label: user.name,
    email: user.email
  });
}

Contact Logout

When user logs out:

function onUserLogout() {
  Goldilocks.clearCustomer();
}

Platform Examples

Shopify

<script>
  window.goldilocksSettings = {
    apiKey: 'your-key',
    {% if customer %}
    customerId: '{{ customer.id }}',
    customerLabel: '{{ customer.name }}',
    customerEmail: '{{ customer.email }}',
    customerData: {
      ordersCount: {{ customer.orders_count }},
      totalSpent: '{{ customer.total_spent }}',
      tags: {{ customer.tags | json }}
    }
    {% endif %}
  };
</script>

WordPress / WooCommerce

<script>
  window.goldilocksSettings = {
    apiKey: 'your-key',
    <?php if (is_user_logged_in()): 
      $user = wp_get_current_user();
    ?>
    customerId: '<?php echo $user->ID; ?>',
    customerLabel: '<?php echo esc_js($user->display_name); ?>',
    customerEmail: '<?php echo esc_js($user->user_email); ?>'
    <?php endif; ?>
  };
</script>

React with Auth

function App() {
  const { user, isAuthenticated } = useAuth();
  
  useEffect(() => {
    if (window.Goldilocks) {
      if (isAuthenticated && user) {
        Goldilocks.setCustomer({
          id: user.id,
          label: user.name,
          email: user.email
        });
      } else {
        Goldilocks.clearCustomer();
      }
    }
  }, [isAuthenticated, user]);
  
  return <div>Your app</div>;
}

Using JWT/Session

// Get contact from your session
fetch('/api/current-user')
  .then(res => res.json())
  .then(user => {
    if (user) {
      window.goldilocksSettings = {
        apiKey: 'your-key',
        customerId: user.id,
        customerLabel: user.name,
        customerEmail: user.email
      };
    }
    loadGoldilocksScript();
  });

Contact Data Best Practices

What to Include

Recommended:

  • Unique identifier
  • Name/label
  • Email
  • Account type/plan
  • Relevant business data

Useful context:

  • Order count
  • Subscription status
  • Account age
  • Recent activity

What to Avoid

  • Passwords or credentials
  • Full credit card numbers
  • Sensitive personal data
  • Extremely large data sets

Data Limits

  • customerId: 256 characters max
  • customerLabel: 256 characters max
  • customerEmail: Standard email length
  • customerData: 10KB max (JSON)

Using Contact Data

In Conversations

Contact data is available to the AI:

  • Personalize greetings
  • Reference order history
  • Understand account context
  • Provide relevant help

In Memory

Combined with contact memory:

  • Remembered preferences
  • Previous conversation context
  • Extracted information from past chats

In Analytics

Track metrics by contact:

  • Conversation history
  • Resolution rates
  • Topic patterns

Anonymous Visitors

For non-logged-in visitors:

Option 1: Anonymous (Default)

Don't set customerId. Each session is independent.

Option 2: Local Storage ID

Generate and persist a local ID:

let visitorId = localStorage.getItem('goldilocks_visitor');
if (!visitorId) {
  visitorId = 'visitor_' + Math.random().toString(36).substr(2, 9);
  localStorage.setItem('goldilocks_visitor', visitorId);
}

window.goldilocksSettings = {
  apiKey: 'your-key',
  customerId: visitorId,
  customerLabel: 'Visitor'
};

This maintains conversation continuity without login.

Option 3: Convert on Login

Start anonymous, convert when they log in:

// Initially anonymous
window.goldilocksSettings = { apiKey: 'your-key' };

// On login
Goldilocks.setCustomer({
  id: user.id,
  label: user.name
});
// Future conversations linked to this ID

Privacy Considerations

  • Inform users about tracking
  • Comply with GDPR/CCPA if applicable
  • Provide opt-out if required

Data Access

Contacts can:

  • Request their data
  • Request deletion
  • View conversation history

See Security Settings for data management.

Troubleshooting

Contact Not Recognized

  1. Verify customerId is set
  2. Check it's set before widget loads
  3. Verify ID is consistent across sessions

Data Not Showing

  1. Check customerData format (valid JSON)
  2. Verify size is under limit
  3. Check browser console for errors

History Not Persisting

  1. Confirm same customerId used
  2. Check widget is identifying correctly
  3. Verify no clearCustomer() calls