Text

Records a single long Unicode text, used when the limits on String are too low.

Important

This type should only be used in special cases when other metrics don't fit. See limitations below.
Reach out to the Glean team before using this.

Recording API

set

Sets a text metric to a specific value.

import * as article from "./path/to/generated/files/article.js";

article.content.set(extractedText);


Limits

• Text metrics can only be sent in custom pings.
• Text metrics are always of data collection category 3 (web_activity) or category 4 (highly_sensitive).
• Only ping and application lifetimes are allowed.
• Fixed maximum text length: 200 kilobytes. Longer text is truncated. This is measured in the number of bytes when the string is encoded in UTF-8.

Testing API

testGetValue

Gets the recorded value for a given text metric.

import * as article from "./path/to/generated/files/article.js";

assert.strictEqual("some content", await article.content.testGetValue());


testGetNumRecordedErrors

Gets number of errors recorded for a given text metric.

import * as article from "./path/to/generated/files/article.js";
import { ErrorType } from "@mozilla/glean/<platform>";

assert.strictEqual(
0,
await article.content.testGetNumRecordedErrors(ErrorType.InvalidValue)
);


Metric parameters

Example text metric definition:

article:
content:
type: text
send_in_pings:
- research
data_sensitivity:
- web_activity
description: >
The plaintext content of the displayed article.
bugs:
- https://bugzilla.mozilla.org/000000
data_reviews:
- https://bugzilla.mozilla.org/show_bug.cgi?id=000000#c3