Document: browsingTopics() method - Web APIs | MDN

Syntax

js

browsingTopics()
browsingTopics(options)

Parameters

options Optional

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 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).

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:

json

{
  "configVersion": "chrome.1",
  "modelVersion": "1",
  "taxonomyVersion": "1",
  "topic": 43,
  "version": "chrome.1:1:1"
}

Exceptions

NotAllowedError DOMException

Thrown if:

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.

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on by MDN contributors.