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 Context
- 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 gl_chat
Pass contact info via the gl_chat API:
// With data-key on script tag for auto-init
gl_chat('identify', {
id: 'cust_12345',
name: 'John Smith',
email: 'john@example.com'
});Or pass in init config:
gl_chat('init', {
apiKey: 'your-key',
customerId: 'cust_12345',
customerLabel: 'John Smith',
customerEmail: 'john@example.com'
});Minimum Required
At minimum, provide id (or customerId in init):
gl_chat('identify', { id: 'your-unique-id' });Contact Properties
Available Fields
| Field | Type | Description |
|---|---|---|
id | string | Unique identifier (required for tracking); use customerId in init |
name | string | Display name |
email | string | Email address |
| Custom fields | any | Any additional keys (e.g. plan, company) are passed as context to the AI |
Example with All Fields
gl_chat('identify', {
id: 'cust_12345',
name: 'John Smith',
email: 'john@example.com',
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) {
gl_chat('identify', {
id: user.id,
name: user.name,
email: user.email
});
}Contact Logout
When a user logs out, the widget retains the last identified customer until the page is refreshed. There is no programmatic "clear" method. For a fully anonymous session after logout, reload the page or ensure the widget script is loaded without prior identification.
Platform Examples
Shopify
<script src="https://api.goldilocks.chat/goldilocks.js" data-key="YOUR_API_KEY" async></script>
<script>
{% if customer %}
gl_chat('identify', {
id: '{{ customer.id }}',
name: '{{ customer.name }}',
email: '{{ customer.email }}',
ordersCount: {{ customer.orders_count }},
totalSpent: '{{ customer.total_spent }}',
tags: {{ customer.tags | json }}
});
{% endif %}
</script>WordPress / WooCommerce
Use data attributes for the script, then identify when user is logged in:
<?php if (is_user_logged_in()):
$user = wp_get_current_user();
?>
<script>
(window.gl_chat = window.gl_chat || function(){ (window.gl_chat.q = window.gl_chat.q || []).push(arguments); });
gl_chat('init', {
apiKey: 'your-key',
customerId: '<?php echo esc_js($user->ID); ?>',
customerLabel: '<?php echo esc_js($user->display_name); ?>',
customerEmail: '<?php echo esc_js($user->user_email); ?>'
});
</script>
<?php else: ?>
<script>
(window.gl_chat = window.gl_chat || function(){ (window.gl_chat.q = window.gl_chat.q || []).push(arguments); });
gl_chat('init', { apiKey: 'your-key' });
</script>
<?php endif; ?>
<script src="https://api.goldilocks.chat/goldilocks.js" async></script>React with Auth
function App() {
const { user, isAuthenticated } = useAuth();
useEffect(() => {
if (isAuthenticated && user) {
gl_chat('identify', {
id: user.id,
name: user.name,
email: user.email
});
}
// Note: On logout, the widget retains the last identity until page reload
}, [isAuthenticated, user]);
return <div>Your app</div>;
}Using JWT/Session
Queue the stub and identify before loading the script, so the widget picks up the contact when it initializes:
<script>
(window.gl_chat = window.gl_chat || function(){ (window.gl_chat.q = window.gl_chat.q || []).push(arguments); });
fetch('/api/current-user')
.then(res => res.json())
.then(user => {
if (user) {
gl_chat('identify', { id: user.id, name: user.name, email: user.email });
}
var s = document.createElement('script');
s.src = 'https://api.goldilocks.chat/goldilocks.js';
s.setAttribute('data-key', 'YOUR_API_KEY');
s.async = true;
document.body.appendChild(s);
});
</script>Contact Data Best Practices
What to Include
Recommended:
- Unique identifier
- Name/label
- 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
Keep payloads reasonable. The backend may enforce limits on field lengths and total size. Avoid sending very large objects or deeply nested structures.
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 for conversation continuity without login. Queue init before the embed script loads:
<script>
(window.gl_chat = window.gl_chat || function(){ (window.gl_chat.q = window.gl_chat.q || []).push(arguments); });
let visitorId = localStorage.getItem('goldilocks_visitor');
if (!visitorId) {
visitorId = 'visitor_' + Math.random().toString(36).substr(2, 9);
localStorage.setItem('goldilocks_visitor', visitorId);
}
gl_chat('init', { apiKey: 'your-key', customerId: visitorId, customerLabel: 'Visitor' });
</script>
<script src="https://api.goldilocks.chat/goldilocks.js" async></script>Option 3: Convert on Login
Start anonymous, convert when they log in:
// Initially anonymous - no identify call
// On login
gl_chat('identify', {
id: user.id,
name: user.name
});
// Future conversations linked to this IDPrivacy Considerations
User Consent
- 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
- Verify
idorcustomerIdis set - Ensure identify is called (before or after widget loads - it queues if called before)
- Verify ID is consistent across sessions
Data Not Showing
- Check identify payload format (valid object with string/number values)
- Keep payload size reasonable
- Check browser console for errors
History Not Persisting
- Confirm same
customerIdoridis used across sessions - Ensure the widget is loaded and identify is called correctly
- Verify the user is identified before starting a new conversation