I’m trying to figure out how to capture the current webpage URL when users interact with my Voiceflow chatbot. The goal is to include this information in the conversation logs so I can see which pages users were on when they started asking questions.
The issue is that previous_event seems to be undefined, and I’m not sure this approach actually saves the URL to the transcript records. Has anyone successfully implemented this feature?
You’re making this way harder than it needs to be. Stop trying to do this manually - automation handles everything without the headaches.
Skip the Voiceflow API wrestling and custom JavaScript. Build a simple automation that captures and logs this data properly.
I hit the same wall last year with a customer support bot. Manual tracking always breaks because chat widgets have their own lifecycle that fights your tracking code.
Here’s what actually works: set up automation that watches page visits and chat interactions at the same time. Someone starts chatting? The automation grabs the current URL, timestamps it, and pushes everything to your logging system. No more undefined variables or vanishing payloads.
It handles all the timing issues and keeps your conversation logs clean. You can even grab extra stuff like user agent, referrer, or session data without touching your website code.
Way better scaling too. Multiple pages with the chatbot? Automation just works everywhere - no copying code around.
Your timing’s off - you’re trying to grab launch event data after Voiceflow already processed and tossed it. Had the exact same issue building a support bot for a multi-page app.
Here’s what actually works: use the user context API when the widget loads. Skip launch events and update your onload function like this:
This stores URL data in user context and sticks around for the whole conversation. The context automatically shows up in transcripts and your Voiceflow logic blocks can access it.
I’ve used this method for over a year across different projects - it grabs page context reliably without those undefined errors. Data always shows up clean in conversation logs.
Had the same problem a few months ago. The launch event payload doesn’t stick around like you’d think it would. What fixed it for me: skip the launch event entirely and set a custom variable right when the widget loads. Use window.voiceflow.chat.interact() to send a custom action that saves the URL as a session variable. Just add this to your onload function: window.voiceflow.chat.interact({ type: 'intent', payload: { intent: { name: 'set_page_url' }, entities: [{ name: 'url', value: window.location.href }] } }). Then create an intent handler for ‘set_page_url’ in your Voiceflow flow to grab the URL entity and store it. That variable stays available throughout the whole conversation and shows up in transcripts. Just make sure this runs before any user interaction so you capture the URL no matter how the conversation kicks off.
Try the API trace method instead. Add window.voiceflow.chat.proactive.clear() then push your URL data with window.voiceflow.chat.proactive.push({ type: 'text', payload: { message: 'Page: ' + window.location.href } }) right after the widget loads. This forces it into the conversation context and shows up in logs automatically. Way simpler than messing with launch events that disappear.
Been dealing with this exact scenario for years. Your approach won’t work because launch event payloads get wiped after initialization - previous_event will always be undefined when you reference it later.
Global state management is what works consistently. Set up a global variable when the page loads, then inject it into the conversation flow using the trace API.
Add this before your widget initialization:
window.currentPageContext = {
url: window.location.href,
timestamp: new Date().toISOString()
};
This bakes the URL data into the conversation transcript from the start. I’ve used this pattern across multiple implementations and it never fails to capture context properly.
Don’t rely on event payloads that disappear after processing. Store what you need in persistent scope and inject it when the conversation starts.