> For the complete documentation index, see [llms.txt](https://help.impact.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.impact.com/brand/zh/what-would-you-like-to-learn-about/platform-features/reach-out-to-partners/generate-leads/create-a-custom-widget.md). Agents can also search and read this documentation through its [MCP server](https://help.impact.com/~gitbook/mcp).

# 创建自定义组件

开发动态工具，助力合作伙伴推广您的品牌。自定义小组件可通过 iframe 将托管在外部的工具或页面直接嵌入 impact.com 界面。使用本指南创建并配置自定义内容小组件，为合作伙伴提供个性化资源和一致的品牌体验。

{% stepper %}
{% step %}

## 打开自定义小组件创建器

1. 在左侧导航菜单中，选择 ![](https://1186853034-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwMLlMoFBtKJa8ptd3zaw%2Fuploads%2Fgit-blob-230534471fef5f40808e921e41ee44e4a06ded03%2Fe6cb9548999afdc1ed3ce4942e4cb5b45b5cecbd323267aac2a7cd1915fccc09.svg?alt=media) **\[互动]** → **内容** → [**小组件**](https://app.impact.com/secure/advertiser/engage/ads/list-widget-tool-flow.ihtml)**.**
2. 在右上角，选择 **创建小组件** → **自定义**.
   {% endstep %}

{% step %}

## 输入小组件详细信息

1. 输入自定义小组件的 **名称** 。
2. 可选：输入自定义小组件的 **说明** 。
3. 可选：输入自定义小组件的 **标签** 。
4. 如有需要， ![](https://1186853034-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwMLlMoFBtKJa8ptd3zaw%2Fuploads%2FiZjM1xY8o3v1iR3Zaysd%2FToggle.svg?alt=media\&token=b1550d48-bba9-4e81-8604-bc12370c5caa) **\[开启] 限制合作伙伴访问权限** ，指定可访问该小组件的合作伙伴和群组。
   * **合作伙伴：** 输入可访问自定义小组件的合作伙伴名称。
   * **群组：** 输入可访问自定义小组件的群组名称。
     {% endstep %}

{% step %}

## 配置小组件

1. 从显示选项中选择小组件的行为：
   * **在新标签页中打开：** 在单独的标签页中打开托管网址。
   * **嵌入 impact.com：** 直接在平台界面中显示小组件。
2. 可选：在 **预览图片** 部分中，选择 **选择文件** 上传缩略图。请确保文件为 GIF、JPG 或 PNG 格式，且大小不超过 512 KB。
3. 在 **小组件 URL** 字段中，输入托管小组件的网址。
4. 在 ![](https://1186853034-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwMLlMoFBtKJa8ptd3zaw%2Fuploads%2Fgit-blob-c2cb550b55c51ea1eeff0acbd6f437a03b621a2c%2F60d033ae8a04c14498d5229c3c0160ac05feea7f605dbd770741793c900469f0.svg?alt=media)**\[下拉菜单]**&#x4E2D;，选择与您网站安全设置相匹配的协议（例如 https\://）。
5. 可选：选择 ![](https://1186853034-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwMLlMoFBtKJa8ptd3zaw%2Fuploads%2Fgit-blob-6282f271b7521383385339243690b303086736d9%2F3b5a585dd2895bdf1c30d1236c72ba590dddd18717863b27074c8d313d05ae20.svg?alt=media) **\[添加] 插入动态字段** 以展开令牌列表。
6. 找到要使用的令牌，然后选择 **插入**。平台会自动将令牌（例如 {irpid}）附加到您的 **Widget URL**。请参阅下方的 [动态字段令牌](#dynamic-field-tokens) 部分，了解每个令牌的说明。
   {% endstep %}

{% step %}

## 更新高级设置

在 **语言** ![](https://1186853034-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwMLlMoFBtKJa8ptd3zaw%2Fuploads%2Fgit-blob-c2cb550b55c51ea1eeff0acbd6f437a03b621a2c%2F60d033ae8a04c14498d5229c3c0160ac05feea7f605dbd770741793c900469f0.svg?alt=media)**\[下拉菜单]**&#x4E2D;，选择此组件要显示的语言。
{% endstep %}

{% step %}

## 完成自定义组件设置

选择 **创建** 以保存组件。合作伙伴可以在 *内容组件*.
{% endstep %}
{% endstepper %}

<details>

<summary>动态字段令牌</summary>

| 令牌                             | 说明                  |
| ------------------------------ | ------------------- |
| `{click_url_encoded}`          | 经过编码的点击 URL         |
| `{click_url}`                  | 未经过编码的点击 URL        |
| `{irimpurl}`                   | 我们的展示 URL           |
| `{irpid}`                      | 合作伙伴 ID             |
| `{subid1}`                     | 合作伙伴子 ID 1          |
| `{subid2}`                     | 合作伙伴子 ID 2          |
| `{subid3}`                     | 合作伙伴子 ID 3          |
| `{sharedId}`                   | 共享 ID               |
| `{iradid}`                     | 广告 ID               |
| `{ircid}`                      | 计划 ID               |
| `{click_url_encoded_deeplink}` | 附加了深层链接参数的编码点击 URL。 |

</details>

## 示例

{% hint style="info" %}
**关于这些示例：** 自定义组件由您构建并托管——impact.com 只会嵌入托管页面，并向其中注入实时合作伙伴数据。复制以下参考实现，将其托管在您自己的域名上并进行调整。合作伙伴无需编辑任何代码，只需从 *内容组件*.
{% endhint %}

### 动态字段令牌如何传递到您的组件

当您将动态字段令牌添加到 **Widget URL**时，impact.com 会在加载您的页面之前，将其替换为每位合作伙伴的实际值。您的页面会从查询字符串中读取这些值，并使用它们来构建可追踪链接。

例如，如果您将 **Widget URL** 设为 `https://widgets.yourbrand.com/search?partner={irpid}&clickurl={click_url_encoded}`，对于 ID 为 `123456`:

{% code overflow="wrap" %}

```
https://widgets.yourbrand.com/search?partner=123456&clickurl=https%3A%2F%2Facme.sjv.io%2Fc%2F123456%2F789012%2F3456
```

{% endcode %}

{% hint style="warning" %}
请将点击 URL 作为 `{click_url_encoded}`传递，而不要使用 `{click_url}` ——原始点击 URL 自身包含 `?` 和 `&` 字符会破坏查询字符串。请在页面中使用前先对其进行解码。
{% endhint %}

### 示例 1：搜索小组件

让合作伙伴无需离开 impact.com，即可搜索您的商品目录，并为任意商品复制可跟踪链接。搜索页面由您托管；impact.com 会传入合作伙伴 ID 和点击 URL，因此每个结果链接都会归因于该合作伙伴。

1. 请将搜索页面托管在您控制的域名上，并使用 HTTPS（例如， `https://widgets.yourbrand.com/search`）。将示例 `CATALOG` 数组替换为对您自己的商品目录或搜索 API 的调用。
2. 按照上述五个步骤创建自定义小组件。在 **配置小组件**中，将 **小组件 URL** 设置为您的页面，并包含 `{irpid}` 和 `{click_url_encoded}` 令牌（如下所示）。
3. 使用 **在新标签页中打开**进行测试，以测试合作伙伴身份执行搜索，并确认结果链接会跳转到您的网站且记录点击。然后将小组件切换为 **嵌入 impact.com**.

**小组件 URL**

{% code overflow="wrap" %}

```
https://widgets.yourbrand.com/search?partner={irpid}&clickurl={click_url_encoded}
```

{% endcode %}

<details>

<summary>search-widget.html</summary>

```html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <title>商品搜索</title>
  <style>
    body { font-family: Arial, sans-serif; margin: 0; padding: 16px; }
    .search-bar { display: flex; gap: 8px; margin-bottom: 16px; }
    .search-bar input { flex: 1; padding: 10px; font-size: 16px; }
    .search-bar button { padding: 10px 16px; font-size: 16px; cursor: pointer; }
    .result { padding: 12px; border: 1px solid #ddd; border-radius: 6px; margin-bottom: 8px; }
    .result a { text-decoration: none; font-weight: bold; }
    .copy { margin-left: 8px; font-size: 13px; color: #2b6cb0; cursor: pointer; }
  </style>
</head>
<body>
  <div class="search-bar">
    <input id="q" type="text" placeholder="搜索商品..." />
    <button id="go">搜索</button>
  </div>
  <div id="results"></div>

  <script>
    // 1. 读取 impact.com 注入到小组件 URL 中的值。
    var params    = new URLSearchParams(window.location.search);
    var partnerId = params.get('partner') || '';
    var clickUrl  = decodeURIComponent(params.get('clickurl') || '');

    // 2. 将此示例数组替换为对您自己的商品目录 / 搜索 API 的调用。
    var CATALOG = [
      { name: 'Trail Runner Shoe',   url: 'https://www.yourbrand.com/products/trail-runner' },
      { name: 'Waterproof Jacket',   url: 'https://www.yourbrand.com/products/waterproof-jacket' },
      { name: 'Merino Hiking Socks', url: 'https://www.yourbrand.com/products/merino-socks' }
    ];

    // 3. 构建可跟踪的深层链接：合作伙伴的点击 URL + 目标页面。
    //    发布前请确认您项目的确切深层链接格式（请参阅“发布前须知”）。
    function buildTrackingLink(destinationUrl) {
      if (!clickUrl) return destinationUrl;            // 回退：缺少令牌时不进行跟踪
      return clickUrl + encodeURIComponent(destinationUrl);
    }

    function search() {
      var term = document.getElementById('q').value.toLowerCase();
      var matches = CATALOG.filter(function (p) {
        return p.name.toLowerCase().indexOf(term) !== -1;
      });
      var container = document.getElementById('results');
      container.innerHTML = matches.length ? '' : '<p>未找到商品。</p>';
      matches.forEach(function (p) {
        var link = buildTrackingLink(p.url);
        var row = document.createElement('div');
        row.className = 'result';
        row.innerHTML =
          ' <a href="' + link + '" target="_blank" rel="noopener">' + p.name + '</a>' +
          ' <span class="copy" data-link="' + link + '">复制链接</span>';
        container.appendChild(row);
      });
    }

    document.getElementById('go').addEventListener('click', search);
    document.getElementById('q').addEventListener('keyup', function (e) {
      if (e.key === 'Enter') search();
    });
    document.addEventListener('click', function (e) {
      if (e.target.classList.contains('copy')) {
        navigator.clipboard.writeText(e.target.getAttribute('data-link'));
      }
    });
  </script>
</body>
</html>
```

</details>

### 示例 2：动态富媒体广告（悬浮聊天组件）

动态富媒体广告是指您托管并嵌入为组件的任何交互式 HTML 资源。在此示例中，您将创建一个悬浮聊天气泡，点击后会展开促销消息和行动号召。访客选择按钮后，系统会通过合作伙伴的点击 URL 将其重定向，因此点击会得到跟踪和归因。

1. 将页面托管在您拥有的域名上，并使用 HTTPS（例如： `https://widgets.yourbrand.com/chat`）。自定义文案、颜色和行动号召，使其符合您的营销活动。
2. 按照上述五个步骤创建自定义组件，并将 **组件 URL** 设置为包含 `{click_url_encoded}` 令牌（如下所示）。
3. 使用 **在新标签页中打开** 作为测试合作伙伴进行测试，确认行动号召会打开您的网站并记录点击，然后将组件切换为 **在 impact.com 中嵌入**.

**小组件 URL**

{% code overflow="wrap" %}

```
https://widgets.yourbrand.com/chat?clickurl={click_url_encoded}
```

{% endcode %}

若要将访客引导至特定页面，而非默认落地页，请使用 `{click_url_encoded_deeplink}` 令牌替代 `{click_url_encoded}`，或者像示例 1 中那样，在自己的代码中附加目标网址。

<details>

<summary>chat-widget.html</summary>

```html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <title>Assistant</title>
  <style>
    html, body { margin: 0; height: 100%; background: transparent; font-family: Arial, sans-serif; }
    #bubble {
      position: fixed; bottom: 20px; right: 20px;
      width: 60px; height: 60px; border-radius: 50%;
      background: #2b6cb0; color: #fff; font-size: 26px;
      display: flex; align-items: center; justify-content: center;
      cursor: pointer; box-shadow: 0 4px 12px rgba(0,0,0,.25);
    }
    #panel {
      position: fixed; bottom: 90px; right: 20px; width: 260px;
      background: #fff; border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.2);
      padding: 16px; display: none;
    }
    #panel.open { display: block; }
    #panel p { margin: 0 0 12px; font-size: 14px; color: #333; }
    #cta {
      display: block; width: 100%; padding: 10px; border: none; border-radius: 6px;
      background: #2b6cb0; color: #fff; font-size: 15px; cursor: pointer;
    }
  </style>
</head>
<body>
  <div id="bubble">&#128172;</div>
  <div id="panel">
    <p>嗨！想了解我们的最新优惠吗？点击下方按钮，即可购物省钱。</p>
    <button id="cta">立即购物</button>
  </div>

  <script>
    // impact.com 会将合作伙伴的点击 URL 注入此页面。
    var params   = new URLSearchParams(window.location.search);
    var clickUrl = decodeURIComponent(params.get('clickurl') || '');

    var bubble = document.getElementById('bubble');
    var panel  = document.getElementById('panel');
    bubble.addEventListener('click', function () {
      panel.classList.toggle('open');
    });

    document.getElementById('cta').addEventListener('click', function () {
      if (!clickUrl) return;
      // 在新标签页中打开，以便记录点击并将其归因于合作伙伴。
      window.open(clickUrl, '_blank', 'noopener');
    });
  </script>
</body>
</html>
```

</details>

## 发布前须知

* 请通过 HTTPS 自行托管此页面。impact.com 会通过 iframe 嵌入您的页面，或在新标签页中打开它；不会托管您的代码。在嵌入模式下，您的页面会在 iframe 中运行，因此请使用 `target="_blank"` 或 `window.open(...)` 打开目标链接，而不要跳转父窗口。
* 对点击 URL 进行编码。将其作为 `{click_url_encoded}` 传入，并在页面中解码，以免其中的 `?` 和 `&` 字符破坏查询字符串。
* 请与您的 impact.com 集成工程师确认深层链接格式，并确保目标网址属于获准用于深层链接的域名。

## 更多资源

* [创建跟踪链接并与合作伙伴分享](https://help.impact.com/brand/zh/what-would-you-like-to-learn-about/platform-features/reach-out-to-partners/generate-leads/create-and-share-tracking-links-with-partners.md) — 了解如何创建跟踪链接并与合作伙伴分享。
* [跟踪链接参数说明](https://help.impact.com/brand/zh/what-would-you-like-to-learn-about/platform-features/tracking/tracking-explained/tracking-link-parameters-explained.md) — 了解跟踪链接的结构以及可添加的参数，例如子 ID、共享 ID 和深层链接。
* [设置深度链接的允许域名](https://help.impact.com/brand/zh/what-would-you-like-to-learn-about/account-administration/program-settings/tracking-settings/set-up-permitted-domains-for-deep-linking.md) — 授权合作伙伴可以在你的网站上创建深度链接的目标域名。
* [资产类型简介](https://help.impact.com/brand/zh/what-would-you-like-to-learn-about/platform-features/ads/introduction-to-asset-types.md) — 可向合作伙伴提供的资产类型，包括自定义小组件的适用场景。
* [从 Rakuten Advertising 迁移到 impact.com：关键步骤](https://help.impact.com/brand/zh/what-would-you-like-to-learn-about/getting-started/rakuten-advertising-to-impact.com-key-transition-steps.md) — 将项目从 Rakuten Advertising 迁移到 impact.com 时会发生哪些变化。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://help.impact.com/brand/zh/what-would-you-like-to-learn-about/platform-features/reach-out-to-partners/generate-leads/create-a-custom-widget.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
