[DOCS]: If I want to add user_id in the first embedding method, iframe, how can I implement it? Currently, it can only be added through script #231

Closed
opened 2026-02-16 05:19:30 -05:00 by yindo · 4 comments
Owner

Originally created by @lilibo217 on GitHub (Aug 20, 2025).

Type of Documentation Change

Content update

Documentation Page URL or Path

No response

Current Content

If I want to add user_id in the first embedding method, iframe, how can I implement it? Currently, it can only be added through script

Suggested Changes

If I want to add user_id in the first embedding method, iframe, how can I implement it? Currently, it can only be added through script

Reason for Change

If I want to add user_id in the first embedding method, iframe, how can I implement it? Currently, it can only be added through script

Code of Conduct

  • I agree to follow Dify's documentation contribution guidelines
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report, otherwise it will be closed.
  • 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
  • Please do not modify this template :) and fill in all the required fields.
Originally created by @lilibo217 on GitHub (Aug 20, 2025). ### Type of Documentation Change Content update ### Documentation Page URL or Path _No response_ ### Current Content If I want to add user_id in the first embedding method, iframe, how can I implement it? Currently, it can only be added through script ### Suggested Changes If I want to add user_id in the first embedding method, iframe, how can I implement it? Currently, it can only be added through script ### Reason for Change If I want to add user_id in the first embedding method, iframe, how can I implement it? Currently, it can only be added through script ### Code of Conduct - [x] I agree to follow Dify's documentation [contribution guidelines](https://github.com/langgenius/dify/blob/0277a37fcad5ad86aeb239485c27fffd5cd90043/CONTRIBUTING.md) - [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [x] I confirm that I am using English to submit this report, otherwise it will be closed. - [x] 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :) - [x] Please do not modify this template :) and fill in all the required fields.
yindo added the documentationquestion labels 2026-02-16 05:19:30 -05:00
yindo closed this issue 2026-02-16 05:19:30 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Aug 20, 2025):

Hi @lilibo217! I'm Dosu and I’m helping the dify-docs team.

You can pass user_id in the iframe embedding method by appending it as a URL parameter, but it must be GZIP-compressed, Base64-encoded, and then URI-encoded. For example, to pass user_id with value apple, compress and encode it, then use a URL like:

<iframe src="http://localhost/chatbot/{token}?user_id=H4sIAAAAAAAAA0ssKMhJBQBQ0C6pBQAAAA%3D%3D" ... ></iframe>

Replace the value after user_id= with your own encoded string. The official docs describe this process for all input parameters, including user_id. Script embedding allows you to set user_id directly in the config, but for iframe embedding, you must use the URL parameter method as described above (docs reference).

If you experienced issues with user_id in iframe embedding, make sure you are using Dify version 1.7.2 or later, as earlier versions had known bugs with this feature (issue reference).

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Join Discord Share on X

@dosubot[bot] commented on GitHub (Aug 20, 2025): <!-- Greeting --> Hi @lilibo217! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the dify-docs team. <!-- Answer --> You can pass user_id in the iframe embedding method by appending it as a URL parameter, but it must be GZIP-compressed, Base64-encoded, and then URI-encoded. For example, to pass user_id with value apple, compress and encode it, then use a URL like: ``` <iframe src="http://localhost/chatbot/{token}?user_id=H4sIAAAAAAAAA0ssKMhJBQBQ0C6pBQAAAA%3D%3D" ... ></iframe> ``` Replace the value after user_id= with your own encoded string. The official docs describe this process for all input parameters, including user_id. Script embedding allows you to set user_id directly in the config, but for iframe embedding, you must use the URL parameter method as described above ([docs reference](https://github.com/langgenius/dify-docs/blob/28b872551226e11105164f29b7ed8a9e287436c3/en/guides/application-publishing/embedding-in-websites.mdx)). If you experienced issues with user_id in iframe embedding, make sure you are using Dify version 1.7.2 or later, as earlier versions had known bugs with this feature ([issue reference](https://github.com/langgenius/dify/issues/23682)). <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/d103649f-9774-423e-9cc7-5e9ef144ecb1?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/d103649f-9774-423e-9cc7-5e9ef144ecb1?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/d103649f-9774-423e-9cc7-5e9ef144ecb1?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/d103649f-9774-423e-9cc7-5e9ef144ecb1?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/d103649f-9774-423e-9cc7-5e9ef144ecb1?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/d103649f-9774-423e-9cc7-5e9ef144ecb1?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/d103649f-9774-423e-9cc7-5e9ef144ecb1?feedback_type=other)</sup>&nbsp;&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/langgenius/dify-docs/issues/422)
Author
Owner

@lilibo217 commented on GitHub (Aug 20, 2025):

Thank you very much for your reply. I have tried my way as you said. Here is my code. Perhaps my expression was not clear enough. I wanted to add user_id in the first embedding method iframe, and the effect is similar to the systemVariables: {user_i: '******'} embedded in the second bubble button. Passing different user_ids can recognize different users' historical conversations, but I found that changing this doesn't work. I don't know if my method was written incorrectly or if there is a problem with passing parameters. I sincerely request a reply. Thank you again。

<script setup&gt;
import { ref, onMounted, onBeforeUnmount } from 'vue'
import pako from 'pako'

const userId = '2effb417-3d43-49ba-8b36-e3da855313aa'
const iframeSrc = ref('')
const chatIframeRef = ref(null)
const maskVisible = ref(false)

function processData(data) {
&nbsp; &nbsp; const uint8Array = new TextEncoder().encode(data)
&nbsp; &nbsp; const gzipped = pako.gzip(uint8Array, { level: 6 })
&nbsp; &nbsp; const base64Str = btoa(String.fromCharCode(...gzipped))
&nbsp; &nbsp; return encodeURIComponent(base64Str)
}

const updateRootFontSize = () =&gt; {
&nbsp; &nbsp; const { documentElement } = document
&nbsp; &nbsp; const dpr = 3
&nbsp; &nbsp; const size = 1920
&nbsp; &nbsp; const offsetWidth = documentElement.offsetWidth
&nbsp; &nbsp; const w = offsetWidth &gt;= 750 ? offsetWidth : offsetWidth * dpr
&nbsp; &nbsp; documentElement.style.fontSize = `${(w / size) * 10}px`
}

onMounted(() =&gt; {
&nbsp; &nbsp; iframeSrc.value = `http://39.105.43.53:8089/chat/c5URJGdPrOTUl1XL?user_id=` + processData(userId)
&nbsp; &nbsp; console.log(iframeSrc.value)

&nbsp; &nbsp; updateRootFontSize()
&nbsp; &nbsp; const ev = 'orientationchange' in window ? 'orientationchange' : 'resize'
&nbsp; &nbsp; window.addEventListener(ev, updateRootFontSize)
})

onBeforeUnmount(() =&gt; {
&nbsp; &nbsp; const ev = 'orientationchange' in window ? 'orientationchange' : 'resize'
&nbsp; &nbsp; window.removeEventListener(ev, updateRootFontSize)
})
</script&gt;

------------------ 原始邮件 ------------------
发件人: "langgenius/dify-docs" @.>;
发送时间: 2025年8月20日(星期三) 下午2:46
@.
>;
@.@.>;
主题: Re: [langgenius/dify-docs] [DOCS]: If I want to add user_id in the first embedding method, iframe, how can I implement it? Currently, it can only be added through script (Issue #422)

dosubot[bot] left a comment (langgenius/dify-docs#422)

Hi @lilibo217! I'm Dosu and I’m helping the dify-docs team.

You can pass user_id in the iframe embedding method by appending it as a URL parameter, but it must be GZIP-compressed, Base64-encoded, and then URI-encoded. For example, to pass user_id with value apple, compress and encode it, then use a URL like:

@lilibo217 commented on GitHub (Aug 20, 2025): Thank you very much for your reply. I have tried my way as you said. Here is my code. Perhaps my expression was not clear enough. I wanted to add user_id in the first embedding method iframe, and the effect is similar to the systemVariables: {user_i: '******'} embedded in the second bubble button. Passing different user_ids can recognize different users' historical conversations, but I found that changing this doesn't work. I don't know if my method was written incorrectly or if there is a problem with passing parameters. I sincerely request a reply. Thank you again。 ```html <script setup&gt; import { ref, onMounted, onBeforeUnmount } from 'vue' import pako from 'pako' const userId = '2effb417-3d43-49ba-8b36-e3da855313aa' const iframeSrc = ref('') const chatIframeRef = ref(null) const maskVisible = ref(false) function processData(data) { &nbsp; &nbsp; const uint8Array = new TextEncoder().encode(data) &nbsp; &nbsp; const gzipped = pako.gzip(uint8Array, { level: 6 }) &nbsp; &nbsp; const base64Str = btoa(String.fromCharCode(...gzipped)) &nbsp; &nbsp; return encodeURIComponent(base64Str) } const updateRootFontSize = () =&gt; { &nbsp; &nbsp; const { documentElement } = document &nbsp; &nbsp; const dpr = 3 &nbsp; &nbsp; const size = 1920 &nbsp; &nbsp; const offsetWidth = documentElement.offsetWidth &nbsp; &nbsp; const w = offsetWidth &gt;= 750 ? offsetWidth : offsetWidth * dpr &nbsp; &nbsp; documentElement.style.fontSize = `${(w / size) * 10}px` } onMounted(() =&gt; { &nbsp; &nbsp; iframeSrc.value = `http://39.105.43.53:8089/chat/c5URJGdPrOTUl1XL?user_id=` + processData(userId) &nbsp; &nbsp; console.log(iframeSrc.value) &nbsp; &nbsp; updateRootFontSize() &nbsp; &nbsp; const ev = 'orientationchange' in window ? 'orientationchange' : 'resize' &nbsp; &nbsp; window.addEventListener(ev, updateRootFontSize) }) onBeforeUnmount(() =&gt; { &nbsp; &nbsp; const ev = 'orientationchange' in window ? 'orientationchange' : 'resize' &nbsp; &nbsp; window.removeEventListener(ev, updateRootFontSize) }) </script&gt; ``` ------------------&nbsp;原始邮件&nbsp;------------------ 发件人: "langgenius/dify-docs" ***@***.***&gt;; 发送时间:&nbsp;2025年8月20日(星期三) 下午2:46 ***@***.***&gt;; ***@***.******@***.***&gt;; 主题:&nbsp;Re: [langgenius/dify-docs] [DOCS]: If I want to add user_id in the first embedding method, iframe, how can I implement it? Currently, it can only be added through script (Issue #422) dosubot[bot] left a comment (langgenius/dify-docs#422) Hi @lilibo217! I'm Dosu and I’m helping the dify-docs team. You can pass user_id in the iframe embedding method by appending it as a URL parameter, but it must be GZIP-compressed, Base64-encoded, and then URI-encoded. For example, to pass user_id with value apple, compress and encode it, then use a URL like: <iframe src="http://localhost/chatbot/{token}?user_id=H4sIAAAAAAAAA0ssKMhJBQBQ0C6pBQAAAA%3D%3D" ... &gt;</iframe&gt; Replace the value after user_id= with your own encoded string. The official docs describe this process for all input parameters, including user_id. Script embedding allows you to set user_id directly in the config, but for iframe embedding, you must use the URL parameter method as described above&nbsp;(docs reference). If you experienced issues with user_id in iframe embedding, make sure you are using Dify version 1.7.2 or later, as earlier versions had known bugs with this feature&nbsp;(issue reference). To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other&nbsp;&nbsp;&nbsp; — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: ***@***.***&gt;
Author
Owner

@dosubot[bot] commented on GitHub (Aug 20, 2025):

The main issue is the parameter name: for Dify iframe embedding to recognize user_id and map historical conversations correctly, you must pass it as sys.user_id (not just user_id) in the URL, and it must be GZIP-compressed, Base64-encoded, and URI-encoded see code reference see docs.

Here's how to fix your code:

function processData(data) {
  const uint8Array = new TextEncoder().encode(data)
  const gzipped = pako.gzip(uint8Array, { level: 6 })
  const base64Str = btoa(String.fromCharCode(...gzipped))
  return encodeURIComponent(base64Str)
}

onMounted(() => {
  iframeSrc.value = `http://39.105.43.53:8089/chat/c5URJGdPrOTUl1XL?sys.user_id=` + processData(userId)
  console.log(iframeSrc.value)
  // ...rest of your code
})

This will allow Dify to distinguish users and load their respective conversation histories via iframe embedding see implementation details.

Make sure you're running Dify v1.7.2 or later, as earlier versions had bugs with user_id in iframe embedding see bug fix.

If it still doesn't work, check for browser console errors, verify your encoding, and clear browser cache/local storage. Known limitations: session resets may clear user mapping, and switching users rapidly can cause persistence issues (being actively improved).

Let me know if you need more troubleshooting!

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Join Discord Share on X

@dosubot[bot] commented on GitHub (Aug 20, 2025): <!-- Answer --> The main issue is the parameter name: for Dify iframe embedding to recognize user_id and map historical conversations correctly, you must pass it as `sys.user_id` (not just `user_id`) in the URL, and it must be GZIP-compressed, Base64-encoded, and URI-encoded [see code reference](https://github.com/langgenius/dify/blob/d12255025c7b42ac99e392cfff6b254a37418f4f/web/app/components/base/chat/utils.ts) [see docs](https://github.com/langgenius/dify/issues/23302). Here's how to fix your code: ```js function processData(data) { const uint8Array = new TextEncoder().encode(data) const gzipped = pako.gzip(uint8Array, { level: 6 }) const base64Str = btoa(String.fromCharCode(...gzipped)) return encodeURIComponent(base64Str) } onMounted(() => { iframeSrc.value = `http://39.105.43.53:8089/chat/c5URJGdPrOTUl1XL?sys.user_id=` + processData(userId) console.log(iframeSrc.value) // ...rest of your code }) ``` This will allow Dify to distinguish users and load their respective conversation histories via iframe embedding [see implementation details](https://github.com/langgenius/dify/issues/23302). Make sure you're running Dify v1.7.2 or later, as earlier versions had bugs with user_id in iframe embedding [see bug fix](https://github.com/langgenius/dify/issues/23682). If it still doesn't work, check for browser console errors, verify your encoding, and clear browser cache/local storage. Known limitations: session resets may clear user mapping, and switching users rapidly can cause persistence issues (being actively improved). Let me know if you need more troubleshooting! <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/7baa9364-e049-470e-9269-c0cef287f751?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/7baa9364-e049-470e-9269-c0cef287f751?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/7baa9364-e049-470e-9269-c0cef287f751?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/7baa9364-e049-470e-9269-c0cef287f751?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/7baa9364-e049-470e-9269-c0cef287f751?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/7baa9364-e049-470e-9269-c0cef287f751?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/7baa9364-e049-470e-9269-c0cef287f751?feedback_type=other)</sup>&nbsp;&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/langgenius/dify-docs/issues/422)
Author
Owner

@killerddd3 commented on GitHub (Jan 4, 2026):

great

@killerddd3 commented on GitHub (Jan 4, 2026): great
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify-docs#231