> ## 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.

# setKv

> 设置用于定向投放的键值对 Sets a key-value pair for optional targeting

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;
})();

<Warning>
  定向参数中不得传入任何可识别用户身份的数据（包括姓名、地址或用户ID）。 You
  may not pass any user-identifiable data (including names, addresses, or user
  IDs) in targeting.
</Warning>

<ParamField path="key" type="string" required>
  定向键 The targeting key
</ParamField>

<ParamField path="value" type="string" required>
  定向值 The targeting value
</ParamField>

<CodeGroup>
  ```js 设置单个键值对 Set a key-value pair theme={null}
  reviq.setKv("key", "value");
  reviq.setKv("dog", "woof");
  reviq.setKv("cat", "meow");
  ```

  ```js 批量设置键值对 Set multiple key-value pairs theme={null}
  reviq.setKvs({
    "key": "value",
    "dog": "woof",
    "cat": "meow"
  });
  ```
</CodeGroup>

<CodeGroup>
  ```js 验证键值对 Verify key-value pairs theme={null}
  googletag.pubads().getTargeting("key"); //= ["value"]
  googletag.pubads().getTargeting("foo"); //= ["bar"]
  googletag.pubads().getTargeting("cat"); //= ["meow"]
  ```
</CodeGroup>

# setKvs

`setKvs`是一个便捷方法，用于一次性设置多个键值对。它接受一个对象作为参数，其中的键为定向键，值为定向值。
The `setKvs` method is a convenience method for setting multiple key-value pairs
at once. It accepts an object where the keys are the targeting keys and the
values are the targeting values.

<ParamField path="kvs" type="object" required>
  包含多个键值对的对象 An object of key-value pairs
</ParamField>
