Frontend Recording
Overview
Section titled “Overview”The easiest way to record messages is directly from your frontend using the Growl SDK’s recordMessage() method.
// Record a user messageawait window.GrowlAds.recordMessage({ message: "Hello, how can you help?", chat_id: "chat_123", user_id: "user_456", role: "user",});
// Record an AI assistant responseawait window.GrowlAds.recordMessage({ message: "I can help you with that!", chat_id: "chat_123", user_id: "user_456", role: "assistant",});Example: Chat Integration
Section titled “Example: Chat Integration”// In your chat componentasync 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, }), ]);}