# 範例：1shop 送出訂單

## 新增變數

<figure><img src="/files/wXEW6BccNgUMXQ0tXUHK" alt=""><figcaption><p>新增變數</p></figcaption></figure>

### 購物商品

<figure><img src="/files/jPouFPo16fQQ3iCW5oQ4" alt=""><figcaption><p>購物商品</p></figcaption></figure>

* 變數名稱：1shop \[purchase] purchase\_items
* 變數類型：資料層變數
* 資料層變數名稱：eventModel.items
* 按下「儲存」

### 購物 ID

如上述新增變數步驟，再建立 purchase\_id 變數

* 變數名稱：1shop \[purchase] purchase\_id
* 變數類型：資料層變數
* 資料層變數名稱：eventModel.transaction\_id
* 按下「儲存」

### 購物 User ID

如上述新增變數步驟，再建立 purchase\_user\_id 變數

* 變數名稱：1shop \[purchase] purchase\_user\_id
* 變數類型：資料層變數
* 資料層變數名稱：eventModel.user\_id
* 按下「儲存」

### 購物金額

如上述新增變數步驟，再建立 purchase\_price 變數

* 變數名稱：1shop \[purchase] purchase\_price
* 變數類型：資料層變數
* 資料層變數名稱：eventModel.value
* 按下「儲存」

***

## 新增觸發條件

<figure><img src="/files/TbuQE6OXVBhYCVk2b9Ip" alt=""><figcaption><p>新增觸發事件</p></figcaption></figure>

<figure><img src="/files/JRjcT39heDQbPstSLWUk" alt=""><figcaption><p>送出訂單事件</p></figcaption></figure>

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

***

## 新增代碼

<figure><img src="/files/TsPmKE7iTBfCefncuxWT" alt=""><figcaption><p>建立代碼</p></figcaption></figure>

<figure><img src="/files/PWCk50Hr0XRLZmGJJa1H" alt=""><figcaption><p>送出訂單追蹤代碼</p></figcaption></figure>

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

```javascript
<script>
var data = {
	'id': {{1shop [purchase] purchase_id}},
	'user_id': {{1shop [purchase] purchase_user_id}},
	'product': '',
	'amount': {{1shop [purchase] purchase_price}}
};

if({{1shop [purchase] purchase_items}} !== undefined){
    var items = {{1shop [purchase] purchase_items}};
  
	for(var i in items){
		if(items[i] !== undefined){
			data.product += (data.product == '')? items[i].name : ',' + items[i].name;
		}
	}

	if(data.product != ''){
		itg('event', 'purchase',{
		    'id':   data.id,             
		    'price': data.amount,
		    'promotion': '',
		    'product': data.product,
            'user':{
				'type': 'own',
				'id': data.user_id,
				'email': '',
				'phone': ''
            }
		});
	}
}
</script>
```

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

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

#### 提醒

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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://instag.gitbook.io/doc/cheng-shi-ma-zi-ding-an-zhuang/gou-mai-zhui-zong/fan-li-1shop-song-chu-ding-dan.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
