countlyMetric

countlyMetric

Source:

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

Members

(static) callback

Source:

Callback that each metric model can define, to be called when data is loaded or refreshed

Example
countlyDeviceDetails.callback = function(isRefresh, data){
   if(isRefresh){
       countlyAppVersion.refresh(data);
   }
   else{
       countlyAppVersion.initialize();
   }
};

(static) fetchValue

Source:

Function to get value, modifying it before processing if needed.

Methods

(static) clearObject(obj) → {object}

Source:

Prefill all expected properties as u, t, n with 0, to avoid null values in the result, if they don't exist, 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) 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) getBars(metric_pd) → {array}

Source:

Get bar data for metric

Parameters:
Name Type Description
metric_pd string

name of the segment/metric to get data for, by default will use default _name provided on initialization

Returns:

object to use when displaying bars as [{"name":"English","percent":44},{"name":"Italian","percent":29},{"name":"German","percent":27}]

Type
array

(static) getBarsWPercentageOfTotal(metric_pd) → {array}

Source:

Get bar data for metric with percentages of total

Parameters:
Name Type Description
metric_pd string

name of the segment/metric to get data for, by default will use default _name provided on initialization

Returns:

object to use when displaying bars as [{"name":"English","percent":44},{"name":"Italian","percent":29},{"name":"German","percent":27}]

Type
array

(static) getData(clean, join, metric1, estOverrideMetric) → {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}
],
"chartDPTotal":{
   "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"}
   ]
},
"chartDPNew":{
   "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":"Total Sessions"},
       {"data":[[-1,null],[0,50],[1,30],[2,26],[3,19],[4,28],[5,26],[6,null]],"label":"New Users"}
   ],
  "ticks":[
       [-1,""], //used for padding for bars
       [23,""], //used for padding for bars
       [0,"English"],
       [1,"Italian"],
       [2,"German"],
       [3,"Japanese"],
       [4,"French"],
       [5,"Korean"]
   ]
}}
Parameters:
Name Type Description
clean boolean

should retrieve clean data or preprocessed by fetchValue function

join boolean

join new and total users into single graph, for example to dispaly in bars on the same graph and not 2 separate pie charts

metric1 string

name of the segment/metric to get data for, by default will use default _name provided on initialization

estOverrideMetric string

name of the total users estimation override, by default will use default _estOverrideMetric provided on initialization

Returns:

chartData

Type
object

(static) 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) getMeta(metric1) → {array}

Source:

Get array of unique segments available for metric data

Parameters:
Name Type Description
metric1 string

name of the segment/metric to get meta for, by default will use default _name provided on initialization

Returns:

array of unique metric values

Type
array

(static) getOSSegmentedData(os, clean, metric_pd, estOverrideMetric) → {object}

Source:

If this metric's data should be segmented by OS (which means be prefixed by first os letter on server side), you can get OS segmented data

Example

Example output

//call
//countlyMetric.getOSSegmentedData("wp")
//data for Windows Phone segment
{"chartData":[
   {"density":"2.0","t":18,"u":18,"n":9},
   {"density":"3.4","t":13,"u":12,"n":5},
   {"density":"1.2","t":11,"u":10,"n":5},
   {"density":"3.5","t":10,"u":10,"n":4},
   {"density":"3.3","t":9,"u":9,"n":3}
],
"chartDP":{
   "dp":[
       {"data":[[0,53]],"label":"2.0"},
       {"data":[[0,49]],"label":"3.4"},
       {"data":[[0,46]],"label":"1.2"},
       {"data":[[0,36]],"label":"3.5"},
       {"data":[[0,32]],"label":"3.3"}
   ]
},
//list of all os segments
"os":[
  {"name":"Windows Phone","class":"windows phone"},
   {"name":"Android","class":"android"},
   {"name":"iOS","class":"ios"}
]}
Parameters:
Name Type Description
os string

os name for which to get segmented metrics data

clean boolean

should retrieve clean data or preprocessed by fetchValue function

metric_pd string

name of the segment/metric to get data for, by default will use default _name provided on initialization

estOverrideMetric string

name of the total users estimation override, by default will use default _estOverrideMetric provided on initialization

Returns:

os segmented metric object

Type
object

(static) getRangeData(metric_pd, meta, explain, order) → {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_pd 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

order array

list of keys ordered in preferred order(to return in same order)

Returns:

data

Type
object

(static) initialize(processedopt) → {jquery_promise}

Source:

Initialize metric model to fetch initial data from server

Example
beforeRender: function() {
   return $.when(countlyMetric.initialize()).then(function () {});
}
Parameters:
Name Type Attributes Description
processed boolean <optional>

if true will fetch processed data, will fetch raw data by default

Returns:

jquery promise to wait while data is loaded

Type
jquery_promise

(static) refresh() → {jquery_promise}

Source:

Refresh metric model by fetching data only for the latest time bucket using action=refresh on server. Currently does not fetch data for processed data loaded on initialization

Example
$.when(countlyMetric.refresh()).then(function () {
   //data loaded, do something
});
Returns:

jquery promise to wait while data is loaded

Type
jquery_promise

(static) reset()

Source:

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

(static) 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