tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 0a13b56b7140c1e5577fe59f4d9ea160cf9931e6
parent 207b6109c87df91dd33b9e3e4b9c9731a24d0299
Author: Nathan Barrett <nbarrett@mozilla.com>
Date:   Fri, 12 Dec 2025 16:00:05 +0000

Bug 2004765 - Pass attribution data to impression and click events r=thecount,home-newtab-reviewers

Adds support for passing attribution data from the DiscoveryStreamFeed/TopSitesFeed
to the DSCard/TopSites, so that attribution information can be included in impression and click events.

Differential Revision: https://phabricator.services.mozilla.com/D275499

Diffstat:
Mbrowser/extensions/newtab/content-src/components/DiscoveryStreamComponents/CardGrid/CardGrid.jsx | 1+
Mbrowser/extensions/newtab/content-src/components/DiscoveryStreamComponents/CardSections/CardSections.jsx | 1+
Mbrowser/extensions/newtab/content-src/components/DiscoveryStreamComponents/DSCard/DSCard.jsx | 2++
Mbrowser/extensions/newtab/content-src/components/DiscoveryStreamImpressionStats/ImpressionStats.jsx | 2++
Mbrowser/extensions/newtab/content-src/components/TopSites/TopSite.jsx | 4++++
Mbrowser/extensions/newtab/data/content/activity-stream.bundle.js | 24+++++++++++++++++-------
Mbrowser/extensions/newtab/lib/DiscoveryStreamFeed.sys.mjs | 1+
Mbrowser/extensions/newtab/lib/TopSitesFeed.sys.mjs | 2++
Mbrowser/extensions/newtab/test/unit/content-src/components/DiscoveryStreamComponents/DSCard.test.jsx | 3+++
Mbrowser/extensions/newtab/test/unit/content-src/components/DiscoveryStreamComponents/ImpressionStats.test.jsx | 7+++++++
10 files changed, 40 insertions(+), 7 deletions(-)

diff --git a/browser/extensions/newtab/content-src/components/DiscoveryStreamComponents/CardGrid/CardGrid.jsx b/browser/extensions/newtab/content-src/components/DiscoveryStreamComponents/CardGrid/CardGrid.jsx @@ -196,6 +196,7 @@ export class _CardGrid extends React.PureComponent { isTimeSensitive={rec.isTimeSensitive} tabIndex={currentCardIndex === this.state.focusedIndex ? 0 : -1} onFocus={() => this.onCardFocus(currentCardIndex)} + attribution={rec.attribution} /> ); } diff --git a/browser/extensions/newtab/content-src/components/DiscoveryStreamComponents/CardSections/CardSections.jsx b/browser/extensions/newtab/content-src/components/DiscoveryStreamComponents/CardSections/CardSections.jsx @@ -458,6 +458,7 @@ function CardSection({ isTimeSensitive={rec.isTimeSensitive} tabIndex={index === focusedIndex ? 0 : -1} onFocus={() => onCardFocus(index)} + attribution={rec.attribution} /> ); return [card]; diff --git a/browser/extensions/newtab/content-src/components/DiscoveryStreamComponents/DSCard/DSCard.jsx b/browser/extensions/newtab/content-src/components/DiscoveryStreamComponents/DSCard/DSCard.jsx @@ -317,6 +317,7 @@ export class _DSCard extends React.PureComponent { features: this.props.features, matches_selected_topic: matchesSelectedTopic, selected_topics: this.props.selectedTopics, + attribution: this.props.attribution, ...(this.props.format ? { format: this.props.format } : { @@ -709,6 +710,7 @@ export class _DSCard extends React.PureComponent { features: this.props.features, ...(format ? { format } : {}), category: this.props.category, + attribution: this.props.attribution, ...(this.props.section ? { section: this.props.section, diff --git a/browser/extensions/newtab/content-src/components/DiscoveryStreamImpressionStats/ImpressionStats.jsx b/browser/extensions/newtab/content-src/components/DiscoveryStreamImpressionStats/ImpressionStats.jsx @@ -79,6 +79,7 @@ export class ImpressionStats extends React.PureComponent { // Keep the 0-based position, can be adjusted by the telemetry // sender if necessary. position: card.pos, + attribution: card.attribution, }, }) ); @@ -105,6 +106,7 @@ export class ImpressionStats extends React.PureComponent { received_rank: link.received_rank, topic: link.topic, features: link.features, + attribution: link.attribution, ...(link.format ? { format: link.format } : { diff --git a/browser/extensions/newtab/content-src/components/TopSites/TopSite.jsx b/browser/extensions/newtab/content-src/components/TopSites/TopSite.jsx @@ -338,6 +338,7 @@ export class TopSiteLink extends React.PureComponent { source: NEWTAB_SOURCE, visible_topsites: visibleTopSites, frecency_boosted: link.type === "frecency-boost", + attribution: link.attribution, }} // For testing. IntersectionObserver={this.props.IntersectionObserver} @@ -554,6 +555,7 @@ export class TopSite extends React.PureComponent { card_type: "spoc", tile_id: this.props.link.id, shim: this.props.link.shim && this.props.link.shim.click, + attribution: this.props.link.attribution, }, }) ); @@ -569,6 +571,7 @@ export class TopSite extends React.PureComponent { tile_id: this.props.link.id, advertiser: title.toLocaleLowerCase(), source: NEWTAB_SOURCE, + attribution: this.props.link.attribution, }, }) ); @@ -587,6 +590,7 @@ export class TopSite extends React.PureComponent { source: NEWTAB_SOURCE, visible_topsites: this.props.visibleTopSites, frecency_boosted: this.props.link.type === "frecency-boost", + attribution: this.props.link.attribution, }, }) ); diff --git a/browser/extensions/newtab/data/content/activity-stream.bundle.js b/browser/extensions/newtab/data/content/activity-stream.bundle.js @@ -2907,7 +2907,8 @@ class ImpressionStats_ImpressionStats extends (external_React_default()).PureCom advertiser: card.advertiser, // Keep the 0-based position, can be adjusted by the telemetry // sender if necessary. - position: card.pos + position: card.pos, + attribution: card.attribution } })); } @@ -2933,6 +2934,7 @@ class ImpressionStats_ImpressionStats extends (external_React_default()).PureCom received_rank: link.received_rank, topic: link.topic, features: link.features, + attribution: link.attribution, ...(link.format ? { format: link.format } : { @@ -3634,6 +3636,7 @@ class _DSCard extends (external_React_default()).PureComponent { features: this.props.features, matches_selected_topic: matchesSelectedTopic, selected_topics: this.props.selectedTopics, + attribution: this.props.attribution, ...(this.props.format ? { format: this.props.format } : { @@ -3951,6 +3954,7 @@ class _DSCard extends (external_React_default()).PureComponent { format } : {}), category: this.props.category, + attribution: this.props.attribution, ...(this.props.section ? { section: this.props.section, section_position: this.props.sectionPosition, @@ -4790,7 +4794,8 @@ class _CardGrid extends (external_React_default()).PureComponent { alt_text: rec.alt_text, isTimeSensitive: rec.isTimeSensitive, tabIndex: currentCardIndex === this.state.focusedIndex ? 0 : -1, - onFocus: () => this.onCardFocus(currentCardIndex) + onFocus: () => this.onCardFocus(currentCardIndex), + attribution: rec.attribution })); } } @@ -8331,7 +8336,8 @@ class TopSiteLink extends (external_React_default()).PureComponent { advertiser: title.toLocaleLowerCase(), source: NEWTAB_SOURCE, visible_topsites: visibleTopSites, - frecency_boosted: link.type === "frecency-boost" + frecency_boosted: link.type === "frecency-boost", + attribution: link.attribution } // For testing. , @@ -8523,7 +8529,8 @@ class TopSite extends (external_React_default()).PureComponent { value: { card_type: "spoc", tile_id: this.props.link.id, - shim: this.props.link.shim && this.props.link.shim.click + shim: this.props.link.shim && this.props.link.shim.click, + attribution: this.props.link.attribution } })); @@ -8536,7 +8543,8 @@ class TopSite extends (external_React_default()).PureComponent { position: this.props.link.pos, tile_id: this.props.link.id, advertiser: title.toLocaleLowerCase(), - source: NEWTAB_SOURCE + source: NEWTAB_SOURCE, + attribution: this.props.link.attribution } })); } else if (isSponsored(this.props.link)) { @@ -8552,7 +8560,8 @@ class TopSite extends (external_React_default()).PureComponent { advertiser: title.toLocaleLowerCase(), source: NEWTAB_SOURCE, visible_topsites: this.props.visibleTopSites, - frecency_boosted: this.props.link.type === "frecency-boost" + frecency_boosted: this.props.link.type === "frecency-boost", + attribution: this.props.link.attribution } })); } else { @@ -11443,7 +11452,8 @@ function CardSection({ sectionLayoutName: layoutName, isTimeSensitive: rec.isTimeSensitive, tabIndex: index === focusedIndex ? 0 : -1, - onFocus: () => onCardFocus(index) + onFocus: () => onCardFocus(index), + attribution: rec.attribution }); return [card]; }))); diff --git a/browser/extensions/newtab/lib/DiscoveryStreamFeed.sys.mjs b/browser/extensions/newtab/lib/DiscoveryStreamFeed.sys.mjs @@ -998,6 +998,7 @@ export class DiscoveryStreamFeed { sponsor: spoc.sponsor, title: spoc.title, url: spoc.url, + attribution: spoc.attributions || null, })), }; } diff --git a/browser/extensions/newtab/lib/TopSitesFeed.sys.mjs b/browser/extensions/newtab/lib/TopSitesFeed.sys.mjs @@ -526,6 +526,7 @@ export class ContileIntegration { image_url: tile.image_url, impression_url: tile.callbacks.impression, image_size: 200, + attribution: tile.attributions || null, }; formattedTileData.push(formattedData); @@ -1057,6 +1058,7 @@ export class TopSitesFeed { sponsored_tile_id: site.id, partner: SPONSORED_TILE_PARTNER_AMP, block_key: site.id, + attribution: site.attribution, }; if (site.image_url && site.image_size >= MIN_FAVICON_SIZE) { // Only use the image from Contile if it's hi-res, otherwise, fallback diff --git a/browser/extensions/newtab/test/unit/content-src/components/DiscoveryStreamComponents/DSCard.test.jsx b/browser/extensions/newtab/test/unit/content-src/components/DiscoveryStreamComponents/DSCard.test.jsx @@ -264,6 +264,7 @@ describe("<DSCard>", () => { features: undefined, matches_selected_topic: undefined, selected_topics: undefined, + attribution: undefined, format: "medium-card", }, }) @@ -325,6 +326,7 @@ describe("<DSCard>", () => { features: undefined, matches_selected_topic: undefined, selected_topics: undefined, + attribution: undefined, format: "spoc", }, }) @@ -389,6 +391,7 @@ describe("<DSCard>", () => { features: undefined, matches_selected_topic: undefined, selected_topics: undefined, + attribution: undefined, format: "medium-card", }, }) diff --git a/browser/extensions/newtab/test/unit/content-src/components/DiscoveryStreamComponents/ImpressionStats.test.jsx b/browser/extensions/newtab/test/unit/content-src/components/DiscoveryStreamComponents/ImpressionStats.test.jsx @@ -148,6 +148,7 @@ describe("<ImpressionStats>", () => { received_rank: undefined, topic: undefined, features: undefined, + attribution: undefined, format: "medium-card", }, { @@ -162,6 +163,7 @@ describe("<ImpressionStats>", () => { received_rank: undefined, topic: undefined, features: undefined, + attribution: undefined, format: "medium-card", }, { @@ -176,6 +178,7 @@ describe("<ImpressionStats>", () => { received_rank: undefined, topic: undefined, features: undefined, + attribution: undefined, format: "medium-card", }, ]); @@ -226,6 +229,7 @@ describe("<ImpressionStats>", () => { source: "newtab", advertiser: "test advertiser", position: 1, + attribution: undefined, }); }); it("should send an impression when the wrapped item transiting from invisible to visible", () => { @@ -269,6 +273,7 @@ describe("<ImpressionStats>", () => { fetchTimestamp: TEST_FETCH_TIMESTAMP, topic: undefined, features: undefined, + attribution: undefined, format: "medium-card", }, { @@ -283,6 +288,7 @@ describe("<ImpressionStats>", () => { fetchTimestamp: TEST_FETCH_TIMESTAMP, topic: undefined, features: undefined, + attribution: undefined, format: "medium-card", }, { @@ -297,6 +303,7 @@ describe("<ImpressionStats>", () => { fetchTimestamp: TEST_FETCH_TIMESTAMP, topic: undefined, features: undefined, + attribution: undefined, format: "medium-card", }, ]);