Skip to content

Frontend Recording

The easiest way to record messages is directly from your frontend using the Growl SDK’s recordMessage() method.

// Record a user message
await window.GrowlAds.recordMessage({
message: "Hello, how can you help?",
chat_id: "chat_123",
user_id: "user_456",
role: "user",
});
// Record an AI assistant response
await window.GrowlAds.recordMessage({
message: "I can help you with that!",
chat_id: "chat_123",
user_id: "user_456",
role: "assistant",
});
// In your chat component
async function handleUserMessage(message, chatId, userId) {
// Record user message immediately
const userMsgRecordPromise = window.GrowlAds.recordMessage({
message: message,
chat_id: chatId,
user_id: userId,
role: "user",
});
// Send to your backend for processing
const response = await fetch("/api/chat", {
method: "POST",
body: JSON.stringify({ message, chatId }),
});
const aiResponse = await response.json();
// Record assistant response
await Promise.all([
userMsgRecordPromise,
window.GrowlAds.recordMessage({
role: "assistant",
message: aiResponse.text,
chat_id: chatId,
user_id: userId,
}),
]);
}