https://retellai.com/?utm_source=discord&utm_medium=seo logo
can the chatbot deployed in a website understand w...
# ❓・ai-evy-support
d
@AI Evy can the chatbot deployed in a website understand which page the user is on when the user has sent a message?
a
Thanks for tagging me @dzei. I'll look through relevant sources and get back to you shortly.
### Answer The Retell chat widget does not automatically detect which page the user is on. However, you can pass this information using dynamic variables. The chat widget supports a
data-dynamic
attribute where you can inject custom data: [(1) ]()
Copy code
html
<script
  id="retell-widget"
  src="<https://dashboard.retellai.com/retell-widget.js%22>
  type="module"
  data-public-key="YOUR_RETELL_PUBLIC_KEY"
  data-agent-id="YOUR_CHAT_AGENT_ID"
  data-dynamic='{"key": "value"}'
></script>
You could populate this with the current page URL or page name using JavaScript on your website. For example, you might set
data-dynamic='{"current_page": "pricing"}'
and then reference
{{current_page}}
in your agent's prompt. [(2) ]() Dynamic variables can be used in prompts, begin messages, tool configurations, and more. Check out these potentially useful sources: [Dynamic Variables]() , [Retell Website Widget]() Would you like a general answer on how to dynamically set the
data-dynamic
attribute based on the current page?
​ To learn more, see the sources I considered: [[1] Retell Website Widget](https://docs.retellai.com/deploy/chat-widget) [[2] Dynamic Variables](https://docs.retellai.com/build/dynamic-variables) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
d
yes
@AI Evy yes
a
Thanks for the follow-up, @dzei. I'll get back to you soon.
### Answer To dynamically set the
data-dynamic
attribute based on the current page, you can use JavaScript to inject the page information before the widget loads. Here's a general approach:
Copy code
html
<script>
  // Get the current page path or title
  const currentPage = window.location.pathname;
  // Or use: document.title, or a custom page identifier
  
  // Create the dynamic variables object
  const dynamicVars = JSON.stringify({
    "current_page": currentPage
  }) ;
  
  // Set the attribute on the widget script
  document.addEventListener('DOMContentLoaded', function() {
    const widgetScript = document.getElementById('retell-widget') ;
    if (widgetScript) {
      widgetScript.setAttribute('data-dynamic', dynamicVars) ;
    }
  }) ;
</script>

<script
  id="retell-widget"
  src="<https://dashboard.retellai.com/retell-widget.js%22>
  type="module"
  data-public-key="YOUR_RETELL_PUBLIC_KEY"
  data-agent-id="YOUR_CHAT_AGENT_ID"
></script>
Then in your agent's prompt, reference the variable using double curly braces: [(1) ]()
Copy code
The user is currently on page: {{current_page}}
Dynamic variables can be used in prompts, begin messages, tool configurations, and more. You can also use
window.location.href
for the full URL, or define custom page names based on your routing logic.
​ To learn more, see the sources I considered: [[1] Dynamic Variables](https://docs.retellai.com/build/dynamic-variables) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.