Created
January 25, 2022 13:54
-
-
Save henshaw/7ea0f1c2dbfafc820ac84632c537fcfd to your computer and use it in GitHub Desktop.
Google Topics API fetch example
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
// 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