Turret’s event tracking captures user interactions along with free-form text metadata. The API analyzes this metadata to automatically group similar events into semantic clusters and track how users flow through different topics within conversations.
Event name (e.g., “user_message”, “search_query”). Used to categorize events.
session_id
Auto-generated
Your conversation/thread ID. Critical for journey tracking. If not provided, Turret generates a UUID and returns it in the response.
user_id
Auto-generated
Your user’s ID. Enables cross-session analysis. If not provided, Turret generates a UUID and returns it in the response.
metadata
Yes
Object containing the data to cluster. The key (e.g., “prompt”) becomes the clustering dimension. The value is the text that gets semantically clustered.
Store these IDs and include them in subsequent requests to maintain session continuity. This is how Turret connects multiple messages into a conversation journey.
If you already have conversation/user IDs, pass them directly:
Copy
await fetch('https://api.useturret.com/track', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-API-Key': 'your-api-key' }, body: JSON.stringify({ name: 'user_message', session_id: myConversationId, // Your existing conversation ID user_id: myUserId, // Your existing user ID metadata: { prompt: userMessage } })});// Response still returns the IDs, but they'll match what you sent
import requestsimport osclass TurretClient: def __init__(self, api_key): self.api_key = api_key self.session_id = None self.user_id = None def track_message(self, prompt): response = requests.post( 'https://api.useturret.com/track', headers={ 'X-API-Key': self.api_key, 'Content-Type': 'application/json' }, json={ 'name': 'user_message', 'session_id': self.session_id, # None on first call 'user_id': self.user_id, # None on first call 'metadata': {'prompt': prompt} } ) response.raise_for_status() data = response.json() # Store IDs for subsequent messages self.session_id = data['session_id'] self.user_id = data['user_id'] return data def new_conversation(self): """Call this when starting a new conversation""" self.session_id = None# Usageturret = TurretClient(os.getenv('TURRET_API_KEY'))# First message - IDs auto-generatedturret.track_message('How do I reset my password?')# Subsequent messages - same sessionturret.track_message('Thanks! How do I change my email?')# New conversationturret.new_conversation()turret.track_message('What are your pricing plans?')
Turret automatically analyzes your metadata fields and classifies them:
Type
Description
Usage
text
Free-form text content
Semantically clustered into topics
enum
Categorical values with limited options
Available for segmentation/filtering
number
Numeric values
Available for aggregation
Field types are detected automatically when you first send events with new metadata keys. You can override these classifications in Settings → Metadata if needed. See Segmentation for more details.
Embedding Generation: Turret generates a vector embedding for the metadata value (e.g., the prompt text) using an embedding model.
Semantic Clustering: Events are grouped into clusters based on embedding similarity. Similar prompts end up in the same cluster, even if they use different words:
“How do I reset my password?” and “I forgot my login credentials” → Same cluster
Cluster Labeling: Clusters are automatically labeled with human-readable descriptions using an LLM (e.g., “Password Reset Requests”).
Track each message a user sends to your AI chatbot:
Copy
// When user sends a message to your chatbotconst { session_id, user_id } = await turret.trackMessage(userMessage);// Store session_id with your conversation state// Include it in all subsequent messages in this conversation
Track support conversations - use ticket ID as session_id:
Copy
{ "name": "support_message", "session_id": "ticket_12345", "user_id": "customer_789", "metadata": { "prompt": "I can't log into my account after the update" }}