/* 
	Ichi Cake 網站放置追蹤code – Google分析
	头部 head.html
	商品详情页 list/details.html  details.js
	所有商品页 list/index.html  list.js
	购物车 shopping/index.html shop.js
	支付页面  shoping/payment.html
	支付成功/失败  shopping/succeed.html  shopping/errors.html	
*/

/* 
1. 衡量商品展示
	要衡量商品的展示情况，请发送包含相应商品信息的 view_item_list：
	
3. 衡量将商品添加到购物车或从购物车中移除商品的操作
	要衡量将商品添加到购物车的操作，请发送包含相应商品信息的 add_to_cart 事件：
	要衡量从购物车中移除商品的操作，请发送包含商品信的 remove_from_cart 事件：
	
4. 衡量结帐步骤
	要衡量第一个结帐步骤，请发送一个包含结帐商品的 begin_checkout 事件：
	要衡量每个后续结帐步骤，请发送一个包含结帐商品的 checkout_progress 事件：
 */

/* 
	@list_name 列表名称
	@page 第几页
	@funs 使用方法
	@items 商品列表
*/
function gtag_funs(list_name='',page=1,funs='view_item_list',items=null){
	if(items==null){
		var items=[];
		$('.gtag-view_item_list .view_item').each(function(k,v){
		
			items[k]={
		        "id": $(v).find('.gtag-id').val(),
		        "name":$(v).find('.gtag-name').val(),
		    	"list_name": list_name,//列表名称
		    	"price": $(v).find('.gtag-price').val(),
				"list_position":page,
		    }
			
		});
	}
	
	gtag('event',funs, {
	  "items": items
	});
}


/* 
5. 衡量购买
	要衡量交易，请发送包含交易中商品的 purchase 事件： 
 */
function purchase(list_name=''){
	var items=[];
	$('.gtag-view_item_list .view_item').each(function(k,v){
	
		items[k]={
	        "id": $(v).find('.gtag-id').val(),
	        "name":$(v).find('.gtag-name').val(),
	    	"list_name": list_name,//列表名称
	    	"price": $(v).find('.gtag-price').val(),
			"list_position":1,
	    }
		
	});

	gtag('event', 'purchase', {
	  "items":items
	});
}

