> ## Documentation Index
> Fetch the complete documentation index at: https://docs.rev.iq/llms.txt
> Use this file to discover all available pages before exploring further.

# setUid

> 提供用于定向投放的用户 ID（uid），支持多参数传入。 Provide a user ID (uid) for targeting. Variadic.

export const domain = (() => {
  const placeholder = "your-domain.com";
  if (typeof window !== "undefined" && !globalThis.__revDomainSetup) {
    globalThis.__revDomainSetup = true;
    function textNodes(node) {
      if (node.nodeType === Node.TEXT_NODE) return [node];
      const nodes = [];
      for (const child of node.childNodes) {
        nodes.push(...textNodes(child));
      }
      return nodes;
    }
    function anchorNodes(node) {
      if (node.nodeType === Node.ELEMENT_NODE && node.tagName === "A") return [node];
      const nodes = [];
      for (const child of node.childNodes) {
        nodes.push(...anchorNodes(child));
      }
      return nodes;
    }
    const domain = globalThis.__revDomain || new URLSearchParams(globalThis.location.search).get('domain') || "yourdomain.com";
    globalThis.__revDomain = domain;
    if (globalThis.__revDomainObs) return;
    const obs = globalThis.__revDomainObs || new MutationObserver(mutations => {
      for (const {addedNodes, removedNodes, target} of mutations) {
        for (const node of [...addedNodes, target]) {
          if (node instanceof HTMLScriptElement) continue;
          if (node instanceof HTMLStyleElement) continue;
          for (const textNode of textNodes(node)) {
            if (textNode.nodeValue && textNode.nodeValue.includes(placeholder)) {
              setTimeout(() => {
                textNode.nodeValue = textNode.nodeValue.replace(placeholder, domain);
              }, 100);
            }
          }
          for (const anchorNode of anchorNodes(node)) {
            if (anchorNode.href && anchorNode.href.includes(placeholder)) {
              setTimeout(() => {
                anchorNode.href = anchorNode.href.replace(placeholder, domain);
              }, 100);
            }
          }
        }
      }
    });
    obs.observe(document.body, {
      childList: true,
      subtree: true
    });
  }
  return placeholder;
})();

提供UID可显著提升广告效果，因此虽为可选项，但强烈建议传入。
Providing a UID significantly improves ad performance. As such, it is
optional, but highly recommended.

我们严格遵守所有隐私法规，不存储任何可识别用户身份的数据。UID传入RevIQ后会经过标准化处理并进行哈希加密，原始值不会被保留。
We comply with all privacy regulations and do not store any user-identifiable
data. Once passed to RevIQ, the UID is normalized and then hashed; we never
store the original value.

<Check>
  如果用户已选择退出追踪，UID将不会被存储或传输。因此，无论用户的追踪偏好如何，调用此函数均是安全的。
  If the user has opted out of tracking, the UID will not be stored or
  transmitted. Thus it is safe to call this function regardless of the user's
  tracking preferences.
</Check>

<ParamField path="value" type="Uid" required>
  ```ts theme={null}
  type Uid = {
    u?: string; // 用户名 username
    e?: string; // 邮箱 email
    p?: string; // 手机号 phone
  };
  ```
</ParamField>

<CodeGroup>
  ```js 使用邮箱 With email theme={null}
  const user = { email: "hachi@rev.iq" };
  reviq.setUid({ e: user.email });
  ```

  ```js 使用手机号 With phone theme={null}
  // 如有可能，请包含国家区号 include country code if possible
  const user = { phone: "+1 555-555-5555" }; 
  reviq.setUid({ p: user.phone }); 
  ```

  ```js 使用用户名 With username theme={null}
  const user = { username: "hachi" };
  reviq.setUid({ u: user.username });
  ```
</CodeGroup>
