-
Notifications
You must be signed in to change notification settings - Fork 22.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Editorial review: Topics API docs (#30107)
* Add Topic API docs * Update files/en-us/web/api/fetch/index.md Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Making fixes for samdutton review comments * prettier fix * Making fixes for samdutton comments * fix ad tech example URL issue * Rewrite explanatory text for Topics API usage * improve Sec-Browsing-Topics header description and ref page * minor tweaks to browsingTopics() wording * Further update description of API usage, based on samdutton comments * Fixes for latest samdutton review * remove specification macros for features that have no spec_url in BCD * final few bits of cleanup * Update history entry description with feedback from Yao * Add privacy sandbox enrollment information, restructure privacy section to fit it * Restructure and clarify topics api content, answer review comments * missing paren * Other small tweaks * Update non-standard and spec opposition information * fix linting errors * Further updates to topics API description * Update standards positions information * more changes to increase accuracy of content * Update files/en-us/web/api/topics_api/index.md Co-authored-by: wbamberg <will@bootbonnet.ca> * Update files/en-us/web/api/topics_api/index.md Co-authored-by: wbamberg <will@bootbonnet.ca> * Update files/en-us/web/api/topics_api/index.md Co-authored-by: wbamberg <will@bootbonnet.ca> * Update files/en-us/web/api/document/browsingtopics/index.md Co-authored-by: wbamberg <will@bootbonnet.ca> * Fixes for wbamberg review comments --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: wbamberg <will@bootbonnet.ca>
- Loading branch information
1 parent
7415a0b
commit b8282f9
Showing
26 changed files
with
797 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
--- | ||
title: "Document: browsingTopics() method" | ||
short-title: browsingTopics() | ||
slug: Web/API/Document/browsingTopics | ||
page-type: web-api-instance-method | ||
status: | ||
- non-standard | ||
browser-compat: api.Document.browsingTopics | ||
--- | ||
|
||
{{APIRef("Topics API")}} | ||
|
||
> **Warning:** This feature is currently opposed by two browser vendors. See the [Standards positions](/en-US/docs/Web/API/Topics_API#standards_positions) section below for details of opposition. | ||
> **Note:** An [Enrollment process](/en-US/docs/Web/Privacy/Privacy_sandbox/Enrollment) is required to use this feature in your applications. | ||
The `browsingTopics()` method of the {{domxref("Document")}} interface returns a promise that fulfills with an array of objects representing the selected topics for the current user, which can then be returned to the ad tech platform in a subsequent fetch request. It also triggers the browser to observe the topics inferred from the calling site's URL (i.e. the site where the ad tech `<iframe>` is embedded). | ||
|
||
See [Using the Topics API](/en-US/docs/Web/API/Topics_API/Using) for more details. | ||
|
||
> **Note:** `browsingTopics()` does not rely on HTTP headers to send topics and mark topics as observed like the other [Topics API enabling features](/en-US/docs/Web/API/Topics_API/Using#what_api_features_enable_the_topics_api), but it is somewhat less performant. You are advised to use one of the HTTP header-using features, falling back to `browsingTopics()` only in situations where the headers cannot be modified. | ||
## Syntax | ||
|
||
```js-nolint | ||
browsingTopics() | ||
browsingTopics(options) | ||
``` | ||
|
||
### Parameters | ||
|
||
- `options` {{optional_inline}} | ||
- : An options object, which can contain the following properties: | ||
- `skipObservation` | ||
- : A boolean value that, if set to `true`, causes the browser to _not_ observe topics when `browsingTopics()` is invoked. The default is `false`, which causes topics to be observed. | ||
|
||
### Return value | ||
|
||
A {{jsxref("Promise")}} that fulfills with an array of up to three objects representing the current user's selected topics for the last three epochs. Each object contains the following properties: | ||
|
||
- `configVersion` | ||
- : A string identifying the algorithm (other than the model part) used to calculate the topic. | ||
- `modelVersion` | ||
- : A string representing the model used to classify a string (such as a web page's hostname) into topic IDs. | ||
- `taxonomyVersion` | ||
- : A string representing the taxonomy version used. | ||
- `topic` | ||
- : A number representing the ID of the topic, which can be used by the browser to retrieve the topic from the taxonomy (see an example [taxonomy of interests](https://github.com/patcg-individual-drafts/topics/blob/main/taxonomy_v1.md)). | ||
- `version` | ||
- : The `configVersion`, `modelVersion`, and `taxonomyVersion`, concatenated with colons (`:`) between each. | ||
|
||
The exact property values may vary by browser implementation. An example object from Chrome might look as follows: | ||
|
||
```js | ||
{ | ||
configVersion: "chrome.1", | ||
modelVersion: "1", | ||
taxonomyVersion: "1", | ||
topic: 43, | ||
version: "chrome.1:1:1" | ||
} | ||
``` | ||
|
||
### Exceptions | ||
|
||
- `NotAllowedError` {{domxref("DOMException")}} | ||
- : Thrown if: | ||
- Usage of the [Topics API](/en-US/docs/Web/API/Topics_API) is disallowed by a {{httpheader('Permissions-Policy/browsing-topics','browsing-topics')}} [Permissions Policy](/en-US/docs/Web/HTTP/Permissions_Policy). | ||
- The calling site does not have the Topics API included in a successful [privacy sandbox enrollment process](/en-US/docs/Web/Privacy/Privacy_sandbox/Enrollment). | ||
|
||
## Examples | ||
|
||
```js | ||
// Get an array of top topics for this user | ||
const topics = await document.browsingTopics(); | ||
|
||
// Request an ad creative | ||
const response = await fetch("https://ads.example/get-creative", { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify(topics), | ||
}); | ||
|
||
// Get the JSON from the response | ||
const creative = await response.json(); | ||
|
||
// Display ad | ||
``` | ||
|
||
## Specifications | ||
|
||
This feature is not part of an official standard, although it is specified in the [Topics API Unofficial Proposal Draft](https://patcg-individual-drafts.github.io/topics/). | ||
|
||
## Browser compatibility | ||
|
||
{{Compat}} | ||
|
||
## See also | ||
|
||
- [Topics API](/en-US/docs/Web/API/Topics_API) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
files/en-us/web/api/htmliframeelement/browsingtopics/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
--- | ||
title: "HTMLIFrameElement: browsingTopics property" | ||
short-title: browsingTopics | ||
slug: Web/API/HTMLIFrameElement/browsingTopics | ||
page-type: web-api-instance-property | ||
status: | ||
- non-standard | ||
browser-compat: api.HTMLIFrameElement.browsingTopics | ||
--- | ||
|
||
{{APIRef("HTML DOM")}} | ||
|
||
> **Warning:** This feature is currently opposed by two browser vendors. See the [Standards positions](#standards_positions) section below for details of opposition. | ||
The **`browsingTopics`** property of the {{domxref("HTMLIFrameElement")}} interface is a boolean specifying that that the selected topics for the current user should be sent with the request for the associated {{htmlelement("iframe")}}'s source in a {{httpheader("Sec-Browsing-Topics")}} header. This reflects the `browsingtopics` HTML attribute. | ||
|
||
See [Using the Topics API](/en-US/docs/Web/API/Topics_API/Using) for more details. | ||
|
||
## Value | ||
|
||
A boolean. The default value is `false`; set it to `true` to send the associated `<iframe>` source request with a {{httpheader("Sec-Browsing-Topics")}} header containing the selected topics for the current user. | ||
|
||
## Examples | ||
|
||
### Get | ||
|
||
Set `browsingtopics` to `true` then load the `<iframe>` contents declaratively: | ||
|
||
```html | ||
<iframe browsingtopics title="Advertising container" src="adtech1.example"> | ||
... | ||
</iframe> | ||
``` | ||
|
||
Log the `browsingTopics` value via script: | ||
|
||
```js | ||
const iframeElem = document.querySelector("iframe"); | ||
console.log(iframeElem.browsingTopics); // will return true in supporting browsers | ||
``` | ||
|
||
### Set | ||
|
||
Specify a minimum `<iframe>`: | ||
|
||
```html | ||
<iframe> ... </iframe> | ||
``` | ||
|
||
Set `browsingtopics` to `true` then load the `<iframe>` contents via script: | ||
|
||
```js | ||
const iframeElem = document.querySelector("iframe"); | ||
|
||
iframeElem.browsingTopics = true; | ||
iframeElem.title = "Advertising container"; | ||
iframeElem.src = "adtech1.example"; | ||
``` | ||
|
||
## Specifications | ||
|
||
This feature is not part of an official standard, although it is specified in the [Topics API Unofficial Proposal Draft](https://patcg-individual-drafts.github.io/topics/). | ||
|
||
## Browser compatibility | ||
|
||
{{Compat}} | ||
|
||
## See also | ||
|
||
- [Topics API](/en-US/docs/Web/API/Topics_API) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.