# 自动触发器

此功能允许通过单一配置管理多种跟踪操作。基于预定义条件（如匹配网站路径、主机名或引用来源），SDK 会自动触发相应的函数。

通过这种方式，可以在不重复设置的情况下控制和自定义跟踪行为，从而更容易在不同场景中管理和扩展跟踪。&#x20;

### 开始使用

要使用 Offer18 的 Web SDK 启动自动跟踪，需要在网站中添加一个脚本标签。

<mark style="color:紫色;">放置位置：页头（所有页面）</mark>

{% code fullWidth="false" %}

```html
<script src="https://web-resources.offer18.net/sdk/web/WebSDK.js"></script>
```

{% endcode %}

***

### 跟踪点击&#x20;

要使用自动化 SDK 脚本跟踪点击，请将以下代码添加到您的网站。

<mark style="color:紫色;">放置位置：页头（所有页面）</mark>

{% code overflow="wrap" %}

```html
<script>
	window.Offer18SDK.init({
		automatedTrigger: true,
		opeations: [{
			triggerFunction: "trackClick",
			triggerconditios: [
				{
					mode: "<condition-mode>", // contain or equal
					type: "<condition-type>", // path / hostname / referral
					value: "<condition-value>"
				}
			],
			triggerConfig: {
				trackingURL: "https://example.com?c/o=xxx&m=000&a=000",
				keymapping: ['<OFFER18-PARAMETER>:<YOUR-PARAMETER>', '<OFFER18-PARAMETER>:<YOUR-PARAMETER>', ...]
			}
		}]
	})
</script>
```

{% endcode %}

***

### 跟踪展示

要使用自动化 SDK 脚本跟踪展示，请将以下代码添加到您的网站。

<mark style="color:紫色;">放置位置：页头（所有页面）</mark>

{% code overflow="wrap" %}

```html
<script>
	window.Offer18SDK.init({
		automatedTrigger: true,
		opeations: [{
			triggerFunction: "trackImpression",
			triggerconditios: [
				{
					mode: "<condition-mode>", // contain or equal
					type: "<condition-type>", // path / hostname / referral
					value: "<condition-value>"
				}
			],
			triggerConfig: {
				impressionURL: "https://example.com?i/o=xxx&m=000&a=000",
				keymapping: ['<OFFER18-PARAMETER>:<YOUR-PARAMETER>', '<OFFER18-PARAMETER>:<YOUR-PARAMETER>', ...]
			}
		}]
	})
</script>
```

{% endcode %}

***

### 跟踪转化

用户必须将以下代码片段添加到除订单确认/订单成功（感谢页）之外的所有落地页。

<mark style="color:紫色;">放置位置：页头（所有页面）</mark>

```html
<script>
	window.Offer18WebSDK.init({
		automatedTrigger: true,
		operations: [
			{
				triggerFunction: "initializeUrlParam",
				triggerConditions: [
					{
						mode: "<condition-mode>", // contain or equal
						type: "<condition-type>", // path / hostname / referral
						value: "<condition-value>"
					}
				],
				triggerConfig: {
					clickIdParameter: "<YOUR-CLICK-ID-PARAMETER>",
				}
			}
		]
	})
</script>
```

随后在感谢页/订单确认页面将以下代码添加到您的网站。

<mark style="color:紫色;">放置位置：感谢页/订单成功页（单页）</mark>

```html
<script>
	window.Offer18WebSDK.init({
		automatedTrigger: true,
		operations: [
			{
				triggerFunction: "trackConversion",
				triggerConditions: [
					{
						mode: "<condition-mode>", // contain or equal
						type: "<condition-type>", // path / hostname / referral
						value: "<condition-value>"
					}
				],
				triggerConfig: {
					domain: '',
					accountId: '',
					offerId: '',
					coupon: '',
					postbackType: '', // 'iframe' or 'pixel'
					isGlobalPixel: false, // true or false
					allowMultiConversion: false, // true or false
					conversionData: {
						event: '', // Event Name (Please specify the event)
						payout: '', // Payout Amount (Please specify the payout amount)
						sale: '', // Sale Amount (Please specify the sale amount)
						currency: '',
						adv_sub1: '',
						adv_sub2: '',
						adv_sub3: '',
						adv_sub4: '',
						adv_sub5: '',
					}
				}
			}
		]
	});
</script>
```

### 调试模式 <a href="#debug-mode" id="debug-mode"></a>

要在 SDK 中启用调试模式，可以在脚本中添加以下代码：

```html
<script>
    window.Offer18WebSDK.activateDebugMode();
</script>
```

启用调试模式可让用户获得有关 SDK 工作的更详细信息，包括任何错误或调试信息。

### 示例代码

```html
<script src="https://web-resources.offer18.net/sdk/web/WebSDK.js"></script>
<script>
    window.Offer18SDK.init({
        automatedTrigger: true,
        opeations: [{
            triggerFunction: "trackClick",
            triggerconditios: [
                { mode: "equal", type: "hostname", value: "websiteurl.com" }
            ],
            triggerConfig: {
                trackingURL: "https://example.o18.click/c?o=0000000&m=0000",
                keymapping: ['a:utm_source']
            }
        },
        {
            triggerFunction: "trackImpression",
            triggerconditios: [
                { mode: "equal", type: "hostname", value: "websiteurl.com" }
            ],
            triggerConfig: {
                impressionURL: "https://example.o18.click/i?o=0000000&m=0000",
                keymapping: ['a:utm_source']
            }
        },
        {
            triggerFunction: "initializeUrlParam",
            triggerconditios: [
                { mode: "equal", type: "hostname", value: "websiteurl.com" }
            ],
            triggerConfig: {
                clickIdParameter: "tid",
            }
        },
        {
            triggerFunction: "trackConversion",
            triggerConditions: [
                { mode: "equal", type: "hostname", value: "websiteurl.com" },
                { mode: "contain", type: "path", value: "thank-you" }
            ],
            triggerConfig: {
                domain: 'example.o18.link',
                accountId: '0000',
                offerId: '00000000',
            }
        }
        ]
    });
</script>
```
