Add tracker mapping worker and initiator domain extraction
Poll-based worker that maps org-scoped tracker patterns to the common knowledge base via pattern matching and domain-based attribution. Populates initiator_domain on detected trackers at report time. Resolves org-scoped vendors through the common third party link. Signed-off-by: Émile Ré <emile@getprobo.com> Signed-off-by: Émile Ré <emile@probo.com>
This commit is contained in:
@@ -16,6 +16,7 @@ package coredata
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"maps"
|
||||
"time"
|
||||
@@ -151,6 +152,33 @@ WHERE
|
||||
return count, nil
|
||||
}
|
||||
|
||||
func (dts *DetectedTrackers) LoadCommonThirdPartyIDByTrackerPatternID(
|
||||
ctx context.Context,
|
||||
conn pg.Querier,
|
||||
trackerPatternID gid.GID,
|
||||
) (*gid.GID, error) {
|
||||
q := `
|
||||
SELECT DISTINCT ctpd.common_third_party_id
|
||||
FROM detected_trackers dt
|
||||
JOIN common_third_party_domains ctpd ON ctpd.domain = dt.initiator_domain
|
||||
WHERE dt.tracker_pattern_id = @tracker_pattern_id
|
||||
AND dt.initiator_domain IS NOT NULL
|
||||
LIMIT 1;
|
||||
`
|
||||
|
||||
args := pgx.StrictNamedArgs{"tracker_pattern_id": trackerPatternID}
|
||||
|
||||
var commonThirdPartyID gid.GID
|
||||
if err := conn.QueryRow(ctx, q, args).Scan(&commonThirdPartyID); err != nil {
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, fmt.Errorf("cannot load common third party ID by tracker pattern: %w", err)
|
||||
}
|
||||
|
||||
return &commonThirdPartyID, nil
|
||||
}
|
||||
|
||||
func (dts *DetectedTrackers) RelinkByTrackerPatternID(
|
||||
ctx context.Context,
|
||||
tx pg.Tx,
|
||||
|
||||
Reference in New Issue
Block a user