Map trackers by sibling patterns sharing an origin
Tracker patterns detected on the same banner that share initiator domains are a strong indicator of the same third party. Previously the mapping worker only checked the global third-party domain catalog, so a tracker whose domain was not registered there fell through to the expensive LLM identification step even when a co-located pattern was already mapped. Add a matchBySiblingOrigin step that finds other patterns on the same banner sharing the same initiator domains and reuses their resolved common third party. It prefers siblings already promoted to an org third party (the strongest signal) and falls back to siblings carrying only a catalog link, skipping when the siblings disagree. The step runs before the catalog domain lookup since an already-qualified sibling is at least as reliable as a raw domain match. Signed-off-by: Émile Ré <emile@probo.com>
This commit is contained in:
@@ -252,6 +252,48 @@ WHERE
|
||||
return nil
|
||||
}
|
||||
|
||||
func (dts *DetectedTrackers) LoadSiblingPatternIDsByInitiatorDomains(
|
||||
ctx context.Context,
|
||||
conn pg.Querier,
|
||||
cookieBannerID gid.GID,
|
||||
domains []string,
|
||||
excludePatternID gid.GID,
|
||||
limit int,
|
||||
) ([]gid.GID, error) {
|
||||
if len(domains) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
q := `
|
||||
SELECT DISTINCT tracker_pattern_id
|
||||
FROM detected_trackers
|
||||
WHERE cookie_banner_id = @cookie_banner_id
|
||||
AND initiator_domain = ANY(@domains)
|
||||
AND tracker_pattern_id IS NOT NULL
|
||||
AND tracker_pattern_id != @exclude_pattern_id
|
||||
LIMIT @limit;
|
||||
`
|
||||
|
||||
args := pgx.StrictNamedArgs{
|
||||
"cookie_banner_id": cookieBannerID,
|
||||
"domains": domains,
|
||||
"exclude_pattern_id": excludePatternID,
|
||||
"limit": limit,
|
||||
}
|
||||
|
||||
rows, err := conn.Query(ctx, q, args)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot load sibling pattern ids: %w", err)
|
||||
}
|
||||
|
||||
ids, err := pgx.CollectRows(rows, pgx.RowTo[gid.GID])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot collect sibling pattern ids: %w", err)
|
||||
}
|
||||
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
func (dts *DetectedTrackers) RelinkByTrackerPatternID(
|
||||
ctx context.Context,
|
||||
tx pg.Tx,
|
||||
|
||||
Reference in New Issue
Block a user