-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Topics FPD module: initial release #8646
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c0a922c
Topics FPD module
dgirardi a84d7b8
Merge branch 'master' into topics
dgirardi c60a985
Small improvements
dgirardi 95c0080
Merge branch 'master' into topics
dgirardi 176f95b
Merge branch 'master' into topics
dgirardi 2388b06
Map taxonomyVersion to segtax, modelVersion to segclass
dgirardi a4743d4
Merge branch 'master' into topics
dgirardi 4f51181
Convert fpdModule & topicsFpdModule to use GreedyPromise
dgirardi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,80 @@ | ||
import {logError, logWarn, mergeDeep} from '../src/utils.js'; | ||
import {getRefererInfo} from '../src/refererDetection.js'; | ||
import {submodule} from '../src/hook.js'; | ||
import {GreedyPromise} from '../src/utils/promise.js'; | ||
|
||
const TAXONOMIES = { | ||
// map from topic taxonomyVersion to IAB segment taxonomy | ||
'1': 600 | ||
} | ||
|
||
function partitionBy(field, items) { | ||
return items.reduce((partitions, item) => { | ||
const key = item[field]; | ||
if (!partitions.hasOwnProperty(key)) partitions[key] = []; | ||
partitions[key].push(item); | ||
return partitions; | ||
}, {}); | ||
} | ||
|
||
export function getTopicsData(name, topics, taxonomies = TAXONOMIES) { | ||
return Object.entries(partitionBy('taxonomyVersion', topics)) | ||
.filter(([taxonomyVersion]) => { | ||
if (!taxonomies.hasOwnProperty(taxonomyVersion)) { | ||
logWarn(`Unrecognized taxonomyVersion from Topics API: "${taxonomyVersion}"; topic will be ignored`); | ||
return false; | ||
} | ||
return true; | ||
}).flatMap(([taxonomyVersion, topics]) => | ||
Object.entries(partitionBy('modelVersion', topics)) | ||
.map(([modelVersion, topics]) => { | ||
const datum = { | ||
ext: { | ||
segtax: taxonomies[taxonomyVersion], | ||
segclass: modelVersion | ||
}, | ||
segment: topics.map((topic) => ({id: topic.topic.toString()})) | ||
}; | ||
if (name != null) { | ||
datum.name = name; | ||
} | ||
return datum; | ||
}) | ||
); | ||
} | ||
|
||
export function getTopics(doc = document) { | ||
let topics = null; | ||
try { | ||
if ('browsingTopics' in doc && doc.featurePolicy.allowsFeature('browsing-topics')) { | ||
topics = GreedyPromise.resolve(doc.browsingTopics()); | ||
} | ||
} catch (e) { | ||
logError('Could not call topics API', e); | ||
} | ||
if (topics == null) { | ||
topics = GreedyPromise.resolve([]); | ||
} | ||
return topics; | ||
} | ||
|
||
const topicsData = getTopics().then((topics) => getTopicsData(getRefererInfo().domain, topics)); | ||
|
||
export function processFpd(config, {global}, {data = topicsData} = {}) { | ||
return data.then((data) => { | ||
if (data.length) { | ||
mergeDeep(global, { | ||
user: { | ||
data | ||
} | ||
}); | ||
} | ||
return {global}; | ||
}); | ||
} | ||
|
||
submodule('firstPartyData', { | ||
name: 'topics', | ||
queue: 1, | ||
processFpd | ||
}); |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems we should potentially use the domain of the url in https://developer.mozilla.org/en-US/docs/Web/API/Document/currentScript
Or perhaps a configuration override is sufficient.
Pubishers may wish to indicate the breadth of the footprint here, eg hearst.com instead of somemagazine.com or cafemedia.com instead of cafedelites.com.
The topics api results are reporteed to be dependent on the domain of the script which calls it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand - do you mean that topics will return different results if you use
<script src="//rubicon.com/prebid.js" />
compared<script src="//appnexus.com/prebid.js" />
? that seems insane.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's how it is described
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it appears there's been some clarification:
"A design goal of the Topics API is to enable interest-based advertising without the sharing of information to more entities than is currently possible with third-party cookies. The Topics API proposes that topics can only be returned for API callers that have already observed them, within a limited timeframe.
Key Term
A Topics API caller is the entity that calls the document.browsingTopics() JavaScript method, and will use the topics returned by the method to help select relevant ads. Typically, a call to document.browsingTopics() would be from code included in a site from a third party such as an adtech platform. The browser determines the caller from the site of the current document. So, if you're a third party on a page, make sure you call the API from an iframe that your site owns."
This suggests only if you call the api from inside a frame and do the post-message will you get different behavior
Let's keep that for a follow up and cancel this change request to this pr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dgirardi testing successful