# 範例：shopline 瀏覽商品

## 瀏覽商品 新增變數

<figure><img src="https://2075385674-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FA8vmX591TX7ccV7n1Qcw%2Fuploads%2F8ZpdLCrZmX9WeDFTjaSz%2Fimage.png?alt=media&#x26;token=aa68aa9d-e4d0-4c01-9a9a-4ece53fa9971" alt=""><figcaption><p>新增變數</p></figcaption></figure>

### 瀏覽商品 product\_items

<figure><img src="https://2075385674-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FA8vmX591TX7ccV7n1Qcw%2Fuploads%2FTjkfer7qIzcTQUrJfKEo%2Fimage.png?alt=media&#x26;token=f8028cc4-0286-480b-a20f-6999b8e98b5e" alt=""><figcaption><p>瀏覽商品變數</p></figcaption></figure>

* 變數名稱：shopline \[view\_item] prdouct\_items
* 變數類型：資料層變數
* 資料層變數名稱：eventModel.items
* 按下「儲存」

***

## 新增觸發條件

<figure><img src="https://2075385674-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FA8vmX591TX7ccV7n1Qcw%2Fuploads%2FMXHIHY1kmVqRN1A9s79A%2Fimage.png?alt=media&#x26;token=1ab5a496-efaf-4fcc-a9c4-1a2bf5c69819" alt=""><figcaption><p>新增觸發事件</p></figcaption></figure>

<figure><img src="https://2075385674-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FA8vmX591TX7ccV7n1Qcw%2Fuploads%2FCv84Em0Iok5E5umSFpUC%2Fimage.png?alt=media&#x26;token=45d1e04b-a996-4924-a53b-480a72227b7a" alt=""><figcaption><p>瀏覽商品事件</p></figcaption></figure>

* 觸發名稱：shopline\[view\_item] (可更改)
* 觸發條件類型：自訂事件
* 事件名稱：view\_item
* 按下「儲存」

***

## 新增代碼

<figure><img src="https://2075385674-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FA8vmX591TX7ccV7n1Qcw%2Fuploads%2FUfHMuXUYJnlpTHtIcitW%2Fimage.png?alt=media&#x26;token=07663b9e-0534-45de-8bfe-93b048cb3503" alt=""><figcaption><p>建立代碼</p></figcaption></figure>

<figure><img src="https://2075385674-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FA8vmX591TX7ccV7n1Qcw%2Fuploads%2F4YAY6Mj6utksTtszhAPt%2Fimage.png?alt=media&#x26;token=972ebc8a-be11-4c43-a086-343d9b005fb0" alt=""><figcaption><p>瀏覽商品追蹤</p></figcaption></figure>

* 代碼名稱： \[shopline] view\_item
* 代碼類型：自訂 HTML
* HTML：複製下面內容程式碼貼上

```javascript
<script>
if({{shopline [view_item] prdouct_items}} !== undefined &&{{shopline [view_item] prdouct_items}} != null){
	var items = {{shopline [view_item] prdouct_items}};

	if(items.length > 0){
		for(var i in items){
			if(items[i] !== undefined){
				itg('anchor', 'product',{
				    'type':'view',
				    'id': items[i].item_id,
				    'category': '',
				    'brand': '',
				    'tag': '',
				    'price': (items[i].price - items[i].discount) * items[i].quantity
				});
			}
		}
	}
}
</script>
```

* 觸發條件：shopline\[view\_item]（ [#xin-zeng-chu-fa-tiao-jian](#xin-zeng-chu-fa-tiao-jian "mention")）

按下右上角「儲存」按鈕後，點擊右上角「提交」並且「發布」即可生效。

#### 提醒

* 請先用「預覽」功能測試，確認「Tags Fired」是否有觸發成功
