forked from mirrors/gecko-dev
Bug 1870160 - Newtab configurable positions for topsites from contile r=nanj
Differential Revision: https://phabricator.services.mozilla.com/D196511
This commit is contained in:
parent
ed67c46f09
commit
be671e3c94
3 changed files with 35 additions and 4 deletions
|
|
@ -1695,6 +1695,9 @@ pref("browser.newtabpage.activity-stream.discoverystream.recentSaves.enabled", f
|
||||||
pref("browser.newtabpage.activity-stream.discoverystream.editorsPicksHeader.enabled", false);
|
pref("browser.newtabpage.activity-stream.discoverystream.editorsPicksHeader.enabled", false);
|
||||||
pref("browser.newtabpage.activity-stream.discoverystream.spoc-positions", "1,5,7,11,18,20");
|
pref("browser.newtabpage.activity-stream.discoverystream.spoc-positions", "1,5,7,11,18,20");
|
||||||
pref("browser.newtabpage.activity-stream.discoverystream.spoc-topsites-positions", "2");
|
pref("browser.newtabpage.activity-stream.discoverystream.spoc-topsites-positions", "2");
|
||||||
|
// This is a 0-based index, for consistency with the other position CSVs,
|
||||||
|
// but Contile positions are a 1-based index, so we end up adding 1 to these before using them.
|
||||||
|
pref("browser.newtabpage.activity-stream.discoverystream.contile-topsites-positions", "0,1");
|
||||||
pref("browser.newtabpage.activity-stream.discoverystream.widget-positions", "");
|
pref("browser.newtabpage.activity-stream.discoverystream.widget-positions", "");
|
||||||
|
|
||||||
pref("browser.newtabpage.activity-stream.discoverystream.spocs-endpoint", "");
|
pref("browser.newtabpage.activity-stream.discoverystream.spocs-endpoint", "");
|
||||||
|
|
|
||||||
|
|
@ -129,6 +129,7 @@ const DEFAULT_SITES_EXPERIMENTS_PREF_BRANCH = "browser.topsites.experiment.";
|
||||||
// Nimbus variable for the Contile integration. It falls back to the pref:
|
// Nimbus variable for the Contile integration. It falls back to the pref:
|
||||||
// `browser.topsites.contile.enabled`.
|
// `browser.topsites.contile.enabled`.
|
||||||
const NIMBUS_VARIABLE_CONTILE_ENABLED = "topSitesContileEnabled";
|
const NIMBUS_VARIABLE_CONTILE_ENABLED = "topSitesContileEnabled";
|
||||||
|
const NIMBUS_VARIABLE_CONTILE_POSITIONS = "contileTopsitesPositions";
|
||||||
const CONTILE_ENDPOINT_PREF = "browser.topsites.contile.endpoint";
|
const CONTILE_ENDPOINT_PREF = "browser.topsites.contile.endpoint";
|
||||||
const CONTILE_UPDATE_INTERVAL = 15 * 60 * 1000; // 15 minutes
|
const CONTILE_UPDATE_INTERVAL = 15 * 60 * 1000; // 15 minutes
|
||||||
// The maximum number of sponsored top sites to fetch from Contile.
|
// The maximum number of sponsored top sites to fetch from Contile.
|
||||||
|
|
@ -491,10 +492,33 @@ class TopSitesFeed {
|
||||||
const contileEnabled = lazy.NimbusFeatures.newtab.getVariable(
|
const contileEnabled = lazy.NimbusFeatures.newtab.getVariable(
|
||||||
NIMBUS_VARIABLE_CONTILE_ENABLED
|
NIMBUS_VARIABLE_CONTILE_ENABLED
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Keep the number of positions in the array in sync with CONTILE_MAX_NUM_SPONSORED.
|
||||||
|
// sponsored_position is a 1-based index, and contilePositions is a 0-based index,
|
||||||
|
// so we need to add 1 to each of these.
|
||||||
|
// Also currently this does not work with SOV.
|
||||||
|
let contilePositions = lazy.NimbusFeatures.pocketNewtab
|
||||||
|
.getVariable(NIMBUS_VARIABLE_CONTILE_POSITIONS)
|
||||||
|
?.split(",")
|
||||||
|
.map(item => parseInt(item, 10) + 1)
|
||||||
|
.filter(item => !Number.isNaN(item));
|
||||||
|
if (!contilePositions || contilePositions.length === 0) {
|
||||||
|
contilePositions = [1, 2];
|
||||||
|
}
|
||||||
|
|
||||||
let hasContileTiles = false;
|
let hasContileTiles = false;
|
||||||
if (contileEnabled) {
|
if (contileEnabled) {
|
||||||
let sponsoredPosition = 1;
|
let contilePositionIndex = 0;
|
||||||
for (let site of this._contile.sites) {
|
// We need to loop through potential spocs and set their positions.
|
||||||
|
// If we run out of spocs or positions, we stop.
|
||||||
|
// First, we need to know which array is shortest. This is our exit condition.
|
||||||
|
const minLength = Math.min(
|
||||||
|
contilePositions.length,
|
||||||
|
this._contile.sites.length
|
||||||
|
);
|
||||||
|
// Loop until we run out of spocs or positions.
|
||||||
|
for (let i = 0; i < minLength; i++) {
|
||||||
|
let site = this._contile.sites[i];
|
||||||
let hostname = shortURL(site);
|
let hostname = shortURL(site);
|
||||||
let link = {
|
let link = {
|
||||||
isDefault: true,
|
isDefault: true,
|
||||||
|
|
@ -503,7 +527,7 @@ class TopSitesFeed {
|
||||||
sendAttributionRequest: false,
|
sendAttributionRequest: false,
|
||||||
label: site.name,
|
label: site.name,
|
||||||
show_sponsored_label: hostname !== "yandex",
|
show_sponsored_label: hostname !== "yandex",
|
||||||
sponsored_position: sponsoredPosition++,
|
sponsored_position: contilePositions[contilePositionIndex++],
|
||||||
sponsored_click_url: site.click_url,
|
sponsored_click_url: site.click_url,
|
||||||
sponsored_impression_url: site.impression_url,
|
sponsored_impression_url: site.impression_url,
|
||||||
sponsored_tile_id: site.id,
|
sponsored_tile_id: site.id,
|
||||||
|
|
@ -517,7 +541,7 @@ class TopSitesFeed {
|
||||||
}
|
}
|
||||||
DEFAULT_TOP_SITES.push(link);
|
DEFAULT_TOP_SITES.push(link);
|
||||||
}
|
}
|
||||||
hasContileTiles = sponsoredPosition > 1;
|
hasContileTiles = contilePositionIndex > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read defaults from remote settings.
|
// Read defaults from remote settings.
|
||||||
|
|
|
||||||
|
|
@ -592,6 +592,10 @@ pocketNewtab:
|
||||||
type: string
|
type: string
|
||||||
fallbackPref: browser.newtabpage.activity-stream.discoverystream.spoc-topsites-positions
|
fallbackPref: browser.newtabpage.activity-stream.discoverystream.spoc-topsites-positions
|
||||||
description: CSV string of spoc position indexes on newtab topsites section
|
description: CSV string of spoc position indexes on newtab topsites section
|
||||||
|
contileTopsitesPositions:
|
||||||
|
type: string
|
||||||
|
fallbackPref: browser.newtabpage.activity-stream.discoverystream.contile-topsites-positions
|
||||||
|
description: CSV string of contile position indexes on newtab topsites section
|
||||||
spocAdTypes:
|
spocAdTypes:
|
||||||
type: string
|
type: string
|
||||||
fallbackPref: browser.newtabpage.activity-stream.discoverystream.spocAdTypes
|
fallbackPref: browser.newtabpage.activity-stream.discoverystream.spocAdTypes
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue