new countlyMetric()
- Description:
Common metric object, all metric models inherit from it and should have these methods
- Source:
Members
(static) countlyMetric.fetchValue
- Description:
Fetching method to modify segment values, like changing name or grouping them
- Source:
Fetching method to modify segment values, like changing name or grouping them
Methods
(static) countlyMetric.clearObject(obj) → {object}
- Description:
Prefill all expected metrics as u, t, n with 0 if they don't exist, to avoid null values in the result, which won't work when drawing graphs
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
obj |
object | oject to prefill with values if they don't exist |
Returns:
prefilled object
- Type
- object
(static) countlyMetric.extendDb(data)
- Description:
Extend current data for model with some additional information about latest period (like data from action=refresh request)
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
data |
object | set new data to be used by model |
(static) countlyMetric.getBars(segment, maxItems, metric) → {array}
- Description:
Get bar data for metric
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
segment |
string | name of the segment to get data for, or use date, for higher level metric without segments |
maxItems |
number | amount of top items to return, if -1 return all |
metric |
string | name of the to use for ordering and returning |
Returns:
object to use when displaying bars as [{"name":"English","percent":44},{"name":"Italian","percent":29},{"name":"German","percent":27}]
- Type
- array
(static) countlyMetric.getData(segment, clean, join) → {object}
- Description:
Get data after initialize finished and data was retrieved
- Source:
Examples
Example output of separate data for 2 pie charts
{"chartData":[
{"langs":"English","t":124,"u":112,"n":50},
{"langs":"Italian","t":83,"u":74,"n":30},
{"langs":"German","t":72,"u":67,"n":26},
{"langs":"Japanese","t":62,"u":61,"n":19},
{"langs":"French","t":66,"u":60,"n":28},
{"langs":"Korean","t":64,"u":58,"n":26}
],
"chart_t":{
"dp":[
{"data":[[0,124]],"label":"English"},
{"data":[[0,83]],"label":"Italian"},
{"data":[[0,72]],"label":"German"},
{"data":[[0,62]],"label":"Japanese"},
{"data":[[0,66]],"label":"French"},
{"data":[[0,64]],"label":"Korean"}
]
},
"chart_n":{
"dp":[
{"data":[[0,50]],"label":"English"},
{"data":[[0,30]],"label":"Italian"},
{"data":[[0,26]],"label":"German"},
{"data":[[0,19]],"label":"Japanese"},
{"data":[[0,28]],"label":"French"},
{"data":[[0,26]],"label":"Korean"}
]
}}
Example output of joined data for 1 bar chart
{"chartData":[
{"langs":"English","t":124,"u":112,"n":50},
{"langs":"Italian","t":83,"u":74,"n":30},
{"langs":"German","t":72,"u":67,"n":26},
{"langs":"Japanese","t":62,"u":61,"n":19},
{"langs":"French","t":66,"u":60,"n":28},
{"langs":"Korean","t":64,"u":58,"n":26}
],
"chartDP":{
"dp":[
{"data":[[-1,null],[0,124],[1,83],[2,72],[3,62],[4,66],[5,64],[6,null]],"label":"t"},
{"data":[[-1,null],[0,50],[1,30],[2,26],[3,19],[4,28],[5,26],[6,null]],"label":"n"}
],
"ticks":[
[-1,""], //used for padding for bars
[6,""], //used for padding for bars
[0,"English"],
[1,"Italian"],
[2,"German"],
[3,"Japanese"],
[4,"French"],
[5,"Korean"]
]
}}
<caption>Example output of higher level data without segments</caption>
Parameters:
| Name | Type | Description |
|---|---|---|
segment |
string | name of the segment to get data for, or will try to get higher level data, like from users collection, without segments |
clean |
boolean | should retrieve clean data or preprocessed by fetchValue function |
join |
boolean | join none unique metrics into single graph, for example to dispaly in bars on the same graph and not 2 separate pie charts |
Returns:
chartData
- Type
- object
(static) countlyMetric.getDb() → {object}
- Description:
Get current data, if some view or model requires access to raw data
- Source:
Returns:
raw data returned from server either in standard metric model or preprocessed data, based on what model uses
- Type
- object
(static) countlyMetric.getMeta(metric) → {array}
- Description:
Get array of unique segment values available for provided segment data
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
metric |
string | name of the segment/metric to get meta for, by default will use default _name provided on initialization |
Returns:
array of unique segment values
- Type
- array
(static) countlyMetric.getMetrics() → {array}
- Description:
Get array of metric names, for this data
- Source:
Returns:
uniques - array of strings with metrics for current data, for example: ["t", "u", "n"]
- Type
- array
(static) countlyMetric.getNumber(metric, isSparklineNotRequired) → {array}
- Description:
Get value of single metric with changes and sparkle lines
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
metric |
string | metric name to return value for |
isSparklineNotRequired |
boolean | boolean to identify if sparkLines object is required in response |
Returns:
object to use when displaying number {value: 123, change: 12, sparkline: [1,2,3,4,5,6,7]}
- Type
- array
(static) countlyMetric.getPeriod() → {module:api/lib/countly.common.periodObj}
- Description:
Get the current period Object for the model
- Source:
Returns:
period object
(static) countlyMetric.getRangeData(metric, meta, explain) → {object}
- Description:
Get range data which is usually stored in some time ranges/buckets. As example is loyalty, session duration and session frequency
- Source:
Example
Example output
//call
//countlyMetric.getRangeData("f", "f-ranges", countlySession.explainFrequencyRange);
//returns
{"chartData":[
{"f":"First session","t":271,"percent":"<div class='percent-bar' style='width:171px;'></div>85.5%"},
{"f":"2 days","t":46,"percent":"<div class='percent-bar' style='width:29px;'></div>14.5%"}
],
"chartDP":{
"dp":[
{"data":[[-1,null],[0,271],[1,46],[2,null]]}
],
"ticks":[
[-1,""],
[2,""],
[0,"First session"],
[1,"2 days"]
]
}
}
Parameters:
| Name | Type | Description |
|---|---|---|
metric |
string | name of the property in the model to fetch |
meta |
string | name of the meta where property's ranges are stored |
explain |
string | function that receives index of the bucket and returns bucket name |
Returns:
with range data
- Type
- object
(static) countlyMetric.getStackedBarData(segment, maxItems, metric, displayType) → {array}
- Description:
Get timeline data for higher metrics with segments
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
segment |
string | name of the segment to get data for, or use date, for higher level metric without segments |
maxItems |
number | amount of top items to return, if -1 return all |
metric |
string | name of the to use for ordering and returning |
displayType |
string | type of data to return, "number" or "percentage" |
Returns:
object to use when displaying bars as [{"name":"English","percent":44},{"name":"Italian","percent":29},{"name":"German","percent":27}]
- Type
- array
(static) countlyMetric.getTableData(segment, maxItems) → {array}
- Description:
Get data for dynamic tables
- Source:
Example
{
cols: [ segment1, count, sum, duration ]
rows: [
[segmentValue1, 15, 10, 10],
[segmentValue2, 14, 10, 10],
[segmentValue3, 12, 10, 10]
]
}
Parameters:
| Name | Type | Description |
|---|---|---|
segment |
string | name of the segment to get data for, by default will use default _name provided on initialization |
maxItems |
number | amount of top items to return |
Returns:
object to use when displaying table
- Type
- array
(static) countlyMetric.getTimelineData() → {array}
- Description:
Get timeline data for higher metrics without segments
- Source:
Returns:
object to use when displaying number {value: 123, change: 12, sparkline: [1,2,3,4,5,6,7]}
- Type
- array
(static) countlyMetric.getTotalUsersObj(prev) → {object}
- Description:
Get total user object for this metric to use for unique user correction
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
prev |
boolean | get correction data for previous period |
Returns:
object with total user data from module:api/parts/data/fetch.getTotalUsersObj
- Type
- object
(static) countlyMetric.getUniqueMetrics() → {array}
- Description:
Get array of unique metric names, for which user estimation should be applied
- Source:
Returns:
uniques - array of strings with unique metrics for current data, for example: ["u"]
- Type
- array
(static) countlyMetric.reset()
- Description:
Reset/delete all retrieved metric data, like when changing app or selected time period
- Source:
(static) countlyMetric.setDb(db)
- Description:
Set current data for model, if you need to provide data for model from another resource (as loaded in different model)
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
db |
object | set new data to be used by model |
(static) countlyMetric.setMetrics(metrics)
- Description:
Sets array of metric names that is used by this model
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
metrics |
array | array of strings with metric names for current data, return will be sorted by first metric, default: ["t", "u", "n"] |
(static) countlyMetric.setPeriod(period)
- Description:
Set period object for the model to use, for overriding calls to common methods
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
period |
module:api/lib/countly.common.periodObj | set period Object used by the model |
(static) countlyMetric.setTotalUsersObj(totalUsersObj, prevTotalUserObj)
- Description:
Set total user object for this metric to use for unique user correction
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
totalUsersObj |
object | object with total user data from |
prevTotalUserObj |
object | object with total user data from |
(static) countlyMetric.setUniqueMetrics(uniques)
- Description:
Sets array of metric names that are unique and estimation should be applied to them
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
uniques |
array | array of strings with unique metrics for current data, default: ["u"] |