---
title: 'Criteo OneTag高级设置'
description: '为了启用一些高级设置，您可以对Criteo OneTag实现进行一些修改。 这涉及跨设备定向、多种货币/国家/地区的广告商以及其他主题。 请阅读以下目录，了解如何完成最适合您的设置。'
language: zh
guide: M2TiX6m90K
updated: 2025-11-12T13:21:16Z
canonical: https://help.criteo.com/kb/guide/zh/criteo-onetag-M2TiX6m90K/Steps/886908
alternates:
  de: https://help.criteo.com/kb/guide/de/erweiterte-einstellungen-von-criteo-onetag-M2TiX6m90K.md
  en: https://help.criteo.com/kb/guide/en/criteo-onetag-advanced-settings-M2TiX6m90K.md
  es: https://help.criteo.com/kb/guide/es/configuracion-avanzada-de-criteo-onetag-M2TiX6m90K.md
  fr: https://help.criteo.com/kb/guide/fr/parametres-avances-de-criteo-onetag-M2TiX6m90K.md
  it: https://help.criteo.com/kb/guide/it/impostazioni-avanzate-di-criteo-onetag-M2TiX6m90K.md
  ja: https://help.criteo.com/kb/guide/ja/criteo-tag-M2TiX6m90K.md
  ko: https://help.criteo.com/kb/guide/ko/criteo-onetag-M2TiX6m90K.md
  pt: https://help.criteo.com/kb/guide/pt/configuracoes-avancadas-da-criteo-onetag-M2TiX6m90K.md
---

> Index of this knowledge base: https://help.criteo.com/llms.txt
>
> Interactive version: https://help.criteo.com/kb/guide/zh/criteo-onetag-M2TiX6m90K/Steps/886908

# Criteo OneTag高级设置

<a id="step-886908"></a>

## Criteo OneTag高级设置

为了启用一些高级设置，您可以对Criteo OneTag实现进行一些修改。  
  
这涉及跨设备定向、多种货币/国家/地区的广告商以及其他主题。 请阅读以下目录，了解如何完成最适合您的设置。

- If "通过跨设备事件传递加密电子邮箱": [通过跨设备事件传递加密电子邮箱](#step-887075)
- If "使用OneTag传递电话号码": [使用OneTag传递电话号码](#step-4106561)
- If "不同网站类型的事件设置": [不同网站类型的事件设置](#step-887074)
- If "多个国家/地区的事件设置": [多个国家/地区的事件设置](#step-887076)
- If "多种货币的事件设置": [多种货币的事件设置](#step-887079)
- If "使用相同购物篮/购物车的多个网站的事件设置": [使用相同购物篮/购物车的多个网站的事件设置](#step-887071)
- If "多种付款方式的事件设置": [多种付款方式的事件设置](#step-887073)
- If "旅游广告商的事件设置": [旅游广告商的事件设置](#step-887078)
- If "搜索列表页面上Criteo OneTag中的产品ID少于或多于3个": [搜索列表页面上Criteo OneTag中的产品ID少于或多于3个](#step-887077)
- If "设置netID集成": [设置netID集成](#step-887072)

<a id="step-887075"></a>

## 通过跨设备事件传递加密电子邮箱

在Criteo OneTag中实现跨设备参数对于以下方面至关重要：

-   当天触达Safari和Firefox上的可寻址受众，并为Chrome上弃用第三方cookie做好准备。
    
-   启用跨设备功能：如果潜在客户使用移动设备浏览您网站上的产品，则此参数可以稍后在其桌面设备上向该客户展示相关广告。
    
-   当您将联系人列表上传到Commerce Growth或通过API发送时，可以提高您的匹配率。
    

**运行方式**

跨设备参数是一小段代码，允许您将访客的加密电子邮箱传递到您的网站。 所有电子邮箱在存储到Criteo的服务器之前，均将使用SHA-256算法进行加密。 然后，Criteo将使用加密值匹配每台设备上的用户。  
  
为确保保护您客户的隐私，Criteo将仅在我们的服务器上存储您客户的加密电子邮箱。  
 

**是否需要更新我的网站的隐私政策？**

您需要确保您的“网站隐私政策”清楚地告知您的网站访客——可能会收集电子邮箱并与您的第三方合作伙伴分享，以优化广告活动效果，并且使用最新、最安全的SHA256加密技术对有关信息进行加密处理。

此外，您应该告知访客您尊重他们的隐私，如果他们不愿意分享有关信息，他们可以在您的网站用户cookie合规横幅 (CMP) 中选择他们首选的选项。

请查阅[Criteo隐私政策](https://help.criteo.com/kb/guide/en/the-criteo-privacy-promise-pDIW4yiawH/Steps/775742)以了解更多信息，您也可以将所提供的链接添加到您网站的“隐私政策”部分。 

> **Tip:** 如果您的法务团队对隐私有任何疑虑，他们可以联系您的Criteo业务联系人，后者会根据需要将他们与我们的法务团队对接。

**如何实现跨设备参数**

为了向您提供最大的灵活性，Criteo接受以下格式的用户电子邮箱：

-   **SHA256加密** （符合可寻址广告行业标准）。
    
-   **MD5**或**SHA256MD5加密** （Criteo的传统方法）。
    
-   **纯文本** （我们随后将对电子邮箱进行SHA256加密处理）。
    

> **Tip:** **注**：Criteo正在将电子邮箱的加密处理方法从MD5/SHA256MD5转换为SHA256。 为了最大限度地提高您的数据与我们的身份图之间的匹配率，特别是在转换期间， **请共享旧格式（MD5或SHA256MD5）以及新SHA256格式**。
>
> 如果您无法共享两者，请**优先考虑SHA256格式**。
>
> 如果您共享的是纯文本，则无需更新。

关于实现跨设备参数的每种方法的更多详细信息：

- If "SHA256和MD5（首选方法）": [SHA256和MD5（首选方法）](#step-1948825)
- If "SHA256加密": [SHA256加密](#step-1948824)
- If "纯文本": [纯文本](#step-1948817)
- If "MD5或SHA256MD5（旧方法）": [MD5或SHA256MD5（旧方法）](#step-1950390)
- If "加密函数": [加密函数](#step-1948827)
- If "常见问题": [常见问题](#step-1948826)

<a id="step-4106561"></a>

## 使用OneTag传递电话号码

电话号码和电子邮件是身份信息的最大来源之一。 为了最大限度地提高我们的身份识别能力，我们决定接受它们以及用户标识符，因为在某些地区（例如亚太地区或美国），它们非常具有代表性，并且比电子邮箱或其他标识符更容易分享。

为了提高与行业中既定标准的兼容性，我们决定通过Criteo的OneTag启用电话号码收集功能。 分享电话号码的一些好处包括：

-   HPN（加密电话号码）是**单个用户的最佳表示，并且会随着时间的推移而持续存在**：一般而言，人们有一个固定的电话号码，而他们可能有多个电子邮箱、手机ID或cookie。 
    
-   HPN**全方位提高了我们对用户的认知**：每个用户都有一个电话号码，可用于他的每台设备。 它帮助我们优化我们的出价、我们的推荐，从而提高我们为客户提供的服务。 
    
-   HPN与包括HEM以及一些备用ID在内的若干标识符**互操作** 。 我们可以：
    
    -   收集HPN <> 备用ID链接并直接在备用ID上进行出价。 
        
    -   收集HEM <> HPN 并通过HEM直接出价。
        

**运行方式**

我们通过一小段代码收集数据，让您能够将访客的电话号码传递到您的网站。 尽管可以以纯文本或加密格式收集，但所有电话号码在存储在Criteo的服务器之前，均将使用SHA-256算法进行加密处理。 然后，Criteo将使用加密值匹配每台设备上的用户。

为确保保护您客户的隐私，Criteo将仅在我们的服务器上存储您客户的加密电话号码。 为了确保足够安全，我们添加了存储在秘密库中的第二个加密值，以避免重新识别用户。

**是否需要更新我的网站的隐私政策？**

您需要确保您的“网站隐私政策”清楚地告知您的网站访客——可能会收集电话号码并与您的第三方合作伙伴分享，以优化广告活动效果，并且使用最新、最安全的SHA256加密技术对有关信息进行加密处理。

此外，您应该告知访客您尊重他们的隐私，如果他们不愿意分享有关信息，他们可以在您的网站用户cookie合规横幅 (CMP) 中选择他们首选的选项。

请查阅[Criteo隐私政策](https://help.criteo.com/kb/guide/en/the-criteo-privacy-promise-pDIW4yiawH/Steps/775742)以了解更多信息，您也可以将所提供的链接添加到您网站的“隐私政策”部分。 

如果您的法务团队对隐私有任何疑虑，他们可以联系您的Criteo业务联系人，后者会根据需要将他们与我们的法务团队对接。

实现方式

为了向您提供最大的灵活性，Criteo接受以下格式的用户电话号码：

-   **SHA256加密** （符合可寻址广告行业标准）。
    
-   **纯文本** （紧接在记录数据之前，我们会对电话号码进行SHA256加密处理）。

- If "SHA256": [SHA256](#step-4106563)
- If "纯文本": [纯文本](#step-4106562)

<a id="step-887074"></a>

## 不同网站类型的事件设置

```javascript
<script type="text/javascript" src="//dynamic.criteo.com/js/ld/ld.js?a=YOUR_PARTNER_ID" async="true"></script>

<script type="text/javascript">

window.criteo_q = window.criteo_q || [];

var deviceType = /iPad/.test(navigator.userAgent) ? "t" : /Mobile|iP(hone|od)|Android|BlackBerry|IEMobile|Silk/.test(navigator.userAgent) ? "m" : "d";

window.criteo_q.push(

    { event: "setAccount", account: YOUR UNIQUE ACCOUNT ID },

    { event: "setSiteType", type: deviceType },

    { event: "setEmail", email: "TRIMMED AND LOWERCASE USER EMAIL ADDRESS" },

    { event: "viewHome"}

);

</script>
```

动态setSiteType参数存在于嵌入您网站每个页面上的Criteo OneTag中。 如果您的网站有不同的版本以支持一系列设备，请通过“**setSiteType**”参数指明向用户显示哪个版本：

-   **d**代表桌面版
-   **m**代表移动版
-   **t**代表平板电脑版

示例：  
  
桌面版网站上的setSiteType参数：

 { event: "setSiteType", type: "d" },

  
移动版网站上的setSiteType参数： 

 { event: "setSiteType", type: "m" },

  
平板电脑版网站上的setSiteType参数：  
 

{ event: "setSiteType", type: "t" },

如果您无法动态发送此值，则可以使用以下脚本自动检测用户使用的是桌面版网站、移动版网站还是平板电脑版网站：  
 

var deviceType = /iPad/.test(navigator.userAgent) ? "t" : /Mobile|iP(hone|od)|Android|BlackBerry|IEMobile|Silk/.test(navigator.userAgent) ? "m" : "d";

然后，您需要将**deviceType**变量置入事件中。 最终，“**setSiteType**”参数将如下所示：

 { event: "setSiteType", type: deviceType },

主页事件如下所示（示例）：

<script type="text/javascript" src="//dynamic.criteo.com/js/ld/ld.js?a=YOUR\_PARTNER\_ID" async="true"></script>

<script type="text/javascript">

window.criteo\_q = window.criteo\_q || \[\];

var deviceType = /iPad/.test(navigator.userAgent) ? "t" : /Mobile|iP(hone|od)|Android|BlackBerry|IEMobile|Silk/.test(navigator.userAgent) ? "m" : "d";

window.criteo\_q.push(

    { event: "setAccount", account: YOUR UNIQUE ACCOUNT ID },

    { event: "setSiteType", type: deviceType },

    { event: "setEmail", email: "TRIMMED AND LOWERCASE USER EMAIL ADDRESS" },

    { event: "viewHome"}

);

</script>

This path ends here.

<a id="step-887076"></a>

## 多个国家/地区的事件设置

```javascript
<script type="text/javascript" src="//dynamic.criteo.com/js/ld/ld.js?a=YOUR_PARTNER_ID" async="true"></script>
<script type="text/javascript"> 
    window.criteo_q = window.criteo_q || []; var criteo_ID = #Country Account ID#; 
    var deviceType = /iPad/.test(navigator.userAgent) ? "t" : /Mobile|iP(hone|od)|Android|BlackBerry|IEMobile|Silk/.test(navigator.userAgent) ? "m" : "d"; 
    window.criteo_q.push(          
        { event: "setAccount", account: criteo_ID },          
        { event: "setSiteType", type: deviceType  },          
        { event: "setEmail", email: "TRIMMED AND LOWERCASE USER EMAIL ADDRESS" },                  
        { event: "viewHome"}  ); 
</script>
```

如果您的网站向多个国家/地区的客户销售产品，则需要动态切换每个国家/地区的Criteo**帐户ID**。 

在以下示例中，您将看到主页事件中添加了一个附加变量**criteo\_ID**。 根据用户选择的国家/地区，此变量的值需要动态更新为特定的**#Country Account ID#**。 此逻辑需要添加到您网站上Criteo OneTag的每个实例中。

Criteo OneTag上实现的特定国家/地区帐户ID的示例：

`<script type="text/javascript" src="//dynamic.criteo.com/js/ld/ld.js?a=YOUR_PARTNER_ID" async="true"></script> <script type="text/javascript"> window.criteo_q = window.criteo_q || []; var criteo_ID = #Country Account ID#; var deviceType = /iPad/.test(navigator.userAgent) ? "t" : /Mobile|iP(hone|od)|Android|BlackBerry|IEMobile|Silk/.test(navigator.userAgent) ? "m" : "d"; window.criteo_q.push(          { event: "setAccount", account: criteo_ID },          { event: "setSiteType", type: deviceType  },          { event: "setEmail", email: "TRIMMED AND LOWERCASE USER EMAIL ADDRESS" },                  { event: "viewHome"}  ); </script>   `

This path ends here.

<a id="step-887079"></a>

## 多种货币的事件设置

如果用户能够在您的网站上以不同的货币购买产品，例如，用户能够从世界各地进行预订的旅游网站，您可能需要定义所购买产品的货币。   
  
定义货币将有助于Criteo在其报告中显示正确的广告活动货币，以与您自己的报告保持一致。  
  
由于产品价格仅在购物篮和交易事件中传递，因此此功能仅应用于Criteo OneTag中的这两个事件。 如果您只以一种货币销售产品，则不应使用此功能。  
  
此功能仅接受有效的ISO货币代码（有关更多信息，请参见[https://www.iso.org/iso-4217-currency-codes.html](https://www.iso.org/iso-4217-currency-codes.html)）。

  
因此，输入必须是与货币代码相对应的有效的3字母字符串（例如，“EUR”、“USD”、“JPY”……）。

-   ISO货币代码
    -   3 字母字符串
    -   有效的货币代码（例如，“EUR”、“USD”、“BRL”……）
-   大写字母
    -   “JPY”是有效输入，而“jpy”则不是。

  
**使用方式**

填充用户在您的网站上所选货币的3字母字符串。 价格值必须与网站上显示的数值完全一致。 如果用户选择美元，而价格是100美元，则Criteo OneTag中的价格需要是100，货币需要是美元。  
  
**句法**

该参数称为**货币**，如下所示：

货币：“JPY”  
  
此为**购物篮事件**中参数的示例：

{ event: "viewBasket", currency : "JPY", item: \[

  { id: "1234", price: 10.2, quantity: 1 },

  { id: "2345", price: 11.2, quantity: 2 }

\]} 

  
在**销售事件**中：

{ event: "trackTransaction", id: "12345", currency : "JPY", item: \[

  { id: "1234", price: 10.2, quantity: 1 },

  { id: "2345", price: 11.2, quantity: 2 }

\]} 

  

**测试方式**

按F12打开浏览器调试工具。 在“网络”选项卡中搜索“criteo”，然后导航到购物篮或销售确认页面（即您实现货币功能的任何页面）。 您将在查询字符串参数中看到的内容如下所示：

This path ends here.

<a id="step-887071"></a>

## 使用相同购物篮/购物车的多个网站的事件设置

```javascript
<script type="text/javascript" src="//dynamic.criteo.com/js/ld/ld.js?a=YOUR_PARTNER_ID" async="true"></script>

 <script type="text/javascript">

 window.criteo_q = window.criteo_q || [];

var deviceType = /iPad/.test(navigator.userAgent) ? "t" : /Mobile|iP(hone|od)|Android|BlackBerry|IEMobile|Silk/.test(navigator.userAgent) ? "m" : "d";

 window.criteo_q.push(

 { event: "manualFlush"},

 { event: "setAccount", account: TEST.COM ACCOUNT ID },

 { event: "setSiteType", type: deviceType },

 { event: "setEmail", email: "TRIMMED AND LOWERCASE USER EMAIL ADDRESS" },

 { event: "viewBasket", item: [ { id: "TEST.COM PRODUCT ID", price: TEST.COM UNIT PRICE, quantity: TEST.COM PRODUCT QUANTITY }

 /* add a line for each product in the user's basket */

 ]},

 { event: "flushEvents"},

 { event: "setAccount", account: EXAMPLE.COM ACCOUNT ID },

 { event: "setSiteType", type: deviceType },

 { event: "setEmail", email: "TRIMMED AND LOWERCASE USER EMAIL ADDRESS" },

 { event: "viewBasket", item: [ { id: "EXAMPLE.COM PRODUCT ID", price: EXAMPLE.COM UNIT PRICE, quantity: EXAMPLE.COM PRODUCT QUANTITY }

 /* add a line for each product in the user's basket */

 ]},

{ event: "flushEvents"}

);

</script>
```

如果您管理多个网站，但它们共享同一个购物篮/购物车页面，则需要在Criteo OneTag中设置手动刷新事件。   
  
例如，您有两个网站，EXAMPLE.COM和TEST.COM，它们共享同一个购物车页面test.com/cart。 您需要将**manualFlush**事件添加到事件中，并将**flushEvents**添加到每个额外的购物网站。   
  
在您的购物篮页面上，在Criteo OneTag上实现的手动刷新的示例：  
 

<script type="text/javascript" src="//dynamic.criteo.com/js/ld/ld.js?a=YOUR\_PARTNER\_ID" async="true"></script>

 <script type="text/javascript">

 window.criteo\_q = window.criteo\_q || \[\];

var deviceType = /iPad/.test(navigator.userAgent) ? "t" : /Mobile|iP(hone|od)|Android|BlackBerry|IEMobile|Silk/.test(navigator.userAgent) ? "m" : "d";

 window.criteo\_q.push(

 { event: "manualFlush"},

 { event: "setAccount", account: TEST.COM ACCOUNT ID },

 { event: "setSiteType", type: deviceType },

 { event: "setEmail", email: "TRIMMED AND LOWERCASE USER EMAIL ADDRESS" },

 { event: "viewBasket", item: \[ { id: "TEST.COM PRODUCT ID", price: TEST.COM UNIT PRICE, quantity: TEST.COM PRODUCT QUANTITY }

 /\* add a line for each product in the user's basket \*/

 \]},

 { event: "flushEvents"},

 { event: "setAccount", account: EXAMPLE.COM ACCOUNT ID },

 { event: "setSiteType", type: deviceType },

 { event: "setEmail", email: "TRIMMED AND LOWERCASE USER EMAIL ADDRESS" },

 { event: "viewBasket", item: \[ { id: "EXAMPLE.COM PRODUCT ID", price: EXAMPLE.COM UNIT PRICE, quantity: EXAMPLE.COM PRODUCT QUANTITY }

 /\* add a line for each product in the user's basket \*/

 \]},

{ event: "flushEvents"}

);

</script>

This path ends here.

<a id="step-887073"></a>

## 多种付款方式的事件设置

```javascript
<!-- //Criteo Loader --> 
<script type="text/javascript" src="//dynamic.criteo.com/js/ld/ld.js?a=YOUR_PARTNER_ID" async="true">
</script>
 <!--............ --> 
 <script type="text/javascript"> 
 function load_Criteo_OneTag(){  
    window.criteo_q = window.criteo_q || [];  
    window.criteo_q.push(  
        { event: "setAccount", account: ##YOUR UNIQUE ACCOUNT ID## },  
        { event: "setSiteType", type: "m FOR MOBILE OR t FOR TABLET OR d FOR DESKTOP" },  
        { event: "setEmail", email: "TRIMMED AND LOWERCASE USER EMAIL ADDRESS" },  
        { event: "trackTransaction", id: "TRANSACTION ID",  
        item: [ { 
            id: "FIRST PRODUCT ID", 
            price: ##FIRST PRODUCT UNIT PRICE##, 
            quantity: ##FIRST PRODUCT QUANTITY## },  
            { id: "SECOND PRODUCT ID", 
            price: ##SECOND PRODUCT UNIT PRICE##, 
            quantity: ##SECOND PRODUCT QUANTITY## }  
            /* add a line for each product in the user's basket */  
        ]}); } 
</script> 
<!--............ --> 
<button type="button" onclick="load_Criteo_OneTag()">PayPal</button>
```

无论用户选择哪种付款方式，均必须在您网站的订单确认页面上安装Criteo OneTag，以便您可以跟踪所购买的产品。  

  
通过跟踪用户购买了什么产品，Criteo可以优化横幅展示，以便用户购买的产品不会再次展示给他们。 如果每种付款方式均有不同的订单确认页面，请确保Criteo OneTag在每个页面上均已实现并正常运行。

**在您的域名外发生的交易**

如果您对交易发生在您的域名之外的情况提供了任何付款方式（例如PayPal），您可能会发现使用该付款方式的大量客户都没有被重定向回您的网站。 如果他们没有自动返回到订单确认/感谢页面，您可能需要在重定向到外部域名的“立即付款”按钮上实现Criteo OneTag，以便Criteo可以获取有关交易。  
  
以下示例所示为如何在名为“PayPal”的按钮上实现Criteo OneTag。 只需添加一个功能：  
  
**为了跟踪外部销售而在按钮上实现的Criteo OneTag**  

 `<!-- //Criteo Loader --> <script type="text/javascript" src="//dynamic.criteo.com/js/ld/ld.js?a=YOUR_PARTNER_ID" async="true"></script> <!--............ --> <script type="text/javascript"> function load_Criteo_OneTag(){  window.criteo_q = window.criteo_q || [];  window.criteo_q.push(  { event: "setAccount", account: YOUR UNIQUE ACCOUNT ID },  { event: "setSiteType", type: "m FOR MOBILE OR t FOR TABLET OR d FOR DESKTOP" },  { event: "setEmail", email: "TRIMMED AND LOWERCASE USER EMAIL ADDRESS" },  { event: "trackTransaction", id: "TRANSACTION ID",  item: [ { id: "FIRST PRODUCT ID", price: FIRST PRODUCT UNIT PRICE, quantity: FIRST PRODUCT QUANTITY },  { id: "SECOND PRODUCT ID", price: SECOND PRODUCT UNIT PRICE, quantity: SECOND PRODUCT QUANTITY }  /* add a line for each product in the user's basket */  ]}); } </script> <!--............ --> <button type="button" onclick="load_Criteo_OneTag()">PayPal</button>`

**如何避免统计因多次点击而导致的重复交易**  
  
有时用户会双击“立即付款”按钮，重定向到外部付款方式。 为了避免每次用户点击时均执行Criteo OneTag，您可以添加一个变量，从而防止事件执行多次。  
  
请查看以下示例：  
  
**在销售确认页面上实现的具有多次点击检测功能的Criteo OneTag：**

 `<!-- //Criteo Loader --> <script type="text/javascript" src="//dynamic.criteo.com/js/ld/ld.js?a=YOUR_PARTNER_ID" async="true"></script> <!-- // Declare the variable --> <script type="text/javascript">  var cto_clicked = false; </script> <!--............ --> <script type="text/javascript"> function load_Criteo_OneTag(){  if (!window.cto_clicked){  window.clicked = true;  window.criteo_q = window.criteo_q || [];  window.criteo_q.push(  { event: "setAccount", account: YOUR UNIQUE ACCOUNT ID },  { event: "setSiteType", type: "m FOR MOBILE OR t FOR TABLET OR d FOR DESKTOP" },  { event: "setEmail", email: "TRIMMED AND LOWERCASE USER EMAIL ADDRESS" },  { event: "trackTransaction", id: "TRANSACTION ID",  item: [ { id: "FIRST PRODUCT ID", price: FIRST PRODUCT UNIT PRICE, quantity: FIRST PRODUCT QUANTITY },  { id: "SECOND PRODUCT ID", price: SECOND PRODUCT UNIT PRICE, quantity: SECOND PRODUCT QUANTITY }  /* add a line for each product in the user's basket */  ]});  } } </script> <!--............ --> <button type="button" onclick="load_Criteo_OneTag()">PayPal</button>`

**生成随机交易ID**  
  
如果在用户点击“立即付款”按钮时，订单没有关联交易ID传递到Criteo OneTag，您可以使用此随机函数生成一个。  
  
**随机函数：**  
  
Math.floor(Math.random()\*9999999)  
  
在以下示例中，此随机函数与前缀“Button\_”相结合，以创建更容易识别的交易ID。 当您使用多种付款方式时，您可以针对用户选择的方法更改“Button”一词。 例如，如果您在重定向到PayPal的按钮上实现了此代码，则可以使用“PayPal\_”而不是“Button\_”，这样更容易识别交易。  
  
请注意，以下代码只是Criteo OneTag的trackTransaction事件的摘录，目的是突出显示与交易ID相关的部分。  
  
**在销售确认页面上实现的Criteo OneTag：**  

`<!--............ --> { event: "trackTransaction", id: "PayPal_" + Math.floor(Math.random()*9999999),  item: [ { id: "FIRST PRODUCT ID", price: FIRST PRODUCT UNIT PRICE, quantity: FIRST PRODUCT QUANTITY },  { id: "SECOND PRODUCT ID", price: SECOND PRODUCT UNIT PRICE, quantity: SECOND PRODUCT QUANTITY }  /* add a line for each product in the user's basket */ ]}); <!--............ -->`

Next: [How to avoid counting repeated transactions caused by multi-clicks](#step-4335430)

<a id="step-887078"></a>

## 旅游广告商的事件设置

```javascript
<script type="text/javascript" src="//dynamic.criteo.com/js/ld/ld.js?a=YOUR_PARTNER_ID" async="true"></script>

 <script type="text/javascript">

 window.criteo_q = window.criteo_q || [];

 window.criteo_q.push(

 { event: "setAccount", account: YOUR_UNIQUE_ACCOUNT_ID },

 { event: "setSiteType", type: "d" },

 { event: "setEmail", email: "criteotest@test.com" },

 { event: "viewSearch", checkin_date: "2016-08-12", checkout_date: "2016-08-18"},

 { event: "viewBasket", item: [ { id: "FLIGHT_ID1", price: 299.99, quantity: 1 }



 ]});

 </script>
```

如果您的网站包含预订日期或租赁某个产品的日期，则**viewSearch事件**可有助于提高您的广告活动效果。 在您的网站上实现**viewSearch**事件可让Criteo更好地了解用户对预订/租赁所期望的旅行/产品的兴趣。    

**viewSearch事件**

  
**viewSearch**事件收集起始日期和结束日期。 这些日期有助于Criteo AI Engine在购买前的正确时间更好地推荐合适的产品。 另外，还提供所需的信息，以便我们不会向已经不再对某个产品感兴趣的用户提供不相关的信息。 

  
**实现方式**

  
您只需在任何显示日期的页面上将以下事件添加到Criteo OneTag，然后使用以下格式动态发送日期：_yyyy-MM-dd_

 { event: "viewSearch", checkin\_date: "yyyy-MM-dd", checkout\_date: "yyyy-MM-dd"}

  
  
因此，如果在**购物篮事件**中实现了**viewSearch**事件，则事件将如下所示：  
 

<script type="text/javascript" src="//dynamic.criteo.com/js/ld/ld.js?a=YOUR\_PARTNER\_ID" async="true"></script>

 <script type="text/javascript">

 window.criteo\_q = window.criteo\_q || \[\];

 window.criteo\_q.push(

 { event: "setAccount", account: YOUR\_UNIQUE\_ACCOUNT\_ID },

 { event: "setSiteType", type: "d" },

 { event: "setEmail", email: "criteotest@test.com" },

 { event: "viewSearch", checkin\_date: "2016-08-12", checkout\_date: "2016-08-18"},

 { event: "viewBasket", item: \[ { id: "FLIGHT\_ID1", price: 299.99, quantity: 1 }

 \]});

 </script>

This path ends here.

<a id="step-887077"></a>

## 搜索列表页面上Criteo OneTag中的产品ID少于或多于3个

搜索列表页面显示**多个产品**，如**类别页面**或**搜索结果页面**。 在这些页面上实现Criteo OneTag可让Criteo跟踪用户对某个产品（例如，某个特定类别的产品）的兴趣。  
  
强烈建议您将排名前**三**的热销产品ID传递到搜索列表页面上的Criteo OneTag。 或者，您可以传递页面上所示产品的三个产品ID。

**传递的产品ID超过3个**

  
如果传递的产品ID超过三个，则Criteo将仅考虑提供的前三个ID。 为了确保取得最佳效果，建议您只传递三个ID。

**传递的产品ID少于3个**

  
如果传递的ID少于三个，则Criteo无法正确分析用户的意图；这将对您的广告活动的效果产生不利影响。 因此，您应始终将三个ID传递到Criteo OneTag。

此规则的唯一例外是搜索结果返回少于三种产品的情况。

This path ends here.

<a id="step-887072"></a>

## 设置netID集成

**European netID Foundation**

_“European netID Foundation由Mediengruppe RTL Deutschland、ProSiebenSat.1和United Internet AG于2018年3月成立。_

_基金会致力于_**_将netID发展成为美国单一登录提供商的欧洲替代提供商_**_。 借助netID隐私中心，用户可以按照数据保护法规，透明地管理他们对互联网服务给予的同意。_

_为此，基金会制定了一项开放标准，使各行各业的用户均能够使用相同的登录数据，获取基金会合作伙伴的所有互联网服务。”_  
  

**netID**

_“通过中央netID帐户，用户可以轻松便捷地登录大量互联网服务。  
在隐私中心以透明方式管理登录名和密码以及他们对使用他们的数据给予的同意——其优势在于，数据数据的控制权完全掌握在用户手中。  
用户可以随时在隐私中心更改他们的同意。  
因此，netID保证了高安全标准和最大程度的数据主权。”_

点击[此处](https://enid.foundation/en/netid/)访问netID官方网站。  
  

**netID与Onetag集成**

动态替换由##包围的字段。 有关字段的更多信息，请查看下表：

`<script type="text/javascript"> window.criteo_q = window.criteo_q || []; window.criteo_q.push({ event: 'setIdentity', identity: { source: "netid.de", uids: [{ id: "##NetID##" }] } }); </script>`  **  
setIdentity event**

此事件应与事件队队列中的任何其他事件一样触发。

This path ends here.

<a id="step-1948825"></a>

## SHA256和MD5（首选方法）

Criteo正在将我们身份图的加密处理方法从MD5/SHA256MD5加密电子邮箱转换为SHA256。 为了最大限度地提高您的数据与我们的身份图之间的匹配率，特别是在转换期间， 请共享旧格式（MD5或SHA256MD5）以及新SHA256格式。

在**setEmail**事件中发送的SHA256加密电子邮箱以及MD5电子邮箱的示例如下所示：

`{ event: "setEmail", email: "##Hashed Email Address##", hash_method: "md5" }`

`{ event: "setEmail", email: "##Hashed Email Address##", hash_method: "sha256" }`

> **Tip:** 在进行加密处理之前，所有用户的电子邮箱均需要进行以下处理：
>
> -   删除首尾空格；删除用户电子邮箱前后的所有空格。
>     
> -   转换为小写。
>     
> -   以UTF-8编码。

应将**setEmail**事件添加到您网站上的所有Criteo事件标签中（例如主页、产品、 添加到购物车、购物篮、销售/转化），以便只要您的网站上有电子邮件，就会进行传递。

以下步骤所示为此事件在Criteo主页标签中结合MD5与SHA256的组合或SHA256MD5与SHA256的组合的示例

- If "SHA256和MD5": [示例](#step-1950389)
- If "SHA256和SHA256MD5": [示例](#step-1950652)

<a id="step-1948824"></a>

## SHA256加密

如果您正在传递SHA256加密电子邮箱，请使用**setEmail**事件。

在**setEmail**事件中发送的SHA256加密电子邮箱的示例如下所示：

`{ event: "setEmail", email: "46a828eb4c5d239d631a15094c934cada1812d5fc22cd14155ca684832a70938", hash_method: "sha256" }`

> **Tip:** 在进行加密处理之前，所有用户的电子邮箱均需要进行以下处理：
>
> -   删除首尾空格；删除用户电子邮箱前后的所有空格。
>     
> -   转换为小写。
>     
> -   以UTF-8编码。

应将**setEmail**事件添加到您网站上的所有Criteo事件标签中（例如主页、产品、 添加到购物车、购物篮、销售/转化），以便只要您的网站上有电子邮件，就会进行传递。

以下步骤所示为此事件在Criteo主页标签中的示例。

Next: [示例](#step-1950477)

<a id="step-1948817"></a>

## 纯文本

```javascript
<!-- Criteo Homepage Tag -->

<script type="text/javascript">

  window.criteo_q = window.criteo_q || [];

  var deviceType = /iPad/.test(navigator.userAgent) ? "t" : /Mobile|iP(hone|od)|Android|BlackBerry|IEMobile|Silk/.test(navigator.userAgent) ? "m" : "d";

  window.criteo_q.push(

    { event: "setAccount", account: YOUR_PARTNER_ID},
    { event: "setEmail", email: "##Email Address##"},
    { event: "setSiteType", type: deviceType},
    { event: "setCustomerId", id: "##Customer Id##" },
    { event: "setRetailerVisitorId", id: "##Visitor Id##"},
    { event: "setZipcode", zipcode: "##Zip Code##" },
    { event: "viewHome" }

  );

</script>

<!-- END Criteo Homepage Tag -->
```

如果您传递的是纯文本电子邮箱，请使用**setEmail**事件。

如果发送的是纯文本电子邮箱，则Criteo会自动对用户的电子邮箱进行加密处理，然后将其保存在我们的数据库中。 以下是在**setEmail**事件中发送的纯文本电子邮箱示例：

`{ event: "setEmail", email: "user@example.com" },`

  
如果您无法传递未加密或已加密的电子邮箱，则向我们传递一个空字符串即可：

`{ event: "setEmail", email: "" },`

> **Warning:** 在某些国家，无论数据在存储之前是否经过加密处理，当地立法均不允许将明文电子邮箱传递给第三方。 虽然Criteo建议在与我们分享任何用户信息之前先对其进行加密处理，但也可选择分享明文电子邮件。 然而，如果客户决定分享未加密的信息，则他们必须了解现行法律，并决定最适合其业务以及所在市场的处理方法。

> **Tip:** 在传递纯文本电子邮箱时，所有用户的电子邮箱均需要：
>
> -   删除首尾空格；删除用户电子邮箱前后的所有空格。
>     
> -   转换为小写。
>     
> -   以UTF-8编码。

应将**setEmail**事件添加到您网站上的所有Criteo事件标签中（例如主页、产品、 添加到购物车、购物篮、销售/转化），以便只要您的网站上有电子邮件，就会进行传递。

此事件在Criteo主页标签中使用SHA256加密的示例如下所示。

This path ends here.

<a id="step-1950390"></a>

## MD5或SHA256MD5（旧方法）

如果您正在传递MD5或SHA256MD5加密电子邮件，请使用**setEmail**事件。

在**setEmail**事件中发送的MD5加密电子邮件的示例如下所示：

`{ event: "setEmail", email: "f3ada405ce890b6f8204094deb12d8a8", hash_method: "sha256" }`

在**setEmail**事件中发送的SHA256MD5加密电子邮件的示例如下所示：

`{ event: "setEmail", email: "0fb0ecec887b92bd4a793669f9a52e8c2af81cdf8a59bc7399c9bc910853fb66", hash_method: "sha256_md5" },`

> **Tip:** 在进行加密处理之前，所有用户的电子邮箱均需要进行以下处理：
>
> -   删除首尾空格；删除用户电子邮箱前后的所有空格。
>     
> -   转换为小写。
>     
> -   以UTF-8编码。

应将**setEmail**事件添加到您网站上的所有Criteo事件标签中（例如主页、产品、 添加到购物车、购物篮、销售/转化），以便只要您的网站上有电子邮件，就会进行传递。

以下步骤所示为此事件在Criteo主页标签中的示例。

- If "MD5加密": [示例](#step-1958150)
- If "SHA256MD5加密": [示例](#step-1958151)

<a id="step-1948827"></a>

## 加密函数

如果您在将用户的电子邮箱传递给Criteo之前对其进行加密处理，则可以使用以下函数之一以确保实现正确加密。

- If "使用JavaScript的SHA256加密函数": [使用JavaScript的SHA256加密函数](#step-1957333)
- If "使用C\#的SHA256加密函数": [使用C\#的SHA256加密函数](#step-1951709)
- If "使用Java的SHA256加密函数": [使用Java的SHA256加密函数](#step-1951710)
- If "使用Perl的SHA256加密函数": [使用Perl的SHA256加密函数](#step-1951708)
- If "使用PHP的SHA256加密函数": [使用PHP的SHA256加密函数](#step-1951742)
- If "使用PHP的MD5加密函数": [使用PHP的MD5加密函数](#step-1951849)
- If "使用C\#的MD5加密函数": [使用C\#的MD5加密函数](#step-1951850)
- If "使用Java的MD5加密函数": [使用Java的MD5加密函数](#step-1951851)
- If "使用JS的MD5加密函数": [使用JS的MD5加密函数](#step-3858724)

<a id="step-1948826"></a>

## 常见问题

**是否需要更新我的网站的隐私政策？**

您需要确保您的“网站隐私政策”清楚地告知您的网站访客——可能会收集电子邮箱并与您的第三方合作伙伴分享，以优化广告活动效果，并且使用最新、最安全的SHA256加密技术对有关信息进行加密处理。 因此，不会与第三方共享任何PII数据。

此外，您应该告知访客您尊重他们的隐私，如果他们不愿意分享有关信息，他们可以在您的网站用户cookie合规横幅 (CMP) 中选择他们首选的选项。

请查阅[Criteo隐私政策](https://help.criteo.com/kb/guide/en/the-criteo-privacy-promise-pDIW4yiawH/Steps/775742)以了解更多信息，您也可以将所提供的链接添加到您网站的“隐私政策”部分。 

> **Tip:** 如果您的法务团队对隐私有任何疑虑，他们可以联系您的Criteo业务联系人，后者会根据需要将他们与我们的法务团队对接。

**我已经在标签中传递了以MD5格式加密的电子邮件，我该怎么办？**

您应该继续使用此种方式传递并确保将“加密方法”参数设置为“md5”。 请注意，Criteo会接收此字符串 ，并在存储之前，通过SHA256对其进行额外编码。

然后，您应该在所有Criteo标签中添加额外的“**setEmail**” 事件，以便传递SHA256。 添加此附加事件时，请确保将“加密方法”参数设置为“sha256”，例如：

`{ event: "setEmail", email: "##Hashed Email Address##", hash_method: "md5" }`

`{ event: "setEmail", email: "##Hashed Email Address##", hash_method: "sha256" }`

**我已经在标签中传递了以SHA256MD5格式加密的电子邮件，我该怎么办？**

您应该继续使用此种方式传递并确保将“加密方法”参数设置为“md5”。 请注意，Criteo会接收此字符串，并在存储之前，对其进行额外的SHA256加密编码。

然后，您应该在所有Criteo标签中添加额外的“**setEmail**” 事件，以便传递SHA256。 添加此附加事件时，请确保将“加密方法”参数设置为“sha256”，例如：

`{ event: "setEmail", email: "##Hashed Email Address##", hash_method: "sha256_md5" }`

`{ event: "setEmail", email: "##Hashed Email Address##", hash_method: "sha256" }`

**我只能传递以SHA256加密处理的电子邮件，我该怎么办？**

无需进行任何更改。 请确保将“加密方法”参数设置为“sha256”，例如：

  `{ event: "setEmail", email: "##Hashed Email Address##", hash_method: "sha256" }`

This path ends here.

<a id="step-4106563"></a>

## SHA256

```javascript
<!-- Criteo Homepage Tag -->
<script type="text/javascript">
  window.criteo_q = window.criteo_q || [];
  var deviceType = /iPad/.test(navigator.userAgent) ? "t" : /Mobile|iP(hone|od)|Android|BlackBerry|IEMobile|Silk/.test(navigator.userAgent) ? "m" : "d";
  window.criteo_q.push(
    { event: "setAccount", account: YOUR_PARTNER_ID},
    { event: "setEmail", email: "##Email Address##", hash_method: "sha256" },
    { event: "setSha256HashedPhoneNumber", phone_number: "fda66831d0cb0eb4bffb21bc795308d69921c211c57be0ae15702071e3b9e989" },
    { event: "setSiteType", type: deviceType},
    { event: "setCustomerId", id: "##Customer Id##" },
    { event: "setRetailerVisitorId", id: "##Visitor Id##"},
    { event: "setZipcode", zipcode: "##Zip Code##" },
    { event: "viewHome" }
  );
</script>
```

由于电话号码属于敏感的PII，因此Criteo接受合作伙伴提供的加密电话号码，并鼓励这种做法。 

预期的相关电话号码格式是删除首尾空格[E.164](https://en.wikipedia.org/wiki/E.164)格式，包括国家代码，没有前导“+”号（因此最多只有15位数字）：sha256（internationalPhoneNumber.replaceAll(/\[^0-9\]/g, "")）。

**示例：**

-   1 (234) 567-8910 → sha256(12345678910) → 63640264849a87c90356129d99ea165e37aa5fabc1fea46906df1a7ca50db492
    
-   81-12-3456-7891 → sha256(811234567891) → d9825fb05347d3c910fc5202c0c20d07a87b791cc643c6f2d70402394a849540
    
-   02 1234 5678 → sha256(0212345678) → 826f54894e28f3f1795f3c5e3335cf98709c5d5b38b3f9c6d72467d491f032df
    
-   +33 1 40 40 22 90 → sha256(33140402290) → fda66831d0cb0eb4bffb21bc795308d69921c211c57be0ae15702071e3b9e988
    

如果您传递的是SHA256加密电话号码，请使用**setSha256HashedPhoneNumber**事件。 在setSha256HashedPhoneNumber事件中发送的SHA256加密电话号码的示例如下所示：

`{ event: "setSha256HashedPhoneNumber", phone_number: "fda66831d0cb0eb4bffb21bc795308d69921c211c57be0ae15702071e3b9e989" }`

应将**setSha256HashedPhoneNumber**事件添加到您网站上的**所有Criteo事件标签**中（例如主页、产品、 添加到购物车、购物篮、销售/转化），以便只要您的网站上有电话号码，就会进行传递。

左侧可以看到此事件在Criteo主页标签中的示例。

This path ends here.

<a id="step-4106562"></a>

## 纯文本

```javascript
<!-- Criteo Homepage Tag -->
<script type="text/javascript">
  window.criteo_q = window.criteo_q || [];
  var deviceType = /iPad/.test(navigator.userAgent) ? "t" : /Mobile|iP(hone|od)|Android|BlackBerry|IEMobile|Silk/.test(navigator.userAgent) ? "m" : "d";
  window.criteo_q.push(
    { event: "setAccount", account: YOUR_PARTNER_ID},
    { event: "setEmail", email: "##Email Address##", hash_method: "sha256" },
    { event: 'setPhoneNumber', phone_number: '+33 (0) 1 40 40 22 90' },
    { event: "setSiteType", type: deviceType},
    { event: "setCustomerId", id: "##Customer Id##" },
    { event: "setRetailerVisitorId", id: "##Visitor Id##"},
    { event: "setZipcode", zipcode: "##Zip Code##" },
    { event: "viewHome" }
  );
</script>
```

**如果发送的是纯文本电话号码，则Criteo会自动对用户的电话号码进行加密处理，然后将其保存在我们的数据库中。**

Criteo将对收集到的数字进行验证并规范。 接受任何国际格式（包括前导“+”号）。 规范化会删除所有非数字字符。

**验证检查：**

-   数字以+号开头
    
-   数字长度不超过15位
    
-   前面不加数字0：许多国家使用数字0作为国家拨号号码
    

**示例：**

-   +1 (234) 567-8910
    
-   +81-12-3456-7891
    
-   +33 1 40 40 22 90
    
-   02 1234 5678**不合格**，因为前面有数字0，表明这是一个国内电话号码
    

与其他ID一样，在存储电话号码之前也会对其进行加密处理。 Criteo的后端将清晰的电话号码映射到SHA256 HPN，因此两种可接受的格式是统一的。 Criteo无法访问与我们分享的任何电话号码。  

> **Tip:** 虽然可以接受明文电话号码，但是**强烈建议在分享任何类型的用户信息时使用SHA-256加密**。

> **Tip:** **注：**在某些国家，无论数据在存储之前是否经过加密处理，当地立法均不允许将明文电话号码传递给第三方。 虽然Criteo建议在与我们分享任何用户信息之前先对其进行加密处理，但也可选择分享明文电话号码。 然而，如果您决定分享未加密的信息，则您必须了解现行法律，并决定最适合您的业务以及所在市场的处理方法。

如果您传递的是纯文本电话号码，请使用**setPhoneNumber**事件。 在setPhoneNumber事件中发送的纯文本电话号码的示例如下所示：

`{ event: 'setPhoneNumber', phone_number: '+33 (0) 1 40 40 22 90' }`

应将**setPhoneNumber**事件添加到您网站上的**所有Criteo事件标签**中（例如主页、产品、 添加到购物车、购物篮、销售/转化），以便只要您的网站有电话号码，就会进行传递。  
  
左侧所示为此事件在Criteo主页标签中的示例。

This path ends here.

<a id="step-4335430"></a>

## How to avoid counting repeated transactions caused by multi-clicks

```javascript
<!-- //Criteo Loader --> 
 <script type="text/javascript" src="//dynamic.criteo.com/js/ld/ld.js?a=YOUR_PARTNER_ID" async="true">
</script> 
<!-- // Declare the variable --> 
<script type="text/javascript">  
    var cto_clicked = false; 
</script> 
<!--............ --> 
<script type="text/javascript"> 
function load_Criteo_OneTag(){  
    if (!window.cto_clicked){  
        window.clicked = true;  
        window.criteo_q = window.criteo_q || [];  
        window.criteo_q.push(  
            { event: "setAccount", account: ##YOUR UNIQUE ACCOUNT ID## },  
            { event: "setSiteType", type: "m FOR MOBILE OR t FOR TABLET OR d FOR DESKTOP" },  
            { event: "setEmail", email: "TRIMMED AND LOWERCASE USER EMAIL ADDRESS" },  
            { event: "trackTransaction", id: "TRANSACTION ID",  
            item: [ 
                { id: "FIRST PRODUCT ID", 
                price: ##FIRST PRODUCT UNIT PRICE##, 
                quantity: ##FIRST PRODUCT QUANTITY## },  
                { id: "SECOND PRODUCT ID", 
                price: ##SECOND PRODUCT UNIT PRICE##, 
                quantity: ##SECOND PRODUCT QUANTITY##} 
                 /* add a line for each product in the user's basket */  
            ]});  } } 
</script> 
<!--............ --> 
<button type="button" onclick="load_Criteo_OneTag()">PayPal</button>
```

Sometimes users will double-click the Pay Now button that redirects to the external payment method. To avoid executing the Criteo OneTag each time the user clicks, you can add a variable that prevents the event from being executed more than once.  
  
**The Criteo OneTag implemented on a Sales Confirmation page with multi-click detection is on the left.**

Next: [Generating a random Transaction ID](#step-4335431)

<a id="step-1950389"></a>

## 示例

```javascript
<!-- Criteo Homepage Tag -->

<script type="text/javascript">

  window.criteo_q = window.criteo_q || [];

  var deviceType = /iPad/.test(navigator.userAgent) ? "t" : /Mobile|iP(hone|od)|Android|BlackBerry|IEMobile|Silk/.test(navigator.userAgent) ? "m" : "d";

  window.criteo_q.push(

    { event: "setAccount", account: YOUR_PARTNER_ID},
    { event: "setEmail", email: "##Email Address##", hash_method: "sha256" },
    { event: "setEmail", email: "##Email Address##", hash_method: "md5" },
    { event: "setSiteType", type: deviceType},
    { event: "setCustomerId", id: "##Customer Id##" },
    { event: "setRetailerVisitorId", id: "##Visitor Id##"},
    { event: "setZipcode", zipcode: "##Zip Code##" },
    { event: "viewHome" }

  );

</script>

<!-- END Criteo Homepage Tag -->
```

This path ends here.

<a id="step-1950652"></a>

## 示例

```javascript
<!-- Criteo Homepage Tag -->

<script type="text/javascript">

  window.criteo_q = window.criteo_q || [];

  var deviceType = /iPad/.test(navigator.userAgent) ? "t" : /Mobile|iP(hone|od)|Android|BlackBerry|IEMobile|Silk/.test(navigator.userAgent) ? "m" : "d";

  window.criteo_q.push(

    { event: "setAccount", account: YOUR_PARTNER_ID},
    { event: "setEmail", email: "##Email Address##", hash_method: "sha256" },
    { event: "setEmail", email: "##Email Address##", hash_method: "sha256_md5" },
    { event: "setSiteType", type: deviceType},
    { event: "setCustomerId", id: "##Customer Id##" },
    { event: "setRetailerVisitorId", id: "##Visitor Id##"},
    { event: "setZipcode", zipcode: "##Zip Code##" },
    { event: "viewHome" }

  );

</script>

<!-- END Criteo Homepage Tag -->
```

This path ends here.

<a id="step-1950477"></a>

## 示例

```javascript
<!-- Criteo Homepage Tag -->

<script type="text/javascript">

  window.criteo_q = window.criteo_q || [];

  var deviceType = /iPad/.test(navigator.userAgent) ? "t" : /Mobile|iP(hone|od)|Android|BlackBerry|IEMobile|Silk/.test(navigator.userAgent) ? "m" : "d";

  window.criteo_q.push(

    { event: "setAccount", account: YOUR_PARTNER_ID},
    { event: "setEmail", email: "##Email Address##", hash_method: "sha256" },
    { event: "setSiteType", type: deviceType},
    { event: "setCustomerId", id: "##Customer Id##" },
    { event: "setRetailerVisitorId", id: "##Visitor Id##"},
    { event: "setZipcode", zipcode: "##Zip Code##" },
    { event: "viewHome" }

  );

</script>

<!-- END Criteo Homepage Tag -->
```

This path ends here.

<a id="step-1958150"></a>

## 示例

```javascript
<!-- Criteo Homepage Tag -->

<script type="text/javascript">

  window.criteo_q = window.criteo_q || [];

  var deviceType = /iPad/.test(navigator.userAgent) ? "t" : /Mobile|iP(hone|od)|Android|BlackBerry|IEMobile|Silk/.test(navigator.userAgent) ? "m" : "d";

  window.criteo_q.push(

    { event: "setAccount", account: YOUR_PARTNER_ID},
    { event: "setEmail", email: "##Email Address##", hash_method: "md5" },
    { event: "setSiteType", type: deviceType},
    { event: "setCustomerId", id: "##Customer Id##" },
    { event: "setRetailerVisitorId", id: "##Visitor Id##"},
    { event: "setZipcode", zipcode: "##Zip Code##" },
    { event: "viewHome" }

  );

</script>

<!-- END Criteo Homepage Tag -->
```

This path ends here.

<a id="step-1958151"></a>

## 示例

```javascript
<!-- Criteo Homepage Tag -->

<script type="text/javascript">

  window.criteo_q = window.criteo_q || [];

  var deviceType = /iPad/.test(navigator.userAgent) ? "t" : /Mobile|iP(hone|od)|Android|BlackBerry|IEMobile|Silk/.test(navigator.userAgent) ? "m" : "d";

  window.criteo_q.push(

    { event: "setAccount", account: YOUR_PARTNER_ID},
    { event: "setEmail", email: "##Email Address##", hash_method: "sha256_md5" },
    { event: "setSiteType", type: deviceType},
    { event: "setCustomerId", id: "##Customer Id##" },
    { event: "setRetailerVisitorId", id: "##Visitor Id##"},
    { event: "setZipcode", zipcode: "##Zip Code##" },
    { event: "viewHome" }

  );

</script>

<!-- END Criteo Homepage Tag -->
```

This path ends here.

<a id="step-1957333"></a>

## 使用JavaScript的SHA256加密函数

```javascript
async function sha256(message) {
  // encode as UTF-8
  const msgBuffer = new TextEncoder('utf-8').encode(message);

  // hash the message
  const hashBuffer = await crypto.subtle.digest('SHA-256', msgBuffer);

  // convert ArrayBuffer to Array
  const hashArray = Array.from(new Uint8Array(hashBuffer));

  // convert bytes to hex string
  const hashHex = hashArray.map(b => ('00' + b.toString(16)).slice(-2)).join('');
  return hashHex;
}

function format(email) {
	return email.toLowerCase().trim();
}

var email = "   uSèr@example.Com   ";
//CHANGE BASED ON WHAT YO USUALLY PUT AS EXAMPLE
var hemPromise = sha256(format(email));
hemPromise.then(hem => console.log(hem));
```

This path ends here.

<a id="step-1951709"></a>

## 使用C\#的SHA256加密函数

```text/x-csharp
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
namespace Sample_EmailHashing_code {
  public class CriteoHashedEmailFormatter {
    private static SHA256 _sha256;
    private static SHA256 Sha256 {
      get {
        return _sha256 ?? (_sha256 = SHA256.Create());
      }
    }
    private static string Sha256Encode(string sourceString) {
      byte[] inputBytes = Encoding.UTF8.GetBytes(sourceString);
      byte[] hash = Sha256.ComputeHash(inputBytes);
      var sb = new StringBuilder(32);
      foreach(byte b in hash) sb.Append(b.ToString("x2"));
      return sb.ToString();
    }
    public static string HashEmail(string sourceEmail) {
      String processedEmail;
      processedEmail = sourceEmail.ToLowerInvariant(); //conversion to lower case
      processedEmail = processedEmail.Trim(); //trimming leading and trailing spaces
      processedEmail = Sha256Encode(processedEmail); //conversion to UTF-8 and hashing with SHA256
      return processedEmail;
    }
  }
  class SampleEmailHashing {
    static void Main(string[] args) {
      String sourceEmail = "   uSèr@example.Com   ";
      String processedEmail = CriteoHashedEmailFormatter.HashEmail(sourceEmail);
      Console.WriteLine(processedEmail);
      Console.ReadKey();
    }
  }
}
```

This path ends here.

<a id="step-1951710"></a>

## 使用Java的SHA256加密函数

```text/x-java
import java.io.*;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class SampleEmailHashing {
  public static void main(String[] args) {
    String sourceEmail = new String(" uSèr@example.Com ");
    String processedEmail = FormatMail(sourceEmail);
    System.out.println(processedEmail);
  } //Method to format the source Email, converting to lower case and removing spaces               
  private static String FormatMail(String mail) {
    String newMail = new String(mail);
    // conversion to lower case characters          
    newMail = newMail.toLowerCase();
    //remove empty spaces          
    newMail = newMail.trim();
    newMail = sha256Java(newMail);
    return newMail;
  } //Method to encrypt email address using MD5      
  public static String sha256Java(String message) {
    String digest = null;
    try { //conversion to UTF-8 and hashing with SHA256
      MessageDigest md = MessageDigest.getInstance("SHA256");
      byte[] hash = md.digest(message.getBytes("UTF-8"));
      StringBuilder sb = new StringBuilder(2 * hash.length);
      for (byte b: hash) {
        sb.append(String.format("%02x", b & 0xff));
      }
      digest = sb.toString();
    } catch (UnsupportedEncodingException ex) {
      ex.printStackTrace();
    } catch (NoSuchAlgorithmException ex) {
      ex.printStackTrace();
    }
    return digest;
  }
}
```

This path ends here.

<a id="step-1951708"></a>

## 使用Perl的SHA256加密函数

```perl
#!/usr/bin/perl  

 use strict;  

 use warnings;  

 use Digest::SHA256 qw(sha256 sha256_hex);  

 use Encode;  

 my $original_email  = qw/ uSèr@example.Com /;  

 my $processed_email = lc($original_email);     

    $processed_email =~ s/^\s+//;     

    $processed_email =~ s/\s+$//;     

    $processed_email = encode_utf8($processed_email);     

    $processed_email = sha256_hex($processed_email);  

 print "Original email:\t$original_email\n";  

 print "Hashed email:\t$processed_email \n"; 
```

This path ends here.

<a id="step-1951742"></a>

## 使用PHP的SHA256加密函数

```php
$source_address = "uSèr@example.Com "; 
$processed_address = strtolower($source_address); //convert address to lower case 
$processed_address = trim($processed_address); //trimming leading and trailing spaces
$processed_address = mb_convert_encoding($processed_address, "UTF-8", "ISO-8859-1"); //conversion from ISO-8859-1 to UTF-8 (replace "ISO-8859-1" with the source encoding of your string) 
$processed_address = hash('sha256', $processed_address, false); //hash address with SHA256 algorithm 
echo "Source e-mail: ".$source_address." | Hashed e-mail: ".$processed_address;
```

This path ends here.

<a id="step-1951849"></a>

## 使用PHP的MD5加密函数

```php
$source_address = "uSèr@example.Com "; 
$processed_address = strtolower($source_address); //convert address to lower case 
$processed_address = trim($processed_address); //trimming leading and trailing spaces 
$processed_address = mb_convert_encoding($processed_address, "UTF-8", "ISO-8859-1"); //conversion from ISO-8859-1 to UTF-8 (replace "ISO-8859-1" with the source encoding of your string) 
$processed_address = hash('md5', $processed_address, false); //hash address with SHA256 algorithm 
echo "Source e-mail: ".$source_address." | Hashed e-mail: ".$processed_address;
```

This path ends here.

<a id="step-1951850"></a>

## 使用C\#的MD5加密函数

```text/x-csharp
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
namespace Sample_EmailHashing_code {
  public class CriteoHashedEmailFormatter {
    private static MD5 _md5;
    private static MD5 Md5 {
      get {
        return _md5 ?? (_md5 = MD5.Create());
      }
    }
    private static string Md5Encode(string sourceString) {
      byte[] inputBytes = Encoding.UTF8.GetBytes(sourceString);
      byte[] hash = Md5.ComputeHash(inputBytes);
      var sb = new StringBuilder(32);
      foreach(byte b in hash) sb.Append(b.ToString("x2"));
      return sb.ToString();
    }
    public static string HashEmail(string sourceEmail) {
        String processedEmail;
        processedEmail = sourceEmail.ToLowerInvariant(); //conversion to lower case              
        processedEmail = processedEmail.Trim(); //trimming leading and trailing spaces              
        //conversion to UTF-8 and hashing with SHA256              
        processedEmail = Md5Encode(processedEmail);              
        return processedEmail;          
    }      
  }      
  class SampleEmailHashing      {          
    static void Main(string[] args)          {              
      String sourceEmail = "   uSèr@example.Com   ";              
      String processedEmail = CriteoHashedEmailFormatter.HashEmail(sourceEmail);              
      Console.WriteLine(processedEmail);              Console.ReadKey();          
    }      
  }  
}
```

This path ends here.

<a id="step-1951851"></a>

## 使用Java的MD5加密函数

```clike
import java.io.*;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class SampleEmailHashing {
  public static void main(String[] args) {
    String sourceEmail = new String(" uSèr@example.Com ");
    String processedEmail = FormatMail(sourceEmail);
    System.out.println(processedEmail);
  } //Method to format the source Email, converting to lower case and removing spaces               
  private static String FormatMail(String mail) {
    String newMail = new String(mail);
    // conversion to lower case characters          
    newMail = newMail.toLowerCase();
    //remove empty spaces          
    newMail = newMail.trim();
    newMail = md5Java(newMail);
    return newMail;
  } //Method to encrypt email address using MD5      
  public static String md5Java(String message) {
    String digest = null;
    try { //conversion to UTF-8 and hashing with MD5
      MessageDigest md = MessageDigest.getInstance("MD5");
      byte[] hash = md.digest(message.getBytes("UTF-8"));
      StringBuilder sb = new StringBuilder(2 * hash.length);
      for (byte b: hash) {
        sb.append(String.format("%02x", b & 0xff));
      }
      digest = sb.toString();
    } catch (UnsupportedEncodingException ex) {
      ex.printStackTrace();
    } catch (NoSuchAlgorithmException ex) {
      ex.printStackTrace();
    }
    return digest;
  }
}
```

This path ends here.

<a id="step-3858724"></a>

## 使用JS的MD5加密函数

```javascript
// md5 function should be provided by the client (by installing a 3rd party one)

function format(email) {
	return email.toLowerCase().trim();
}

var email = "   uSèr@example.Com   ";
var hemPromise = md5(format(email));
hemPromise.then(hem => console.log(hem));
```

> **Tip:** **重要提示**
>
> 在页面中实现代码之前，请确保安装此外部库[https://www.md5.cz/javascript-md5](https://www.md5.cz/javascript-md5b)。

This path ends here.

<a id="step-4335431"></a>

## Generating a random Transaction ID

```javascript
<!--............ --> 
{ event: "trackTransaction", 
    id: "PayPal_" + Math.floor(Math.random()*9999999),  
    item: [ 
        { id: "FIRST PRODUCT ID", 
        price: ##FIRST PRODUCT UNIT PRICE##, 
        quantity: ##FIRST PRODUCT QUANTITY## },  
        { id: "SECOND PRODUCT ID", 
        price: ##SECOND PRODUCT UNIT PRICE##, 
        quantity: ##SECOND PRODUCT QUANTITY## }  
        /* add a line for each product in the user's basket */ 
    ]}); 
<!--............ -->  
```

In the event that the order does not have an associated Transaction ID to pass into the Criteo OneTag when the user clicks on the Pay Now button, you can use this random function to generate one.  
  
**Random function:**  
  
 Math.floor(Math.random()\*9999999)  
  
In the example below, this random function is combined with the prefix "Button\_" in order to create a Transaction ID that is more easily identified. Where you use multiple payment options you can change the word "Button" for the method selected by the user. For example, if you implemented this code on a button that redirects to PayPal, you can use "PayPal\_" instead of "Button\_" so it is even easier to identify the transaction.  
  
Note that the code on the left is just an extract of the trackTransaction event of the Criteo OneTag in order to highlight the portion relating to the Transaction ID.  
  
**The Criteo OneTag implemented on a Sales Confirmation page on the left.**

This path ends here.
