Commit 4b63e100 authored by Georg Fritzsche's avatar Georg Fritzsche Committed by Alessio Placitelli
Browse files

Add documentation for counters to Glean

parent b7bc815c
......@@ -19,6 +19,8 @@ by glean.
There are different metrics to choose from, depending on what you want to achieve:
* [Events](#Events): These allow recording of e.g. individual occurences of user actions, say every time a view was open and from where.
* [Counters](#Counters): Used to count how often something happens, say how often a certain button was pressed.
## Events
......@@ -59,3 +61,38 @@ assertEquals(2, snapshot.size)
val first = snapshot.single()
assertEquals("login_opened", first.name)
```
## Counters
Used to count how often something happens, say how often a certain button was pressed.
A counter always starts from `0`. Each time you record to a counter, its value is incremented.
Say you're adding a new counter for how often the refresh button is pressed. First you need to add an entry for the counter to the `metrics.yaml` file:
```YAML
controls:
refresh_pressed:
type: counter
description: >
Counts how often the refresh button is pressed.
...
```
Now you can use the event from the applications code:
```Kotlin
import org.mozilla.yourApplication.GleanMetrics.Controls
// ...
Controls.refreshPressed.add() // Adds 1 to the counter.
Controls.refreshPressed.add(5) // Adds 5 to the counter.
```
There are test APIs available too:
```Kotlin
import org.mozilla.yourApplication.GleanMetrics.Controls
// Was anything recorded?
assertTrue(Controls.refreshPressed.testHasValue())
// Does the counter have the expected value?
assertEquals(6, Controls.refreshPressed.testGetValue())
```
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment