# Taboola Pixel 自定义代码接入指引（ 主题 1.0 ～2.1 ）

**URL:** <https://community.shoplineapp.cn/t/topic/31>\
**Category:** 解决方案\
**Tags:** taboola, pixel\
**Created:** [2026 年1 月 19 日 07:50 UTC](https://community.shoplineapp.cn/t/topic/31 "2026-01-19T07:50:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

作者： ![子寒](https://community.shoplineapp.cn/user_avatar/community.shoplineapp.cn/%E5%AD%90%E5%AF%92/32/41_2.png) [@子寒](https://community.shoplineapp.cn/u/%E5%AD%90%E5%AF%92)\
发布日期： [2026 年1 月 19 日 07:50 UTC](https://community.shoplineapp.cn/t/topic/31/1 "2026-01-19T07:50:28Z")

</div>

一、官方文档

> **[Add the base pixel manually](https://developers.taboola.com/pixel/docs/add-the-base-pixel-manually)**
>
> Add the base pixel manually to a standard web page

#### 二、兼容版本

Theme OS 1.0, 2.0, 2.1

#### 三、操作流程

###### 1. 安装自定义代码应用, 点击添加代码

 ![image](https://community.shoplineapp.cn/uploads/default/original/1X/2c9da7c90eca35458e3ef7c7f141ac72827e6326.jpeg)

###### 2. 触发页面全选,插入位置顶部

 ![image](https://community.shoplineapp.cn/uploads/default/original/1X/3c7987469923992b42cde6d7bc46082ef7f17384.png)

###### 3. 将以下代码复制入代码内容, 请将所有`YOUR_ACCOUNT_ID`替换为您的 Account ID

 ![image](https://community.shoplineapp.cn/uploads/default/original/1X/0a5bade17688ec8ccb610bab2c4867dbd8df8441.png)

当前支持事件：

1. page\_view

2. add\_to\_cart

3. view\_content

4. start\_checkout

5. make\_purchase

主题 2.1

```auto
<!-- Taboola Pixel Code -->
<script type="text/javascript">
  
  window._tfa = window._tfa || []; window._tfa.push({notify: 'event', name:
  'page_view', id: YOUR_ACCOUNT_ID}); !function (t, f, a, x) { if
  (!document.getElementById(x)) { t.async = 1;t.src =
  a;t.id=x;f.parentNode.insertBefore(t, f); }
  }(document.createElement('script'),
  document.getElementsByTagName('script')[0],
  '//cdn.taboola.com/libtrc/unip/YOUR_ACCOUNT_ID/tfa.js', 'tb_tfa_script');

  // add_to_cart
  (function() {
      const pushTaboolaEvent = () => {
          _tfa.push({notify: 'event', name: 'add_to_cart', id: YOUR_ACCOUNT_ID});
      };
      const originalFetch = window.fetch;
      window.fetch = function(...args) {
          return new Promise((resolve, reject) => {
              originalFetch.apply(this, args)
                  .then(response => {
                      const clone = response.clone();
                      if ((args[0] && args[0].url && args[0].url.includes("/cart/add")) || (args[0] && args[0] === "/cart/add")) {
                          clone.json().then(data => {
                              pushTaboolaEvent();
                          });
                      }
                      
                      resolve(response);
                  })
                  .catch(error => {
                      reject(error);
                  });
          });
      };
      const originalSend = XMLHttpRequest.prototype.send;
      XMLHttpRequest.prototype.send = function(body) {
          const method = this._method;
          const url = this._url;
          if (method === 'POST' && url === '/leproxy/api/carts/cart/batch/add') {
              console.log('axon add_to_cart xhr');
              try {
                  const bodyData = JSON.parse(body);
                  pushTaboolaEvent();
              } catch (error) {
                  console.error("Error processing add_to_cart batch request", error);
              }
          }

          return originalSend.apply(this, arguments);
      };
  })();

  // view_content
  {{#if @root.product}}
    _tfa.push({notify: 'event', name: 'view_content', id: YOUR_ACCOUNT_ID});
  {{/if}}

  // start_checkout
  {{#if @root.checkout}}
    _tfa.push({notify: 'event', name: 'start_checkout', id: YOUR_ACCOUNT_ID});
  {{/if}}

  // make_purchase
  {{#if @root.thankyou}}
    _tfa.push({notify: 'event', name: 'make_purchase', id: YOUR_ACCOUNT_ID});
  {{/if}}
</script>
<!-- End of Taboola Pixel Code -->

```

主题 1.0&2.0

```auto
<!-- Taboola Pixel Code -->
<script type="text/javascript">
  
  window._tfa = window._tfa || []; window._tfa.push({notify: 'event', name:
  'page_view', id: YOUR_ACCOUNT_ID}); !function (t, f, a, x) { if
  (!document.getElementById(x)) { t.async = 1;t.src =
  a;t.id=x;f.parentNode.insertBefore(t, f); }
  }(document.createElement('script'),
  document.getElementsByTagName('script')[0],
  '//cdn.taboola.com/libtrc/unip/YOUR_ACCOUNT_ID/tfa.js', 'tb_tfa_script');

  // add_to_cart
  window.Shopline.event?.on('DataReport::AddToCart', function (payload) {
    _tfa.push({notify: 'event', name: 'add_to_cart', id: YOUR_ACCOUNT_ID});
  })

  // view_content
  {{#if @root.product}}
    _tfa.push({notify: 'event', name: 'view_content', id: YOUR_ACCOUNT_ID});
  {{/if}}

  // start_checkout
  {{#if @root.checkout}}
    _tfa.push({notify: 'event', name: 'start_checkout', id: YOUR_ACCOUNT_ID});
  {{/if}}

  // make_purchase
  {{#if @root.thankyou}}
    _tfa.push({notify: 'event', name: 'make_purchase', id: YOUR_ACCOUNT_ID});
  {{/if}}
</script>
<!-- End of Taboola Pixel Code -->

```
