Nebula
Nebula copied to clipboard
Is it worth looking into the Topics API for features?
This is meant for advertisers, but the API appears to be available directly in JavaScript, so we could technically use it to personalize websites based on user interest in general... Or maybe use it to track additional data in GA (if it is not available already in there?)
https://developer.chrome.com/docs/privacy-sandbox/topics/
How to call it:
if ( 'browsingTopics' in document && document.featurePolicy.allowsFeature('browsing-topics') ){
//Customize content or do whatever here
console.log( document.browsingTopics() );
}
It will return 5 topics (I believe in a random order) of what the user may be interested in. There is a small chance that one of the topics returned is not actually related to the user's interests– this is by design. So the first interest in this JS object is not necessarily the user's top-interest!
For now, Nebula is sending a GA event when the Topics API is available in a user's browser. It does not send any topic data yet– just that it is available.
https://www.youtube.com/watch?v=hEBzWuXjeTQ
The document.browsingTopics()
returns a promise so here is the syntax I am using now:
document.browsingTopics().then(function(topics){
if ( topics ){ //If the topics array is not empty
gtag('event', 'topics_api', {
event_category: 'Topics API',
event_action: 'Interests',
event_label: topics.join(', '),
interests: topics.join(', '),
non_interaction: true
});
}
});
Don't forget to create a custom dimension in GA4 for interests
.
This appears to be available as of Chrome 117+ which is where Canary is. I think it is still in origin trial, so this may not be available in stable Chrome until a later version.
This seems like it could be very interesting, however the Topics API appears to only become available for high-traffic websites and when users come to the website often... At least that is what I'm getting from the attestation message.
So for now, I've deactivated it by commenting it out– it can be brought back, or referenced/used in child themes.