Skip to content

Instantly share code, notes, and snippets.

@henshaw
Created January 25, 2022 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save henshaw/7ea0f1c2dbfafc820ac84632c537fcfd to your computer and use it in GitHub Desktop.
Save henshaw/7ea0f1c2dbfafc820ac84632c537fcfd to your computer and use it in GitHub Desktop.
Google Topics API fetch example
// document.browsingTopics() returns an array of up to three topic objects in random order.
const topics = await document.browsingTopics();
// The returned array looks like: [{'value': Number, 'taxonomyVersion': String, 'modelVersion': String}]
// Get data for an ad creative.
const creative = 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment