Tracking terms is done by declaring them and the service they are associated with. Such a declaration is achieved by editing JSON files in the declarations
folder.
Before adding new terms, open the declarations
folder and check if the service you want to track terms for is already declared. If a JSON file with the name of the service is already present, you can jump straight to declaring terms. Otherwise, keep reading!
Before declaring a service, you will need to choose the service name and service ID. The service ID will be the name of the JSON file in which the service will be declared. It is a normalised version of the service name.
The service name is exposed to end users. It should reflect as closely as possible the official service name, as referenced in the terms or “about” pages, so that it can be recognised easily and unambiguously.
eBay
.hi5
.LINE
.App Store
.туту.ру
(Cyrillic).抖音短视频
(Simplified Chinese characters).Booking.com
.historielærer.dk
.Ads
(by Facebook) → Facebook Ads
.Analytics
(by Google) → Google Analytics
.Firebase
(by Google) → Firebase
.App Store
(by Apple) → App Store
.If you have a hard time finding the service name, check out the practical guidelines to find the service name, and feel free to mention your uncertainties in the pull request! We will help you improve the service name if necessary 🙂
The service ID is exposed to developers. It should be easy to handle with scripts and other tools.
RTÉ
→ RTE
.historielærer.dk
→ historielaerer.dk
.туту.ру
→ tutu.ru
.抖音短视频
→ Douyin
.:
, /
, \
). These are replaced with a dash (-
).Booking.com
→ Booking.com
.Yahoo!
→ Yahoo!
.re:start
→ re-start
.we://
→ we---
.App Store
→ App Store
.DeviantArt
→ DeviantArt
.If you have a hard time defining the service ID, check out the practical guidelines to derive the ID from the service name, and feel free to mention your uncertainties in the pull request! We will help you improve the service ID if necessary 🙂
More details on the ID and naming constraints and recommendations can be found in the relevant decision record.
Once you have the service name and the service ID, create a JSON file in the declarations
folder named after the ID of the service you want to add, with the following structure:
{
"name": "<service name>",
"documents": {}
}
Within the documents
JSON object, you will now declare terms.
Terms are declared in a service declaration file, under the documents
property.
Most of the time, terms are written in only one source document (for example Facebook Terms of Service) but sometimes terms can be spread across multiple online source documents, and their combination constitutes the terms (for example Facebook Community Guidelines).
The way in which a source document is obtained is defined in a JSON object:
{
"fetch": "The URL where the document can be found",
"executeClientScripts": "A boolean to execute client-side JavaScript loaded by the document before accessing the content, in case the DOM modifications are needed to access the content; defaults to false (fetch HTML only)",
"filter": "An array of service specific filter function names",
"remove": "A CSS selector, a range selector or an array of selectors that target the insignificant parts of the document that has to be removed. Useful to remove parts that are inside the selected parts",
"select": "A CSS selector, a range selector or an array of selectors that target the meaningful parts of the document, excluding elements such as headers, footers and navigation"
}
fetch
and select
are mandatory.fetch
is mandatory.Let’s start by defining these keys!
fetch
This property should simply contain the URL at which the terms you want to track can be downloaded. HTML and PDF files are supported.
When terms coexist in different languages and jurisdictions, please refer to the scope of the collection to which you are contributing. This scope is usually defined in the README.
select
This property is not needed for PDF documents.
Most of the time, contractual documents are exposed as web pages, with a header, a footer, navigation menus, possibly ads… We aim at tracking only the significant parts of the document. In order to achieve that, the select
property allows to extract only those parts in the process of converting from snapshot to version.
The select
value can be either a CSS selector, a range selector or an array of those.
CSS selectors should be provided as a string. See the specification for how to write CSS selectors.
For example, the following selector will select the content in the
<main>
tag of the HTML document:"select": "main"
A range selector is defined with a start and an end CSS selector. It is also necessary to define if the range starts before or after the element targeted by the start CSS selector and to define if it ends before or after the element targeted by the end CSS selector.
To that end, a range selector is a JSON object containing two keys out of the four that are available: startBefore
, startAfter
, endBefore
and endAfter
.
{
"start[Before|After]": "<CSS selector>",
"end[Before|After]": "<CSS selector>"
}
For example, the following selector will select the content between the element targeted by the CSS selector
#privacy-eea
, including it, and the element targeted by the CSS selectorfooter
, excluding it:{ "startBefore": "#privacy-eea", "endBefore": "footer" }
remove
This property is optional.
Beyond selecting a subset of a web page, some documents will have non-significant parts in the middle of otherwise significant parts. For example, they can have “go to top” links or banner ads. These can be removed by listing CSS selectors, range selectors or an array of them under the remove
property.
Let’s assume a web page contains the following content:
<main>
<div class="filter-holder">
<select class="filter-options">
<option value="https://www.example.com/policies/user-agreement" selected>User Agreement</option>
<option value="https://www.example.com/policies/privacy-policy">Privacy Policy</option>
<option value="https://www.example.com/policies/content-policy">Content Policy</option>
<option value="https://www.example.com/policies/broadcasting-content-policy">Broadcasting Content Policy</option>
</select>
</div>
<h1>User Agreement</h1>
<div>…terms…</div>
</main>
If only main
is used in select
, the following version will be extracted:
User Agreement Privacy Policy Content Policy Broadcasting Content Policy Moderator Guidelines Transparency Report 2017 Transparency Report 2018 Guidelines for Law Enforcement Transparency Report 2019
User Agreement
==============
…terms…
Whereas we want instead:
User Agreement
==============
…terms…
This result can be obtained with the following declaration:
{
"fetch": "https://example.com/user-agreement",
"select": "main",
"remove": ".filter-holder"
}
{
"fetch": "https://support.google.com/adsense/answer/48182",
"select": ".article-container",
"remove": ".print-button, .go-to-top"
}
{
"fetch": "https://www.wechat.com/en/service_terms.html",
"select": "#agreement",
"remove": {
"startBefore": "#wechat-terms-of-service-usa-specific-terms-",
"endBefore": "#wechat-terms-of-service-european-union-specific-terms-"
}
}
{
"fetch": "https://fr-fr.facebook.com/legal/terms/plain_text_terms",
"select": "div[role=main]",
"remove": [
{
"startBefore": "[role=\"separator\"]",
"endAfter": "body"
},
"[style=\"display:none\"]"
]
}
executeClientScripts
This property is optional.
In some cases, the content of the document is only loaded (or is modified dynamically) by client scripts.
When set to true
, this boolean property loads the page in a headless browser to load all assets and execute client scripts before trying to get the document contents.
Since the performance cost of this approach is high, it is set to false
by default, relying on the HTML content only.
filter
This property is optional.
Finally, some documents will need more complex filtering beyond simple element selection and removal, for example to remove noise (changes in textual content that are not meaningful to the terms of services). Such filters are declared as JavaScript functions that modify the downloaded web page through the DOM API.
Filters take the document DOM and the terms declaration as parameters and are:
Filters are loaded automatically from files named after the service they operate on. For example, filters for the Meetup service, which is declared in declarations/Meetup.json
, are loaded from declarations/Meetup.filters.js
.
The generic function signature for a filter is:
export [async] function filterName(document, documentDeclaration)
Each filter is exposed as a named function export that takes a document
parameter and behaves like the document
object in a browser DOM. These functions can be async
, but they will still run sequentially. The whole document declaration is passed as second parameter.
The
document
parameter is actually a JSDOM document instance.
You can learn more about usual noise and ways to handle it in the guidelines.
Let’s assume a service adds a unique clickId
parameter in the query string of all link destinations. These parameters change on each page load, leading to recording noise in versions. Since links should still be recorded, it is not appropriate to use remove
to remove the links entirely. Instead, a filter will manipulate the links destinations to remove the always-changing parameter. Concretely, the goal is to apply the following filter:
- Read the <a href="https://example.com/example-page?clickId=349A2033B&lang=en">list of our affiliates</a>.
+ Read the <a href="https://example.com/example-page?lang=en">list of our affiliates</a>.
The code below implements this filter:
function removeTrackingIdsQueryParam(document) {
const QUERY_PARAM_TO_REMOVE = 'clickId';
document.querySelectorAll('a').forEach(link => { // iterate over every link in the page
const url = new URL(link.getAttribute('href'), document.location); // URL is part of the DOM API, see https://developer.mozilla.org/en-US/docs/Web/API/URL
const params = new URLSearchParams(url.search); // URLSearchParams is part of the DOM API, see https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams
params.delete(QUERY_PARAM_TO_REMOVE); // we use the DOM API instead of RegExp because we can't know in advance in which order parameters will be written
url.search = params.toString(); // store the query string without the parameter
link.setAttribute('href', url.toString()); // write the destination URL without the parameter
});
}
The second parameter can be used to access the defined document URL or selector inside the filter.
Let’s assume a service stores some of its legally-binding terms in images. To track these changes properly, images should be stored as part of the terms. By default, images are not stored since they significantly increase the document size. The filter below will store images inline in the terms, encoded in a data URL. In order to download the images for conversion, the base URL of the web page is needed to resolve relative links. This information is obtained from the declaration.
import fetch from 'isomorphic-fetch';
export async function convertImagesToBase64(document, documentDeclaration) {
const { fetch: baseUrl, select: selector } = documentDeclaration;
const images = Array.from(document.querySelectorAll(`${selector} img`));
return Promise.all(images.map(async ({ src }, index) => {
const imageAbsoluteUrl = new URL(src, baseUrl).href;
const response = await fetch(imageAbsoluteUrl);
const mimeType = response.headers.get('content-type');
const content = await response.arrayBuffer();
const base64Image = btoa(String.fromCharCode(...new Uint8Array(content)));
images[index].src = `data:${mimeType};base64,${base64Image}`;
}));
}
In the case where terms are extracted from one single source document, they are declared by simply declaring that source document:
…
"documents": {
"<terms type>": {
"fetch": "…",
"executeClientScripts": "…",
"filter": "…",
"remove": "…",
"select": "…"
}
}
…
When the terms are spread across multiple source documents, they should be declared by declaring their combination:
…
"documents": {
"<terms type>": {
"combine": [
{
"fetch": "…",
"executeClientScripts": "…",
"filter": "…",
"remove": "…",
"select": "…"
},
{
"fetch": "…",
"executeClientScripts": "…",
"filter": "…",
"remove": "…",
"select": "…"
}
]
}
}
…
If some parts of the source documents are repeated, they can be factorised. For example, it is common for the structure of HTML pages to be similar from page to page, so select
, remove
and filter
would be the same. These elements can be shared instead of being duplicated:
…
"documents": {
"<terms type>":
"executeClientScripts": "…",
"filter": "…",
"remove": "…",
"select": "…",
"combine": [
{
"fetch": "…",
},
{
"fetch": "…",
}
]
}
…
Great, your terms declaration is now almost complete! You simply need to write it under the appropriate terms type in the documents
JSON object within the service declaration.
In order to distinguish between the many terms that can be associated with a service and enable cross-services comparison of similar terms, we maintain a unique list of terms types in a dedicated repository.
Please note, the terms type may differ from the exact name provided by the service, but it should align with the underlying commitment. For example, some providers might call “Terms and Conditions” or “Terms of Use” what some others call “Terms of Service”.
If the terms you want to add don’t match an existing type, you can suggest a new one.
You can test the declarations you created or changed by running the following command:
npm test [$service_id [$another_service_id …]]
Since this operation fetches documents and could be long, you can also validate the declaration structure only:
npm run test:schema [$service_id [$another_service_id …]]
In order to ensure consistency across declarations, all declarations files have to be formatted homogeneously.
In order to achieve this, you can use the following command:
npm run lint [$service_id [$another_service_id …]]
All parts of a terms declaration (web location, selection, noise removal, distribution across multiple documents…) can change over time. The process of updating these elements to enable continued tracking is called maintenance. Without it, terms can become:
Open Terms Archive needs to keep track of this changes in order to regenerate versions history from snapshots history.
To keep track of services declarations and filters changes, Open Terms Archive offers a versioning system. It is optional and should be added only when needed. It works by creating history files for terms declarations and filters, where each entry should be a previous valid declaration or filter function and should have an expiry date.
Both for terms and filters history, the expiration date is declared in a property validUntil
. It should be the authored date and time of the last snapshot commit for which the declaration is still valid.
Terms declarations history files and filters history files can both evolve on their own. Having one does not imply to create the other.
The current (latest) valid declaration has no date and should not appear in the history object: it stays in its own file, just like if there was no history at all.
Declarations history are stored in a history JSON file with the following name declarations/$service_id.history.json
.
The terms history contains an object with terms types as properties. Each terms type property is an array of history entries. Each entry has the same format as a normal terms declaration, except there is the mandatory extra property validUntil
.
{
…
"<terms type>": [
{
"fetch": "The URL where the document can be found",
"executeClientScripts": "A boolean to execute client-side JavaScript loaded by the document before accessing the content, in case the DOM modifications are needed to access the content; defaults to false (fetch HTML only)",
"filter": "An array of service specific filter function names",
"remove": "A CSS selector, a range selector or an array of selectors that target the insignificant parts of the document that has to be removed. Useful to remove parts that are inside the selected parts",
"select": "A CSS selector, a range selector or an array of selectors that target the meaningful parts of the document, excluding elements such as headers, footers and navigation",
"validUntil": "The inclusive expiration date in ISO format"
}
]
…
}
For example, to add a history entry for the Terms of Service
of the service ASKfm
, create the file declarations/ASKfm.history.json
with the following contents:
{
"Terms of Service": [
{
"fetch": "https://ask.fm/docs/terms_of_use/?lang=en",
"select": "body",
"filter": ["add"],
"validUntil": "2020-10-29T21:30:00.000Z"
}
]
}
Filters history is declared in a filters history declaration JavaScript file with the following name: declarations/$service_id.filters.history.js
.
For each filter, a variable named like the filter must be exported. This variable should contain an array of filter history entries. Each entry is an object with the expiration date, as validUntil
property, and the valid function for this date, under the filter
property. Both properties are mandatory.
export const <filterName> = [
{
validUntil: "The inclusive expiration date in ISO format",
filter: function() { /* body valid until the expiration of the `validUntil` date */ }
}
];
For example, to add a history entry for the removeSharesButton
filter of the service ASKfm
, create the file declarations/ASKfm.filters.history.js
with the following content:
export const removeSharesButton = [
{
validUntil: '2020-08-22T11:30:21.000Z',
filter: async (document) => {
document.querySelectorAll('.shares').forEach((element) => element.remove());
},
},
];
If the service provider stops offering a service, the associated terms will become unavailable. To mark that service termination in Open Terms Archive and ensure tracking tentatives are stopped, while maintaining the possibility to explore the history:
<terms type>
entries from the documents
key in the declaration:{
"name": "<service name>",
"documents": {}
}
The consensus is to consider that a service provider renaming a service (for example, Twitter
to X
) is akin to terminating the previous service and opening a new one. Therefore, to apply a service renaming, open a pull request that both terminates the previous service and adds a new service declaration with the new service name. You can reuse the documents
part of the original declaration, but should double-check that the selectors and URLs still match, as a service rename is most often accompanied by a new page layout, a new domain name, and sometimes entirely new terms.