countlyMetric

countlyMetric

new countlyMetric()

Source:

Common metric object, all metric models inherit from it and should have these methods

Members

(static) countlyMetric.fetchValue

Source:

Fetching method to modify segment values, like changing name or grouping them

Methods

(static) countlyMetric.clearObject(obj) → {object}

Source:

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

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)

Source:

Extend current data for model with some additional information about latest period (like data from action=refresh request)

Parameters:
Name Type Description
data object

set new data to be used by model

(static) countlyMetric.getBars(segment, maxItems, metric) → {array}

Source:

Get bar data for metric

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

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}

Source:

Get data after initialize finished and data was retrieved

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}

Source:

Get current data, if some view or model requires access to raw data

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}

Source:

Get array of unique segment values available for provided segment data

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}

Source:

Get array of metric names, for this data

Returns:

uniques - array of strings with metrics for current data, for example: ["t", "u", "n"]

Type
array

(static) countlyMetric.getNumber(metric) → {array}

Source:

Get value of single metric with changes and sparkle lines

Parameters:
Name Type Description
metric string

metric name to return value for

Returns:

object to use when displaying number {value: 123, change: 12, sparkline: [1,2,3,4,5,6,7]}

Type
array

(static) countlyMetric.getRangeData(metric, meta, explain) → {object}

Source:

Get range data which is usually stored in some time ranges/buckets. As example is loyalty, session duration and session frequency

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.getTableData(segment, maxItems) → {array}

Source:

Get data for dynamic tables

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}

Source:

Get timeline data for higher metrics without segments

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}

Source:

Get total user object for this metric to use for unique user correction

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}

Source:

Get array of unique metric names, for which user estimation should be applied

Returns:

uniques - array of strings with unique metrics for current data, for example: ["u"]

Type
array

(static) countlyMetric.reset()

Source:

Reset/delete all retrieved metric data, like when changing app or selected time period

(static) countlyMetric.setDb(db)

Source:

Set current data for model, if you need to provide data for model from another resource (as loaded in different model)

Parameters:
Name Type Description
db object

set new data to be used by model

(static) countlyMetric.setMetrics(metrics)

Source:

Sets array of metric names that is used by this model

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.setTotalUsersObj(totalUsersObj, prevTotalUserObj)

Source:

Set total user object for this metric to use for unique user correction

Parameters:
Name Type Description
totalUsersObj object

object with total user data from module:api/parts/data/fetch.getTotalUsersObj

prevTotalUserObj object

object with total user data from module:api/parts/data/fetch.getTotalUsersObj for previous period

(static) countlyMetric.setUniqueMetrics(uniques)

Source:

Sets array of metric names that are unique and estimation should be applied to them

Parameters:
Name Type Description
uniques array

array of strings with unique metrics for current data, default: ["u"]