Including webpage URL in VoiceFlow chatbot conversation logs

I want to capture the current page URL where users interact with my VoiceFlow chatbot and include it in the conversation transcripts. This would help me track which pages generate the most questions from users.

(function(document, scriptTag) {
  var widget = document.createElement(scriptTag), firstScript = document.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: "start",
            payload: {
            page_url: window.location.href
            }
        }
        },
        autostart: false
    });
  }
  widget.src = "https://cdn.voiceflow.com/widget/bundle.mjs"; 
  widget.type = "text/javascript"; 
  firstScript.parentNode.insertBefore(widget, firstScript);
})(document, 'script');

I also tried this approach:

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

The variable previous_event seems undefined and I’m not sure how this connects to the transcript logging. Any ideas on the correct way to pass page URL data to VoiceFlow transcripts?

You’re mixing client-side JavaScript with Voiceflow’s internal variables. The previous_event approach only works inside Voiceflow’s canvas with their built-in functions - not in your embed script. Your first approach with launch payload is right, but you need to capture the data properly in your flow. Create a page_url variable and use a Set Variable block right after Start to capture {launch.payload.page_url}. This stores the URL for the whole session. For transcripts, either use a Custom Action to send this to your analytics service, or append it to user messages with a Code block. I store it as a session variable and reference it throughout - works reliably for tracking.

hey, looks like you gotta keep the page_url in a global variable, then use it in your flow. previous_event is just for Voiceflow, so it won’t work in your js code. try custom actions to log that url in transcripts!