1package analytics 2 3// This type is used to represent properties in messages that support it. 4// It is a free-form object so the application can set any value it sees fit but 5// a few helper method are defined to make it easier to instantiate properties with 6// common fields. 7// Here's a quick example of how this type is meant to be used: 8// 9// analytics.Page{ 10// UserId: "0123456789", 11// Properties: analytics.NewProperties() 12// .SetRevenue(10.0) 13// .SetCurrency("USD"), 14// } 15// 16type Properties map[string]interface{} 17 18func NewProperties() Properties { 19 return make(Properties, 10) 20} 21 22func (p Properties) SetRevenue(revenue float64) Properties { 23 return p.Set("revenue", revenue) 24} 25 26func (p Properties) SetCurrency(currency string) Properties { 27 return p.Set("currency", currency) 28} 29 30func (p Properties) SetValue(value float64) Properties { 31 return p.Set("value", value) 32} 33 34func (p Properties) SetPath(path string) Properties { 35 return p.Set("path", path) 36} 37 38func (p Properties) SetReferrer(referrer string) Properties { 39 return p.Set("referrer", referrer) 40} 41 42func (p Properties) SetTitle(title string) Properties { 43 return p.Set("title", title) 44} 45 46func (p Properties) SetURL(url string) Properties { 47 return p.Set("url", url) 48} 49 50func (p Properties) SetName(name string) Properties { 51 return p.Set("name", name) 52} 53 54func (p Properties) SetCategory(category string) Properties { 55 return p.Set("category", category) 56} 57 58func (p Properties) SetSKU(sku string) Properties { 59 return p.Set("sku", sku) 60} 61 62func (p Properties) SetPrice(price float64) Properties { 63 return p.Set("price", price) 64} 65 66func (p Properties) SetProductId(id string) Properties { 67 return p.Set("id", id) 68} 69 70func (p Properties) SetOrderId(id string) Properties { 71 return p.Set("orderId", id) 72} 73 74func (p Properties) SetTotal(total float64) Properties { 75 return p.Set("total", total) 76} 77 78func (p Properties) SetSubtotal(subtotal float64) Properties { 79 return p.Set("subtotal", subtotal) 80} 81 82func (p Properties) SetShipping(shipping float64) Properties { 83 return p.Set("shipping", shipping) 84} 85 86func (p Properties) SetTax(tax float64) Properties { 87 return p.Set("tax", tax) 88} 89 90func (p Properties) SetDiscount(discount float64) Properties { 91 return p.Set("discount", discount) 92} 93 94func (p Properties) SetCoupon(coupon string) Properties { 95 return p.Set("coupon", coupon) 96} 97 98func (p Properties) SetProducts(products ...Product) Properties { 99 return p.Set("products", products) 100} 101 102func (p Properties) SetRepeat(repeat bool) Properties { 103 return p.Set("repeat", repeat) 104} 105 106func (p Properties) Set(name string, value interface{}) Properties { 107 p[name] = value 108 return p 109} 110 111// This type represents products in the E-commerce API. 112type Product struct { 113 ID string `json:"id,omitempty"` 114 SKU string `json:"sky,omitempty"` 115 Name string `json:"name,omitempty"` 116 Price float64 `json:"price"` 117} 118