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