Including webpage URL in VoiceFlow chatbot conversation logs

I need help capturing the current page URL and including it in my VoiceFlow chatbot transcripts. This would help me track which pages users are on when they start conversations with the bot.

I attempted this approach but it’s not working:

(function(doc, scriptTag) {
  var widget = doc.createElement(scriptTag), existing = doc.getElementsByTagName(scriptTag)[0];
  widget.onload = function() {
    window.voiceflow.chat.load({
      verify: { projectID: 'YOUR_PROJECT_ID_HERE' },
      url: 'https://general-runtime.voiceflow.com',
      versionID: 'production',
      launch: {
        event: {
            type: "launch",
            payload: {
            page_url: window.location.href
            }
        }
        },
        autostart: false
    });
  }
  widget.src = "https://cdn.voiceflow.com/widget/bundle.mjs"; 
  widget.type = "text/javascript"; 
  existing.parentNode.insertBefore(widget, existing);
})(document, 'script');

I also tried extracting the URL like this:

if (previous_event) {
  page_url = previous_event.payload.page_url
} else {
  page_url = "unknown"
}

The issue is that previous_event seems undefined and I’m not sure how this would actually appear in the transcript logs. Any suggestions on the correct way to implement this?

try window.voiceflow.chat.proactive.clear() first, then use window.voiceflow.chat.interact() with your url payload instead of launch event. the transcript will show custom payloads when you send them through interact method rather than launch config.

Your launch event syntax looks right, but you might not be able to grab the payload that way. I ran into the same thing and found custom variables work way better. Once the chat loads, try this: window.voiceflow.chat.interact({ type: 'intent', payload: { query: '', intent: { name: 'set_page_url' }, entities: [{ name: 'page_url', value: window.location.href }] } }) - it sends the URL as a structured entity. Then just use a capture step in your VoiceFlow to grab the page_url entity. This way the URL shows up in your transcript logs and you can use it anywhere in the flow.