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?