# 範例：1shop 瀏覽商品

## 瀏覽商品 新增變數

<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%2FJ0GKdUMK1larYfe8SvXC%2Fimage.png?alt=media&#x26;token=d0f38df7-8062-4e7d-abea-182a2423b682" alt=""><figcaption><p>加入購物車變數</p></figcaption></figure>

* 變數名稱：1shop \[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%2F0FZPdmI2rDfYEGEipjFa%2Fimage.png?alt=media&#x26;token=5bcd1e2c-a76b-493c-9b27-66ebafb0490a" alt=""><figcaption><p>瀏覽商品事件</p></figcaption></figure>

* 觸發名稱：1shop\[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%2F4ezMYr3bR3hb256oO0QB%2Fimage.png?alt=media&#x26;token=ec7bee21-bd5d-4056-a71a-6a56969bae90" alt=""><figcaption><p>瀏覽商品追蹤</p></figcaption></figure>

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

```javascript
<script>
if({{1shop [view_item] prdouct_items}} !== undefined && {{1shop [view_item] prdouct_items}} != null){
	var items = {{1shop [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].name,
				    'category': items[i].category,
				    'brand': '',
				    'tag': '',
				    'price': items[i].price
				});
			}
		}
	}
}
</script>
```

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

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

#### 提醒

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