-
Notifications
You must be signed in to change notification settings - Fork 3
/
metrics.go
274 lines (243 loc) · 10.8 KB
/
metrics.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
package chartmogul
// MetricsFilter convenient object to hold all filtering parameters.
type MetricsFilter struct {
StartDate string `json:"start-date,omitempty"`
EndDate string `json:"end-date,omitempty"`
Interval string `json:"interval,omitempty"`
Geo string `json:"geo,omitempty"`
Plans string `json:"plans,omitempty"`
}
// AllMetrics represents results of Metrics API.
type AllMetrics struct {
Date string `json:"date"`
CustomerChurnRate float64 `json:"customer-churn-rate"`
MrrChurnRate float64 `json:"mrr-churn-rate"`
Ltv float64 `json:"ltv"`
Customers uint32 `json:"customers"`
Asp float64 `json:"asp"`
Arpa float64 `json:"arpa"`
Arr float64 `json:"arr"`
Mrr float64 `json:"mrr"`
CustomerChurnRatePercentageChange float64 `json:"customer-churn-rate-percentage-change"`
MrrChurnRatePercentageChange float64 `json:"mrr-churn-rate-percentage-change"`
LtvPercentageChange float64 `json:"ltv-percentage-change"`
CustomersPercentageChange float64 `json:"customers-percentage-change"`
AspPercentageChange float64 `json:"asp-percentage-change"`
ArpaPercentageChange float64 `json:"arpa-percentage-change"`
ArrPercentageChange float64 `json:"arr-percentage-change"`
MrrPercentageChange float64 `json:"mrr-percentage-change"`
}
// MetricsResult represents results of Metrics API.
type MetricsResult struct {
Entries []*AllMetrics `json:"entries,omitempty"`
Summary *AllSummary `json:"summary"`
}
// Summary represents results of Metrics API.
type Summary struct {
Current float64 `json:"current"`
Previous float64 `json:"previous"`
PercentageChange float64 `json:"percentage-change"`
}
// Summary represents results of Metrics API.
type AllSummary struct {
CurrentCustomerChurnRate float64 `json:"current-customer-churn-rate"`
PreviousCustomerChurnRate float64 `json:"previous-customer-churn-rate"`
CustomerChurnRatePercentageChange float64 `json:"customer-churn-rate-percentage-change"`
CurrentMrrChurnRate float64 `json:"current-mrr-churn-rate"`
PreviousMrrChurnRate float64 `json:"previous-mrr-churn-rate"`
MrrChurnRatePercentageChange float64 `json:"mrr-churn-rate-percentage-change"`
CurrentLtv float64 `json:"current-ltv"`
PreviousLtv float64 `json:"previous-ltv"`
LtvPercentageChange float64 `json:"ltv-percentage-change"`
CurrentCustomers uint32 `json:"current-customers"`
PreviousCustomers uint32 `json:"previous-customers"`
CustomersPercentageChange float64 `json:"customers-percentage-change"`
CurrentAsp float64 `json:"current-asp"`
PreviousAsp float64 `json:"previous-asp"`
AspPercentageChange float64 `json:"asp-percentage-change"`
CurrentArpa float64 `json:"current-arpa"`
PreviousArpa float64 `json:"previous-arpa"`
ArpaPercentageChange float64 `json:"arpa-percentage-change"`
CurrentArr float64 `json:"current-arr"`
PreviousArr float64 `json:"previous-arr"`
ArrPercentageChange float64 `json:"arr-percentage-change"`
CurrentMrr float64 `json:"current-mrr"`
PreviousMrr float64 `json:"previous-mrr"`
MrrPercentageChange float64 `json:"mrr-percentage-change"`
}
// MRRMetrics represents results of Metrics API.
type MRRMetrics struct {
Date string `json:"date"`
MRR float64 `json:"mrr"`
MRRNewBusiness float64 `json:"mrr-new-business"`
MRRExpansion float64 `json:"mrr-expansion"`
MRRContraction float64 `json:"mrr-contraction"`
MRRChurn float64 `json:"mrr-churn"`
MRRReactivation float64 `json:"mrr-reactivation"`
PercentageChange float64 `json:"percentage-change"`
}
// MRRResult represents results of Metrics API.
type MRRResult struct {
Entries []*MRRMetrics `json:"entries,omitempty"`
Summary *Summary `json:"summary"`
}
// ARRMetrics represents results of Metrics API.
type ARRMetrics struct {
Date string `json:"date"`
ARR float64 `json:"arr"`
PercentageChange float64 `json:"percentage-change"`
}
// ARRResult represents results of Metrics API.
type ARRResult struct {
Entries []*ARRMetrics `json:"entries,omitempty"`
Summary *Summary `json:"summary"`
}
// ARPAMetrics represents results of Metrics API.
type ARPAMetrics struct {
Date string `json:"date"`
ARPA float64 `json:"arpa"`
PercentageChange float64 `json:"percentage-change"`
}
// ARPAResult represents results of Metrics API.
type ARPAResult struct {
Entries []*ARPAMetrics `json:"entries,omitempty"`
Summary *Summary `json:"summary"`
}
// ASPMetrics represents results of Metrics API.
type ASPMetrics struct {
Date string `json:"date"`
ASP float64 `json:"asp"`
PercentageChange float64 `json:"percentage-change"`
}
// ASPResult represents results of Metrics API.
type ASPResult struct {
Entries []*ASPMetrics `json:"entries,omitempty"`
Summary *Summary `json:"summary"`
}
// CustomerCountMetrics represents results of Metrics API.
type CustomerCountMetrics struct {
Date string `json:"date"`
Customers uint32 `json:"customers"`
PercentageChange float64 `json:"percentage-change"`
}
// CustomerCountResult represents results of Metrics API.
type CustomerCountResult struct {
Entries []*CustomerCountMetrics `json:"entries,omitempty"`
Summary *Summary `json:"summary"`
}
// CustomerChurnRateMetrics represents results of Metrics API.
type CustomerChurnRateMetrics struct {
Date string `json:"date"`
CustomerChurnRate float64 `json:"customer-churn-rate"`
PercentageChange float64 `json:"percentage-change"`
}
// CustomerChurnRateResult represents results of Metrics API.
type CustomerChurnRateResult struct {
Entries []*CustomerChurnRateMetrics `json:"entries,omitempty"`
Summary *Summary `json:"summary"`
}
// MRRChurnRateMetrics represents results of Metrics API.
type MRRChurnRateMetrics struct {
Date string `json:"date"`
MRRChurnRate float64 `json:"mrr-churn-rate"`
PercentageChange float64 `json:"percentage-change"`
}
// MRRChurnRateResult represents results of Metrics API.
type MRRChurnRateResult struct {
Entries []*MRRChurnRateMetrics `json:"entries,omitempty"`
Summary *Summary `json:"summary"`
}
// LTVMetrics represents results of Metrics API.
type LTVMetrics struct {
Date string `json:"date"`
LTV float64 `json:"ltv"`
PercentageChange float64 `json:"percentage-change"`
}
// LTVResult represents results of Metrics API.
type LTVResult struct {
Entries []*LTVMetrics `json:"entries,omitempty"`
Summary *Summary `json:"summary"`
}
const (
metricsEndpoint = "metrics/all"
metricsMRREndpoint = "metrics/mrr"
metricsARREndpoint = "metrics/arr"
metricsARPAEndpoint = "metrics/arpa"
metricsASPEndpoint = "metrics/asp"
metricsCustomerCountEndpoint = "metrics/customer-count"
metricsCustomerChurnRateEndpoint = "metrics/customer-churn-rate"
metricsMRRChurnRateEndpoint = "metrics/mrr-churn-rate"
metricsLTVEndpoint = "metrics/ltv"
)
// MetricsRetrieveAll retrieves all key metrics, for the specified time period.
//
// See https://dev.chartmogul.com/v1.0/reference#retrieve-all-key-metrics
func (api API) MetricsRetrieveAll(metricsFilter *MetricsFilter) (*MetricsResult, error) {
output := &MetricsResult{}
err := api.list(metricsEndpoint, output, *metricsFilter)
return output, err
}
// MetricsRetrieveMRR retrieves the MRR metrics, for the specified time period.
//
// See https://dev.chartmogul.com/v1.0/reference#retrieve-mrr
func (api API) MetricsRetrieveMRR(metricsFilter *MetricsFilter) (*MRRResult, error) {
output := &MRRResult{}
err := api.list(metricsMRREndpoint, output, *metricsFilter)
return output, err
}
// MetricsRetrieveARR retrieves the ARR metrics, for the specified time period.
//
// See https://dev.chartmogul.com/v1.0/reference#retrieve-arr
func (api API) MetricsRetrieveARR(metricsFilter *MetricsFilter) (*ARRResult, error) {
output := &ARRResult{}
err := api.list(metricsARREndpoint, output, *metricsFilter)
return output, err
}
// MetricsRetrieveARPA retrieves the ARPA metrics, for the specified time period.
//
// See https://dev.chartmogul.com/v1.0/reference#retrieve-arpa
func (api API) MetricsRetrieveARPA(metricsFilter *MetricsFilter) (*ARPAResult, error) {
output := &ARPAResult{}
err := api.list(metricsARPAEndpoint, output, *metricsFilter)
return output, err
}
// MetricsRetrieveASP retrieves the ASP metrics, for the specified time period.
//
// See https://dev.chartmogul.com/v1.0/reference#retrieve-asp
func (api API) MetricsRetrieveASP(metricsFilter *MetricsFilter) (*ASPResult, error) {
output := &ASPResult{}
err := api.list(metricsASPEndpoint, output, *metricsFilter)
return output, err
}
// MetricsRetrieveCustomerCount retrieves customer count, for the specified time period.
//
// See https://dev.chartmogul.com/v1.0/reference#retrieve-customer-count
func (api API) MetricsRetrieveCustomerCount(metricsFilter *MetricsFilter) (*CustomerCountResult, error) {
output := &CustomerCountResult{}
err := api.list(metricsCustomerCountEndpoint, output, *metricsFilter)
return output, err
}
// MetricsRetrieveCustomerChurnRate retrieves customer churn rate, for the specified time period.
//
// See https://dev.chartmogul.com/v1.0/reference#retrieve-customer-churn-rate
func (api API) MetricsRetrieveCustomerChurnRate(metricsFilter *MetricsFilter) (*CustomerChurnRateResult, error) {
output := &CustomerChurnRateResult{}
err := api.list(metricsCustomerChurnRateEndpoint, output, *metricsFilter)
return output, err
}
// MetricsRetrieveMRRChurnRate retrieves all key metrics, for the specified time period.
//
// See https://dev.chartmogul.com/v1.0/reference#retrieve-mrr-churn-rate
func (api API) MetricsRetrieveMRRChurnRate(metricsFilter *MetricsFilter) (*MRRChurnRateResult, error) {
output := &MRRChurnRateResult{}
err := api.list(metricsMRRChurnRateEndpoint, output, *metricsFilter)
return output, err
}
// MetricsRetrieveLTV retrieves LTV metrics, for the specified time period.
//
// See https://dev.chartmogul.com/v1.0/reference#retrieve-ltv
func (api API) MetricsRetrieveLTV(metricsFilter *MetricsFilter) (*LTVResult, error) {
output := <VResult{}
err := api.list(metricsLTVEndpoint, output, *metricsFilter)
return output, err
}